use named placeholders and dict for clearer formatting

pull/619/head
Denver Risser 2021-01-27 16:55:35 -05:00
parent 05f542e385
commit 0243a6c899
1 changed files with 11 additions and 4 deletions

View File

@ -18,7 +18,14 @@ class MailMassMailingContact(models.Model):
contact_email = contact.email.strip().lower() contact_email = contact.email.strip().lower()
other_emails = [e.strip().lower() for e in others.mapped('email')] other_emails = [e.strip().lower() for e in others.mapped('email')]
if contact_email in other_emails: if contact_email in other_emails:
raise ValidationError(_( in_list = others.filtered(lambda o: o.email == contact_email) \
"Cannot have the same email (%s) more" .list_ids.mapped('name')
"than once in the same list." % contact_email lists = ''.join(map(lambda l: '- {}\n'.format(l), in_list))
)) msg = _('''Email (%(contact_email)s) already in mailing list(s):
%(lists)s
Please use a different email address or remove \
(%(contact_email)s) from the mailing list(s) above.''')
raise ValidationError(msg % {
'contact_email': contact_email,
'lists': lists,
})