Skip to content

Commit 4f48cb2

Browse files
committed
Make Person.role_email a bit smarter, make Person.email_address (which
seems to be a wrapper for old code at the moment) always return a string - Legacy-Id: 3747
1 parent 896347b commit 4f48cb2

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

redesign/person/models.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,25 @@ def short(self):
2929
prefix, first, middle, last, suffix = self.ascii_parts()
3030
return (first and first[0]+"." or "")+(middle or "")+" "+last+(suffix and " "+suffix or "")
3131
def role_email(self, role_name, group=None):
32+
"""Lookup email for role for person, optionally on group which
33+
may be an object or the group acronym."""
3234
if group:
35+
if isinstance(group, str) or isinstance(group, unicode):
36+
group = Group.objects.get(acronym=group)
3337
e = Email.objects.filter(person=self, role__group=group, role__name=role_name)
34-
if e:
35-
return e[0]
3638
else:
3739
e = Email.objects.filter(person=self, role__group__state="active", role__name=role_name)
38-
if e:
39-
return e[0]
40+
if e:
41+
return e[0]
42+
# no cigar, try the complete set before giving up
4043
e = self.email_set.order_by("-active")
4144
if e:
4245
return e[0]
4346
return None
4447
def email_address(self):
4548
e = self.email_set.filter(active=True)
4649
if e:
47-
return e[0]
50+
return e[0].address
4851
else:
4952
return ""
5053
def formatted_email(self):

0 commit comments

Comments
 (0)