Mercurial > public > sg101
changeset 610:838eb32383a9
Show member flags on forum index page.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Fri, 03 Aug 2012 20:30:58 -0500 |
parents | 678a1a2ef55a |
children | 8b9fc7487222 |
files | bio/templatetags/bio_tags.py sg101/templates/accounts/user_stats_tag.html sg101/templates/bio/member_flags_tag.html |
diffstat | 3 files changed, 28 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/bio/templatetags/bio_tags.py Sat Jul 28 15:12:09 2012 -0500 +++ b/bio/templatetags/bio_tags.py Fri Aug 03 20:30:58 2012 -0500 @@ -4,6 +4,7 @@ from django import template from django.conf import settings from django.core.cache import cache +from django.db.models import Count import bio.flags import bio.models @@ -115,3 +116,19 @@ 'size': size, 'STATIC_URL': settings.STATIC_URL, } + + +@register.inclusion_tag('bio/member_flags_tag.html') +def member_flags(): + """Displays a list of member flags.""" + + flag_data = UserProfile.objects.exclude(country='').values('country').\ + annotate(count=Count('country')).order_by('country') + + for rec in flag_data: + rec['name'] = bio.flags.FLAG_DATA[rec['country']] + + return { + 'flag_data': flag_data, + 'STATIC_URL': settings.STATIC_URL, + }
--- a/sg101/templates/accounts/user_stats_tag.html Sat Jul 28 15:12:09 2012 -0500 +++ b/sg101/templates/accounts/user_stats_tag.html Fri Aug 03 20:30:58 2012 -0500 @@ -1,10 +1,12 @@ {% load url from future %} {% load bio_tags %} +{% load cache %} {% load humanize %} <div id="accounts-stats"> {% if num_users %} -Our site has <strong>{{ num_users|intcomma }}</strong> members. +Our site has <strong>{{ num_users|intcomma }}</strong> members from around the world: {% endif %} +{% cache 360 member_flags_tag %}{% member_flags %}{% endcache %} {% if new_users %} Please welcome our newest members: <ul class="inline-list">
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sg101/templates/bio/member_flags_tag.html Fri Aug 03 20:30:58 2012 -0500 @@ -0,0 +1,8 @@ +{% if flag_data %} +<div> + {% for rec in flag_data %} + <img src="{{ STATIC_URL }}/flags/24/{{ rec.country }}.png" + alt="{{ rec.name }}" title="{{ rec.count }} {{ rec.name }}" /> + {% endfor %} +</div> +{% endif %}