X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/f906193db2ec44590f57beae2e8ee2df76117b7b..53d1af7d218c1b0e07165a029d6002338933eb36:/apps/api/handlers.py?ds=sidebyside diff --git a/apps/api/handlers.py b/apps/api/handlers.py index e10a4b5a2..f99dd90ab 100644 --- a/apps/api/handlers.py +++ b/apps/api/handlers.py @@ -15,6 +15,7 @@ from api.helpers import timestamp from api.models import Deleted from catalogue.forms import BookImportForm from catalogue.models import Book, Tag, BookMedia, Fragment +from picture.models import Picture from stats.utils import piwik_track @@ -249,9 +250,8 @@ class TagsHandler(BaseHandler): except KeyError, e: return rc.NOT_FOUND - tags = Tag.objects.filter(category=category_sng) - tags = [t for t in tags if t.get_count() > 0] - if tags: + tags = Tag.objects.filter(category=category_sng).exclude(book_count=0) + if tags.exists(): return tags else: return rc.NOT_FOUND @@ -518,7 +518,7 @@ class CatalogueHandler(BaseHandler): changed_at__gte=since, changed_at__lt=until): # only serve non-empty tags - if tag.get_count(): + if tag.book_count: tag_d = cls.tag_dict(tag, fields) updated.append(tag_d) elif tag.created_at < since: @@ -581,3 +581,21 @@ class ChangesHandler(CatalogueHandler): @piwik_track def read(self, request, since): return self.changes(request, since) + + +class PictureHandler(BaseHandler): + model = Picture + fields = ('slug', 'title') + allowed_methods = ('POST',) + + def create(self, request): + if not request.user.has_perm('catalogue.add_book'): + return rc.FORBIDDEN + + data = json.loads(request.POST.get('data')) + form = BookImportForm(data) + if form.is_valid(): + form.save() + return rc.CREATED + else: + return rc.NOT_FOUND