Anonymous committed b3acf57

More on caching. Improved tag cloud code

Comments (0)

Files changed (2)


     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()


 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
 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)
 def display_article(request, year, slug, template='articles/article_detail.html'):
     """Displays a single article."""
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.