# HG changeset patch # User Brian Neal # Date 1307214634 0 # Node ID a0847158cf72f60bb944d999bab695b3a9717255 # Parent a01596ab17cf6f10492685aebd160fc15d7ef80f Tweaking the birthday block; now display a list of people for each day and bold the current day. diff -r a01596ab17cf -r a0847158cf72 gpp/core/templatetags/core_tags.py --- a/gpp/core/templatetags/core_tags.py Sat Jun 04 03:12:15 2011 +0000 +++ b/gpp/core/templatetags/core_tags.py Sat Jun 04 19:10:34 2011 +0000 @@ -1,6 +1,7 @@ """ Miscellaneous/utility template tags. """ +import collections import datetime import urllib @@ -71,6 +72,20 @@ elapsed.is_safe = True +class Birthday(object): + """ + A simple named tuple-type class for birthdays. + This class was created to make things easier in the template. + + """ + day = None + profiles = [] + + def __init__(self, day, profiles=None): + self.day = day + self.profiles = profiles if profiles else [] + + @register.inclusion_tag('core/birthday_block.html') def birthday_block(): """ @@ -79,11 +94,17 @@ today = datetime.date.today() profiles = list(UserProfile.objects.filter(birthday__month=today.month).select_related( 'user')) - profiles.sort(key=lambda p: p.birthday.day) + + days = collections.defaultdict(list) + for profile in profiles: + days[profile.birthday.day].append(profile) + + birthdays = [Birthday(day, profiles) for day, profiles in days.iteritems()] + birthdays.sort(key=lambda b: b.day) return { 'STATIC_URL': settings.STATIC_URL, - 'profiles': profiles, + 'birthdays': birthdays, 'today': today, } diff -r a01596ab17cf -r a0847158cf72 gpp/templates/core/birthday_block.html --- a/gpp/templates/core/birthday_block.html Sat Jun 04 03:12:15 2011 +0000 +++ b/gpp/templates/core/birthday_block.html Sat Jun 04 19:10:34 2011 +0000 @@ -3,10 +3,17 @@ {% load humanize %} {% block block_title %}Cake {{ today|date:"F" }} Birthdays Cake {% endblock %} {% block block_content %} -{% if profiles %} +{% if birthdays %} {% else %}