# HG changeset patch
# User Brian Neal
# Date 1245011122 0
# Node ID 2763977301c21636b87530d83e9ea9640379eaf5
# Parent 48b221d304c63089365513aeb4f00dfd9993a544
Added support for caching. The avatar template tag now uses the cache.
diff -r 48b221d304c6 -r 2763977301c2 gpp/bio/templatetags/avatar_tags.py
--- a/gpp/bio/templatetags/avatar_tags.py Fri Jun 12 02:37:28 2009 +0000
+++ b/gpp/bio/templatetags/avatar_tags.py Sun Jun 14 20:25:22 2009 +0000
@@ -3,30 +3,38 @@
"""
from django import template
from django.conf import settings
+from django.core.cache import cache
register = template.Library()
@register.simple_tag
def avatar(user, align='bottom'):
- alt = user.username
- title = alt
- try:
+ cache_key = 'avatar_' + user.username
+ img_tag = cache.get(cache_key)
+ if img_tag:
+ return img_tag
+
+ alt = user.username
+ title = alt
+ try:
profile = user.get_profile()
- except:
+ except:
profile = None
- if profile is None or profile.avatar.name == '':
+ if profile is None or profile.avatar.name == '':
url = settings.AVATAR_DEFAULT_URL
width = settings.MAX_AVATAR_SIZE_PIXELS
height = settings.MAX_AVATAR_SIZE_PIXELS
- else:
+ else:
url = profile.avatar.url
width = profile.avatar.width
height = profile.avatar.height
- style = ''
- if align == 'left':
+ style = ''
+ if align == 'left':
style = 'style="float:left;margin-right:3px;"'
- return u""" """ % (
+ img_tag = u""" """ % (
url, alt, title, width, height, style)
+ cache.set(cache_key, img_tag)
+ return img_tag
diff -r 48b221d304c6 -r 2763977301c2 gpp/settings.py
--- a/gpp/settings.py Fri Jun 12 02:37:28 2009 +0000
+++ b/gpp/settings.py Sun Jun 14 20:25:22 2009 +0000
@@ -134,6 +134,15 @@
FILE_UPLOAD_PERMISSIONS = 0640
#######################################################################
+# Caching
+#######################################################################
+if local_settings.USE_CACHE:
+ CACHE_BACKEND = local_settings.CACHE_BACKEND
+ #CACHE_MIDDLEWARE_SECONDS = local_settings.CACHE_MIDDLEWARE_SECONDS
+ #CACHE_MIDDLEWARE_KEY_PREFIX = local_settings.CACHE_MIDDLEWARE_KEY_PREFIX
+ #CACHE_MIDDLEWARE_ANONYMOUS_ONLY = local_settings.CACHE_MIDDLEWARE_ANONYMOUS_ONLY
+
+#######################################################################
# Tagging Specific Settings
#######################################################################
FORCE_LOWERCASE_TAGS = True
diff -r 48b221d304c6 -r 2763977301c2 gpp/templates/base.html
--- a/gpp/templates/base.html Fri Jun 12 02:37:28 2009 +0000
+++ b/gpp/templates/base.html Sun Jun 14 20:25:22 2009 +0000
@@ -7,6 +7,7 @@
{% load potd_tags %}
{% load messages_tags %}
{% load script_tags %}
+{% load cache %}
SurfGuitar101.com | {% block title %}{% endblock %}
@@ -63,7 +64,9 @@
Links
Downloads
- {% photo_of_the_day %}
+ {% cache 300 potd_block %}
+ {% photo_of_the_day %}
+ {% endcache %}
{% shoutbox %}
{% irc_status %}
diff -r 48b221d304c6 -r 2763977301c2 gpp/templates/home.html
--- a/gpp/templates/home.html Fri Jun 12 02:37:28 2009 +0000
+++ b/gpp/templates/home.html Sun Jun 14 20:25:22 2009 +0000
@@ -3,6 +3,7 @@
{% load news_tags %}
{% load weblinks_tags %}
{% load downloads_tags %}
+{% load cache %}
{% block title %}Home{% endblock %}
{% block custom_css %}
@@ -35,6 +36,7 @@
permanent. The site (content, user accounts, etc.) may be wiped at any time while we fix bugs and add features.
Also, I hope that the look and feel of this site can be greatly improved to something really cool! I'll need
lots of help for this aspect, as I'm more of a coder than a designer.
+{% cache 600 home_content %}
{% current_bulletins %}
{% current_news %}
@@ -43,4 +45,5 @@
{% latest_downloads %}
+{% endcache %}
{% endblock %}