Mercurial > public > sg101
changeset 444:a0847158cf72
Tweaking the birthday block; now display a list of people for each day and bold the current day.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 04 Jun 2011 19:10:34 +0000 |
parents | a01596ab17cf |
children | e9f203c5f5bb |
files | gpp/core/templatetags/core_tags.py gpp/templates/core/birthday_block.html |
diffstat | 2 files changed, 33 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- 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, }
--- 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 %}<img src="{{ STATIC_URL }}icons/cake.png" alt="Cake" class="middle" /> {{ today|date:"F" }} Birthdays <img src="{{ STATIC_URL }}icons/cake.png" alt="Cake" class="middle" /> {% endblock %} {% block block_content %} -{% if profiles %} +{% if birthdays %} <ul> - {% for profile in profiles %} - <li>{{ profile.birthday.day|ordinal }} – <a href="{% url 'bio-view_profile' username=profile.user.username %}">{{ profile.user.username }}</a></li> + {% for bday in birthdays %} + <li> + {% if bday.day == today.day %}<strong>{% endif %} + {{ bday.day|ordinal }} – + {% for profile in bday.profiles %} + <a href="{% url 'bio-view_profile' username=profile.user.username %}">{{ profile.user.username }}</a>{% if not forloop.last %}, {% endif %} + {% endfor %} + {% if bday.day == today.day %}</strong>{% endif %} + </li> {% endfor %} </ul> {% else %}