Commits

Josh VanderLinden  committed b3acf57

More on caching. Improved tag cloud code

  • Participants
  • Parent commits 5336c6c

Comments (0)

Files changed (2)

File articles/templatetags/article_tags.py

 
     cache_key = 'tag_cloud_tags'
     tags = cache.get(cache_key)
-    if tags == None:
+    if tags is None:
         MAX_WEIGHT = 5
         tags = Tag.objects.all()
 
+        if len(tags):
+            # go no further
+            return {}
+
         min_count = max_count = tags[0].article_set.count()
         for tag in tags:
             tag.count = tag.article_set.count()

File articles/views.py

 from django.http import HttpResponsePermanentRedirect, Http404, HttpResponseRedirect, HttpResponse
 from django.shortcuts import render_to_response, get_object_or_404
 from django.template import RequestContext
+from django.views.decorators.cache import cache_page
 from articles.models import Article, Tag
 from datetime import datetime
 
 ARTICLE_PAGINATION = getattr(settings, 'ARTICLE_PAGINATION', 20)
 
+@cache_page
 def display_blog_page(request, tag=None, username=None, year=None, month=None, page=1):
     """
     Handles all of the magic behind the pages that list articles in any way.
 
     return render_to_response(template, variables)
 
+@cache_page
 def display_article(request, year, slug, template='articles/article_detail.html'):
     """Displays a single article."""