LOANWOLF_BANK_ACCOUNTS_LENGTH = {
'001': 7, # Banque de Montréal
'002': 7, # Scotia
'003': 7, # RBC
'004': 7 or 11, # TD (7 or 11)
'006': 7, # BNC
'010': 7, # CIBC
'016': 9, # HSBC
'039': 9, # Banque Laurentienne
'614': 10, # Tangerine
'815': 7, # Desjardins
'829': 7, # Desjardins Ontario
}
and
def clean_bank_account(self):
bank_account = self.form.cleaned_data.get('bank_account')
bank_transit = self.form.cleaned_data.get('bank_transit')
if bank_account not in (None, ''):
bank = self.form.cleaned_data.get('bank')
if bank not in (None, ''):
# Check bank account format for specific banks
length = settings.LOANWOLF_BANK_ACCOUNTS_LENGTH.get(bank)
if length:
if bank_transit not in (None, ''):
if not bank_account.isnumeric() or length != len(bank_account):
if bank == '004':
raise ValidationError(
_('Bank account number must contain 7 or 11 digits') % length # noqa
)
else:
raise ValidationError(
_('Bank account number must contain %d digits') % length # noqa
)
else:
raise ValidationError(
_('Cannot validate bank account without a valid bank transit') # noqa
)
return bank_account
I wanted to give more than one arguments, definitions to 004
so that if length
is different of 7 or 11, then I want to display Bank account number must contain 7 or 11 digits
. How could I pass more than one arguments to a keyword?
Use a list or a tuple instead of just a integer as the values in the dictionary.
LOANWOLF_BANK_ACCOUNTS_LENGTH = {
'001': [7], # Banque de Montréal
'002': [7], # Scotia
'003': [7], # RBC
'004': [7, 11], # TD (7 or 11)
'006': [7], # BNC
'010': [7], # CIBC
'016': [9], # HSBC
'039': [9], # Banque Laurentienne
'614': [10], # Tangerine
'815': [7], # Desjardins
'829': [7], # Desjardins Ontario
}
You would also need to change some of the logic in clean_bank_account
too.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.