# HG changeset patch # User Brian Neal # Date 1280700841 0 # Node ID f53eb0aae7a975efe995ebb9b851992af5560cb2 # Parent 6dde069debd4b6c6c42b5ba220c8dd174f43824e Fix #89; avatar caching was broken. diff -r 6dde069debd4 -r f53eb0aae7a9 gpp/bio/templatetags/avatar_tags.py --- a/gpp/bio/templatetags/avatar_tags.py Sun Aug 01 21:30:22 2010 +0000 +++ b/gpp/bio/templatetags/avatar_tags.py Sun Aug 01 22:14:01 2010 +0000 @@ -10,31 +10,35 @@ @register.simple_tag def avatar(user, align='bottom'): + """Returns the HTML for a user's avatar image.""" + + # In the cache is stored a tuple containing info about the + # avatar: (url, width, height) cache_key = 'avatar_' + user.username - img_tag = cache.get(cache_key) - if img_tag: - return img_tag + img_info = cache.get(cache_key) + if img_info is None: + try: + profile = user.get_profile() + except: + profile = None + if profile is None or profile.avatar.name == '': + img_info = (settings.AVATAR_DEFAULT_URL, + settings.MAX_AVATAR_SIZE_PIXELS, + settings.MAX_AVATAR_SIZE_PIXELS) + else: + img_info = (profile.avatar.url, profile.avatar.width, + profile.avatar.height) + cache.set(cache_key, img_info) alt = user.username title = alt - try: - profile = user.get_profile() - except: - profile = None - 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: - url = profile.avatar.url - width = profile.avatar.width - height = profile.avatar.height style = '' if align == 'left': style = 'style="float:left;margin-right:3px;"' + # other styles not supported - img_tag = u"""%s""" % ( - url, alt, title, width, height, style) - cache.set(cache_key, img_tag) + img_tag = (u'%s') % ( + img_info[0], alt, title, img_info[1], img_info[2], style) return img_tag