tag page, short_html
authorMarcin Koziej <marcin.koziej@nowoczesnapolska.org.pl>
Wed, 21 Dec 2011 15:57:36 +0000 (16:57 +0100)
committerMarcin Koziej <marcin.koziej@nowoczesnapolska.org.pl>
Wed, 21 Dec 2011 15:57:36 +0000 (16:57 +0100)
apps/catalogue/models.py
apps/catalogue/urls.py
apps/catalogue/views.py
apps/picture/models.py
wolnelektury/settings.py
wolnelektury/templates/catalogue/picture_detail.html

index d615fb6..288a189 100644 (file)
@@ -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_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()
         # Fragment.short_html relies on book's tags, so reset it here too
         for fragm in self.fragments.all():
             fragm.reset_short_html()
index 0e62c30..0b2a1bb 100644 (file)
@@ -7,7 +7,12 @@ from catalogue.feeds import AudiobookFeed
 from catalogue.models import Book
 from picture.models import Picture
 
 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<picture>%s)/?$' % Picture.URLID_RE, 'picture_detail')
+        ) + \
+    patterns('catalogue.views',
     url(r'^$', 'catalogue', name='catalogue'),
     url(r'^polki/(?P<shelf>[a-zA-Z0-9-]+)/formaty/$', 'shelf_book_formats', name='shelf_book_formats'),
     url(r'^polki/(?P<shelf>[a-zA-Z0-9-]+)/(?P<book>%s)/usun$' % Book.URLID_RE, 'remove_from_shelf', name='remove_from_shelf'),
     url(r'^$', 'catalogue', name='catalogue'),
     url(r'^polki/(?P<shelf>[a-zA-Z0-9-]+)/formaty/$', 'shelf_book_formats', name='shelf_book_formats'),
     url(r'^polki/(?P<shelf>[a-zA-Z0-9-]+)/(?P<book>%s)/usun$' % Book.URLID_RE, 'remove_from_shelf', name='remove_from_shelf'),
@@ -41,9 +46,4 @@ urlpatterns = patterns('catalogue.views',
 
     url(r'^custompdf/(?P<book_fileid>%s).pdf' % Book.FILEID_RE, 'download_custom_pdf'),
 
 
     url(r'^custompdf/(?P<book_fileid>%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<picture>%s)/?$' % Picture.URLID_RE, 'picture_detail')
-    )
-
+) 
index 57a4975..f1eeab7 100644 (file)
@@ -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 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)
 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=''):
 
 
 def tagged_object_list(request, tags=''):
+    #    import pdb; pdb.set_trace()
     try:
         tags = models.Tag.get_tag_list(tags)
     except models.Tag.DoesNotExist:
     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()
 
         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,
     return object_list(
         request,
         objects,
index 2d24408..1dfd596 100644 (file)
@@ -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.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
 
 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)
 
 
         ret = super(Picture, self).save(force_insert, force_update)
 
+        if reset_short_html:
+            self.reset_short_html()
+
         return ret
 
     def __unicode__(self):
         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
             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)
index b597e33..e476d13 100644 (file)
@@ -170,6 +170,7 @@ COMPRESS_CSS = {
             'css/header.css',
             'css/main_page.css',
             'css/dialogs.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',
             'css/book_box.css',
             'css/catalogue.css',
             'css/sponsors.css',
index f4aabb4..b059709 100644 (file)
@@ -22,7 +22,7 @@
         </div>
 
        {% thumbnail picture.image_file "400x500" upscale="false" as im %}
         </div>
 
        {% thumbnail picture.image_file "400x500" upscale="false" as im %}
-       <img style="margin:{{ im|margin:"400x500" }}" src="{{ im.url }}" width="{{ im.x }}" height="{{ im.y }}" />
+       <img style="margin:{{ im|margin:"500x500" }}" src="{{ im.url }}" width="{{ im.x }}" height="{{ im.y }}" />
        {% endthumbnail %}
 
         {% if picture.info.license %}
        {% endthumbnail %}
 
         {% if picture.info.license %}
@@ -32,7 +32,7 @@
         {% if picture.info.description %}
             <div id="description">
                 <div id='description-long'>{{ picture.info.description|safe }}</div>
         {% if picture.info.description %}
             <div id="description">
                 <div id='description-long'>{{ picture.info.description|safe }}</div>
-                <div id='description-short'>{{ picture.info.description|safe|truncatewords_html:30 }}</div>
+{%comment%}                <div id='description-short'>{{ picture.info.description|safe|truncatewords_html:30 }}</div>{%endcomment%}
             </div>
             <div id="toggle-description"><p></p></div>
         {% endif %}
             </div>
             <div id="toggle-description"><p></p></div>
         {% endif %}