Add auto-hide/show magic to message recipients field when viewing

This commit is contained in:
Lance Edgar 2016-05-01 14:57:41 -05:00
parent f3cab67aaf
commit 70a2f10c81
2 changed files with 29 additions and 0 deletions

View file

@ -97,6 +97,12 @@ class RecipientsFieldRenderer(formalchemy.FieldRenderer):
recips = sorted([r.recipient.display_name for r in recips])
if len(recips) < len(recipients):
recips.insert(0, 'you')
max_display = 5
if len(recips) > max_display:
basic = HTML.literal("{}, ".format(', '.join(recips[:max_display-1])))
more = tags.link_to("({} more)".format(len(recips[max_display-1:])), '#', class_='more')
everyone = HTML.tag('span', class_='everyone', c=', '.join(recips[max_display-1:]))
return basic + more + everyone
return ', '.join(recips)