Permalink
Browse files

Merge

  • Loading branch information...
2 parents ba756e1 + d1ee0b6 commit 46518fe116c5ca416750683fb3622f1ae4844dc8 @stephenmcd stephenmcd committed Feb 24, 2011
Showing with 21 additions and 12 deletions.
  1. +11 −5 mezzanine/blog/templates/blog/includes/filter_panel.html
  2. +10 −7 mezzanine/blog/templatetags/blog_tags.py
@@ -15,9 +15,12 @@
{% if months %}
<h3>{% trans "Archive" %}</h3>
{% for month in months %}
-{% ifchanged month.year %}{% if not forloop.first %}</ul>{% endif %}<h4>{{ month.year }}</h4><ul>{% endifchanged %}
-<li><a href="{% url blog_post_list_month year=month.year month=month.month %}"
- >{{ month|date:"F" }}</a></li>
+ {% ifchanged month.date.year %}
+ {% if not forloop.first %}</ul>{% endif %}
+ <h4>{{ month.date.year }}</h4><ul>
+ {% endifchanged %}
+ <li><a href="{% url blog_post_list_month year=month.date.year month=month.date.month %}"
+ >{{ month.date|date:"F" }}</a> ({{ month.post_count }})</li>
{% endfor %}
</ul>
{% endif %}
@@ -47,10 +50,13 @@
{% blog_authors as authors %}
{% if authors %}
<h3>{% trans "Authors" %}</h3>
+<ul>
{% for author in authors %}
-<a href="{% url blog_post_list_author author.username %}"
- >{{ author.get_full_name|default:author.username }}</a>
+ <li><a href="{% url blog_post_list_author author.username %}"
+ >{{ author.get_full_name|default:author.username }}</a>
+ ({{ author.post_count }})</li>
{% endfor %}
+</ul>
{% endif %}
<h3>{% trans "Feeds" %}</h3>
@@ -60,12 +60,15 @@ def blog_months(*args):
"""
Put a list of dates for blog posts into the template context.
"""
- months = []
- for month in BlogPost.objects.published().dates("publish_date", "month",
- order="DESC"):
- if month not in months:
- months.append(month)
- return months
+ dates = BlogPost.objects.published().values_list("publish_date", flat=True)
+ date_dicts = [{"date": datetime(d.year, d.month, 1)} for d in dates]
+ month_dicts = []
+ for date_dict in date_dicts:
+ if date_dict not in month_dicts:
+ month_dicts.append(date_dict)
+ for i, date_dict in enumerate(month_dicts):
+ month_dicts[i]["post_count"] = date_dicts.count(date_dict)
+ return month_dicts
@register.as_tag
@@ -108,7 +111,7 @@ def blog_authors(*args):
Put a list of authors (users) for blog posts into the template context.
"""
blog_posts = BlogPost.objects.published()
- return list(User.objects.filter(blogposts__in=blog_posts).distinct())
+ return list(User.objects.filter(blogposts__in=blog_posts).annotate(post_count=Count("blogposts")))
@register.as_tag

0 comments on commit 46518fe

Please sign in to comment.