From: Marcin Koziej Date: Wed, 21 Dec 2011 15:57:36 +0000 (+0100) Subject: tag page, short_html X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/e9cd7fc641895a7702a8f81fcd11c388dd7d9db7?ds=inline;hp=--cc tag page, short_html --- e9cd7fc641895a7702a8f81fcd11c388dd7d9db7 diff --git a/apps/catalogue/models.py b/apps/catalogue/models.py index d615fb65b..288a18906 100644 --- a/apps/catalogue/models.py +++ b/apps/catalogue/models.py @@ -490,7 +490,7 @@ class Book(models.Model): cache_key = "Book.short_html/%d/%s" for lang, langname in settings.LANGUAGES: cache.delete(cache_key % (self.id, lang)) - cache.delete(cache_key = "Book.mini_box/%d" % (self.id, )) + cache.delete("Book.mini_box/%d" % (self.id, )) # Fragment.short_html relies on book's tags, so reset it here too for fragm in self.fragments.all(): fragm.reset_short_html() diff --git a/apps/catalogue/urls.py b/apps/catalogue/urls.py index 0e62c300e..0b2a1bb41 100644 --- a/apps/catalogue/urls.py +++ b/apps/catalogue/urls.py @@ -7,7 +7,12 @@ from catalogue.feeds import AudiobookFeed from catalogue.models import Book from picture.models import Picture -urlpatterns = patterns('catalogue.views', +urlpatterns = patterns('picture.views', + # pictures - currently pictures are coupled with catalogue, hence the url is here + url(r'^obraz/?$', 'picture_list'), + url(r'^obraz/(?P%s)/?$' % Picture.URLID_RE, 'picture_detail') + ) + \ + patterns('catalogue.views', url(r'^$', 'catalogue', name='catalogue'), url(r'^polki/(?P[a-zA-Z0-9-]+)/formaty/$', 'shelf_book_formats', name='shelf_book_formats'), url(r'^polki/(?P[a-zA-Z0-9-]+)/(?P%s)/usun$' % Book.URLID_RE, 'remove_from_shelf', name='remove_from_shelf'), @@ -41,9 +46,4 @@ urlpatterns = patterns('catalogue.views', url(r'^custompdf/(?P%s).pdf' % Book.FILEID_RE, 'download_custom_pdf'), -) + patterns('picture.views', - # pictures - currently pictures are coupled with catalogue, hence the url is here - url(r'^obraz/?$', 'picture_list'), - url(r'^obraz/(?P%s)/?$' % Picture.URLID_RE, 'picture_detail') - ) - +) diff --git a/apps/catalogue/views.py b/apps/catalogue/views.py index 57a4975ac..f1eeab739 100644 --- a/apps/catalogue/views.py +++ b/apps/catalogue/views.py @@ -31,7 +31,9 @@ from catalogue.tasks import touch_tag from pdcounter import models as pdcounter_models from pdcounter import views as pdcounter_views from suggest.forms import PublishingSuggestForm +from picture.models import Picture +from itertools import chain from os import path staff_required = user_passes_test(lambda user: user.is_staff) @@ -88,6 +90,7 @@ def differentiate_tags(request, tags, ambiguous_slugs): def tagged_object_list(request, tags=''): + # import pdb; pdb.set_trace() try: tags = models.Tag.get_tag_list(tags) except models.Tag.DoesNotExist: @@ -166,6 +169,9 @@ def tagged_object_list(request, tags=''): only_author = len(tags) == 1 and tags[0].category == 'author' objects = models.Book.objects.none() + # Add pictures + objects = Picture.tagged.with_all(tags)|objects + return object_list( request, objects, diff --git a/apps/picture/models.py b/apps/picture/models.py index 2d2440884..1dfd59618 100644 --- a/apps/picture/models.py +++ b/apps/picture/models.py @@ -5,6 +5,10 @@ from sorl.thumbnail import ImageField from django.conf import settings from django.core.files.storage import FileSystemStorage from django.utils.datastructures import SortedDict +from django.template.loader import render_to_string +from django.core.cache import cache +from catalogue.utils import split_tags +from django.utils.safestring import mark_safe from librarian import dcparser, picture from slughifi import slughifi @@ -51,6 +55,9 @@ class Picture(models.Model): ret = super(Picture, self).save(force_insert, force_update) + if reset_short_html: + self.reset_short_html() + return ret def __unicode__(self): @@ -147,3 +154,30 @@ class Picture(models.Model): info = dcparser.parse(self.xml_file.path, picture.PictureInfo) self._info = info return self._info + + def reset_short_html(self): + if self.id is None: + return + + cache_key = "Picture.short_html/%d" % (self.id) + cache.delete(cache_key) + + def short_html(self): + if self.id: + cache_key = "Picture.short_html/%d" % (self.id) + 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(category__in=('author', 'kind', 'epoch')) + tags = split_tags(tags) + + short_html = unicode(render_to_string('picture/picture_short.html', + {'picture': self, 'tags': tags})) + + if self.id: + cache.set(cache_key, short_html, catalogue.models.CACHE_FOREVER) + return mark_safe(short_html) diff --git a/wolnelektury/settings.py b/wolnelektury/settings.py index b597e3347..e476d13ce 100644 --- a/wolnelektury/settings.py +++ b/wolnelektury/settings.py @@ -170,6 +170,7 @@ COMPRESS_CSS = { 'css/header.css', 'css/main_page.css', 'css/dialogs.css', + 'css/picture_box.css', 'css/book_box.css', 'css/catalogue.css', 'css/sponsors.css', diff --git a/wolnelektury/templates/catalogue/picture_detail.html b/wolnelektury/templates/catalogue/picture_detail.html index f4aabb456..b0597097f 100644 --- a/wolnelektury/templates/catalogue/picture_detail.html +++ b/wolnelektury/templates/catalogue/picture_detail.html @@ -22,7 +22,7 @@ {% thumbnail picture.image_file "400x500" upscale="false" as im %} - + {% endthumbnail %} {% if picture.info.license %} @@ -32,7 +32,7 @@ {% if picture.info.description %}
{{ picture.info.description|safe }}
-
{{ picture.info.description|safe|truncatewords_html:30 }}
+{%comment%}
{{ picture.info.description|safe|truncatewords_html:30 }}
{%endcomment%}

{% endif %}