- def reset_short_html(self):
- if self.id is None:
- return
-
- for area in self.areas.all().iterator():
- area.reset_short_html()
-
- try:
- author = self.tags.filter(category='author')[0].sort_key
- except IndexError:
- author = u''
- type(self).objects.filter(pk=self.pk).update(sort_key_author=author)
-
- cache_key = "Picture.short_html/%d/%s"
- for lang, langname in settings.LANGUAGES:
- permanent_cache.delete(cache_key % (self.id, lang))
-
- def short_html(self):
- if self.id:
- cache_key = "Picture.short_html/%d/%s" % (self.id, get_language())
- short_html = permanent_cache.get(cache_key)
- else:
- short_html = None
-
- if short_html is not None:
- return mark_safe(short_html)
- else:
- tags = self.tags.filter(category__in=('author', 'kind', 'epoch', 'genre'))
- tags = split_tags(tags)
-
- short_html = unicode(render_to_string(
- 'picture/picture_short.html',
- {'picture': self, 'tags': tags}))
-
- if self.id:
- permanent_cache.set(cache_key, short_html)
- return mark_safe(short_html)
-