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
}
和
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
我想给004
提供多个参数,定义,以便length
不同于7或11,那么我想显示Bank account number must contain 7 or 11 digits
。我怎样才能将多个参数传递给关键字?
答案 0 :(得分:0)
使用列表或元组而不仅仅是整数作为字典中的值。
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
}
您还需要更改clean_bank_account
中的一些逻辑。