- def short_html(self):
- if self.id:
- cache_key = "Book.short_html/%d/%s" % (self.id, get_language())
- short_html = cache.get(cache_key)
- else:
- short_html = None
-
- if short_html is not None:
- return mark_safe(short_html)
- else:
- tags = self.tags.filter(~Q(category__in=('set', 'theme', 'book')))
- tags = [mark_safe(u'<a href="%s">%s</a>' % (tag.get_absolute_url(), tag.name)) for tag in tags]
-
- formats = []
- # files generated during publication
- if self.has_media("html"):
- formats.append(u'<a href="%s">%s</a>' % (reverse('book_text', args=[self.fileid()]), _('Read online')))
- for ebook_format in self.ebook_formats:
- if self.has_media(ebook_format):
- formats.append(u'<a href="%s">%s</a>' % (
- self.get_media(ebook_format).url,
- ebook_format.upper()
- ))
- # other files
- for m in self.media.order_by('type'):
- formats.append(u'<a href="%s">%s</a>' % (m.file.url, m.type.upper()))
-
- formats = [mark_safe(format) for format in formats]
-
- short_html = unicode(render_to_string('catalogue/book_short.html',
- {'book': self, 'tags': tags, 'formats': formats}))
-
- if self.id:
- cache.set(cache_key, short_html, CACHE_FOREVER)
- return mark_safe(short_html)
-
- def mini_box(self):
- if self.id:
- cache_key = "Book.mini_boxs/%d" % (self.id, )
- short_html = cache.get(cache_key)
- else:
- short_html = None
-
- if short_html is None:
- authors = self.tags.filter(category='author')
-
- short_html = unicode(render_to_string('catalogue/book_mini_box.html',
- {'book': self, 'authors': authors, 'STATIC_URL': settings.STATIC_URL}))
-
- if self.id:
- cache.set(cache_key, short_html, CACHE_FOREVER)
- return mark_safe(short_html)
-