Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenmcd committed Feb 24, 2011
2 parents ba756e1 + d1ee0b6 commit 46518fe
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
16 changes: 11 additions & 5 deletions mezzanine/blog/templates/blog/includes/filter_panel.html
Expand Up @@ -15,9 +15,12 @@ <h3>{% trans "Recent Posts" %}</h3>
{% 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 %}
Expand Down Expand Up @@ -47,10 +50,13 @@ <h3>{% trans "Tags" %}</h3>
{% 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>
Expand Down
17 changes: 10 additions & 7 deletions mezzanine/blog/templatetags/blog_tags.py
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 46518fe

Please sign in to comment.