Minor presentation fixes.
[wolnelektury.git] / apps / opds / views.py
index 4dd1ca2..c529e02 100644 (file)
@@ -12,6 +12,7 @@ from django.utils.feedgenerator import Atom1Feed
 from django.conf import settings
 from django.http import Http404
 from django.contrib.sites.models import Site
 from django.conf import settings
 from django.http import Http404
 from django.contrib.sites.models import Site
+from django.utils.functional import lazy
 
 from basicauth import logged_in_or_basicauth, factory_decorator
 from catalogue.models import Book, Tag
 
 from basicauth import logged_in_or_basicauth, factory_decorator
 from catalogue.models import Book, Tag
@@ -64,21 +65,22 @@ _root_feeds = (
 )
 
 
 )
 
 
+current_domain = lazy(lambda: Site.objects.get_current().domain, str)()
 def full_url(url):
 def full_url(url):
-    return urljoin("http://%s" % Site.objects.get_current().domain, url)
+    return urljoin("http://%s" % current_domain, url)
 
 
 class OPDSFeed(Atom1Feed):
     link_rel = u"subsection"
     link_type = u"application/atom+xml"
 
 
 
 class OPDSFeed(Atom1Feed):
     link_rel = u"subsection"
     link_type = u"application/atom+xml"
 
-    _book_parent_img = full_url(os.path.join(settings.STATIC_URL, "img/book-parent.png"))
+    _book_parent_img = lazy(lambda: full_url(os.path.join(settings.STATIC_URL, "img/book-parent.png")), str)()
     try:
         _book_parent_img_size = unicode(os.path.getsize(os.path.join(settings.STATIC_ROOT, "img/book-parent.png")))
     except:
         _book_parent_img_size = ''
 
     try:
         _book_parent_img_size = unicode(os.path.getsize(os.path.join(settings.STATIC_ROOT, "img/book-parent.png")))
     except:
         _book_parent_img_size = ''
 
-    _book_img = full_url(os.path.join(settings.STATIC_URL, "img/book.png"))
+    _book_img = lazy(lambda: full_url(os.path.join(settings.STATIC_URL, "img/book.png")), str)()
     try:
         _book_img_size = unicode(os.path.getsize(os.path.join(settings.STATIC_ROOT, "img/book.png")))
     except:
     try:
         _book_img_size = unicode(os.path.getsize(os.path.join(settings.STATIC_ROOT, "img/book.png")))
     except:
@@ -236,7 +238,7 @@ class ByCategoryFeed(Feed):
         return feed['title']
 
     def items(self, feed):
         return feed['title']
 
     def items(self, feed):
-        return Tag.objects.filter(category=feed['category']).exclude(book_count=0)
+        return Tag.objects.filter(category=feed['category']).exclude(items=None)
 
     def item_title(self, item):
         return item.name
 
     def item_title(self, item):
         return item.name
@@ -262,13 +264,7 @@ class ByTagFeed(AcquisitionFeed):
         return get_object_or_404(Tag, category=category, slug=slug)
 
     def items(self, tag):
         return get_object_or_404(Tag, category=category, slug=slug)
 
     def items(self, tag):
-        books = Book.tagged.with_any([tag])
-        l_tags = Tag.objects.filter(category='book', slug__in=[book.book_tag_slug() for book in books.iterator()])
-        descendants_keys = [book.pk for book in Book.tagged.with_any(l_tags)]
-        if descendants_keys:
-            books = books.exclude(pk__in=descendants_keys)
-
-        return books
+        return Book.tagged_top_level([tag])
 
 
 @factory_decorator(logged_in_or_basicauth())
 
 
 @factory_decorator(logged_in_or_basicauth())
@@ -287,7 +283,7 @@ class UserFeed(Feed):
         return u"Półki użytkownika %s" % user.username
 
     def items(self, user):
         return u"Półki użytkownika %s" % user.username
 
     def items(self, user):
-        return Tag.objects.filter(category='set', user=user).exclude(book_count=0)
+        return Tag.objects.filter(category='set', user=user).exclude(items=None)
 
     def item_title(self, item):
         return item.name
 
     def item_title(self, item):
         return item.name
@@ -298,9 +294,6 @@ class UserFeed(Feed):
     def item_description(self):
         return u''
 
     def item_description(self):
         return u''
 
-# no class decorators in python 2.5
-#UserFeed = factory_decorator(logged_in_or_basicauth())(UserFeed)
-
 
 @factory_decorator(logged_in_or_basicauth())
 @piwik_track
 
 @factory_decorator(logged_in_or_basicauth())
 @piwik_track
@@ -320,9 +313,6 @@ class UserSetFeed(AcquisitionFeed):
     def items(self, tag):
         return Book.tagged.with_any([tag])
 
     def items(self, tag):
         return Book.tagged.with_any([tag])
 
-# no class decorators in python 2.5
-#UserSetFeed = factory_decorator(logged_in_or_basicauth())(UserSetFeed)
-
 
 @piwik_track
 class SearchFeed(AcquisitionFeed):
 
 @piwik_track
 class SearchFeed(AcquisitionFeed):