X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/99f6dd4f1ff0390de9a9bbd4e3352b953cb9a235..0bd51a33b9ffe994541ccd02fc850d47ac82ccec:/apps/api/handlers.py diff --git a/apps/api/handlers.py b/apps/api/handlers.py index c118d95df..e1792af13 100644 --- a/apps/api/handlers.py +++ b/apps/api/handlers.py @@ -4,12 +4,12 @@ # from datetime import datetime, timedelta import json -from urlparse import urljoin from django.conf import settings from django.contrib.sites.models import Site from django.core.cache import get_cache from django.core.urlresolvers import reverse +from django.utils.functional import lazy from django.utils.timezone import utc from piston.handler import AnonymousBaseHandler, BaseHandler from piston.utils import rc @@ -26,7 +26,8 @@ from wolnelektury.utils import tz from stats.utils import piwik_track -API_BASE = WL_BASE = MEDIA_BASE = 'http://' + Site.objects.get_current().domain +API_BASE = WL_BASE = MEDIA_BASE = lazy( + lambda: u'http://' + Site.objects.get_current().domain, unicode)() category_singular = { @@ -37,7 +38,7 @@ category_singular = { 'themes': 'theme', 'books': 'book', } -category_plural={} +category_plural = {} for k, v in category_singular.items(): category_plural[v] = k @@ -102,7 +103,6 @@ class BookMediaHandler(BaseHandler): @classmethod def director(cls, media): return media.extra_info.get('director_name', '') - class BookDetails(object): @@ -198,7 +198,7 @@ class AnonymousBooksHandler(AnonymousBaseHandler, BookDetails): books = Book.tagged.with_all(tags) else: books = Book.objects.all() - + if top_level: books = books.filter(parent=None) if audiobooks: @@ -295,7 +295,6 @@ class CollectionDetailHandler(BaseHandler, CollectionDetails): @piwik_track def read(self, request, slug): - print slug """ Returns details of a collection, identified by slug. """ try: return Collection.objects.get(slug=slug) @@ -384,7 +383,7 @@ class FragmentDetails(object): def href(cls, fragment): """ Returns URI in the API for the fragment. """ - return API_BASE + reverse("api_fragment", + return API_BASE + reverse("api_fragment", args=[fragment.book.slug, fragment.anchor]) @classmethod @@ -561,7 +560,7 @@ class CatalogueHandler(BaseHandler): if updated: changes['updated'] = updated - for book in Deleted.objects.filter(content_type=Book, + for book in Deleted.objects.filter(content_type=Book, deleted_at__gte=since, deleted_at__lt=until, created_at__lt=since).iterator(): @@ -626,7 +625,7 @@ class CatalogueHandler(BaseHandler): updated = [] deleted = [] - for tag in Tag.objects.filter(category__in=categories, + for tag in Tag.objects.filter(category__in=categories, changed_at__gte=since, changed_at__lt=until).iterator(): # only serve non-empty tags @@ -639,7 +638,7 @@ class CatalogueHandler(BaseHandler): changes['updated'] = updated for tag in Deleted.objects.filter(category__in=categories, - content_type=Tag, + content_type=Tag, deleted_at__gte=since, deleted_at__lt=until, created_at__lt=since).iterator():