X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/b093ccb2e9454bb3d60e5d3e3a49e37e02125b2b..465f9d370fb3b96b4cc30e139d24e4479a9f7ab0:/apps/api/handlers/library_handlers.py?ds=inline diff --git a/apps/api/handlers/library_handlers.py b/apps/api/handlers/library_handlers.py index 948bad4b..e2d986ee 100755 --- a/apps/api/handlers/library_handlers.py +++ b/apps/api/handlers/library_handlers.py @@ -5,6 +5,7 @@ import logging log = logging.getLogger('platforma.api.library') from piston.handler import BaseHandler, AnonymousBaseHandler +from piston.utils import rc from datetime import date @@ -14,8 +15,8 @@ from django.db import IntegrityError import librarian import librarian.html import difflib +import wlrepo -from wlrepo import * from explorer.models import GalleryForDocument # internal imports @@ -150,7 +151,7 @@ class LibraryHandler(BaseHandler): import traceback # rollback branch creation lib._rollback() - raise LibraryException(traceback.format_exc()) + raise wlrepo.LibraryException(traceback.format_exc()) url = reverse('document_view', args=[doc.id]) @@ -162,12 +163,12 @@ class LibraryHandler(BaseHandler): url = url ) finally: lock.release() - except LibraryException, e: + except wlrepo.LibraryException, e: import traceback return response.InternalError().django_response({ "reason": traceback.format_exc() }) - except DocumentAlreadyExists: + except wlrepo.DocumentAlreadyExists: # Document is already there return response.EntityConflict().django_response({ "reason": "already-exists", @@ -177,6 +178,7 @@ class LibraryHandler(BaseHandler): # # Document Handlers # + class DiffHandler(BaseHandler): allowed_methods = ('GET',) @@ -221,7 +223,7 @@ class DocumentHandler(BaseHandler): try: doc = lib.document(docid, user, rev=rev) - except RevisionMismatch, e: + except wlrepo.RevisionMismatch, e: # the document exists, but the revision is bad return response.EntityNotFound().django_response({ 'reason': 'revision-mismatch', @@ -229,7 +231,7 @@ class DocumentHandler(BaseHandler): 'docid': docid, 'user': user, }) - except RevisionNotFound, e: + except wlrepo.RevisionNotFound, e: # the user doesn't have this document checked out # or some other weird error occured # try to do the checkout @@ -249,7 +251,7 @@ class DocumentHandler(BaseHandler): 'docid': docid, 'user': user, }) - except RevisionNotFound, e: + except wlrepo.RevisionNotFound, e: return response.EntityNotFound().django_response({ 'reason': 'document-not-found', 'message': e.message, @@ -312,7 +314,7 @@ class DocumentHTMLHandler(BaseHandler): "with-paths": 'boolean(1)', }) - except (EntryNotFound, RevisionNotFound), e: + except (wlrepo.EntryNotFound, wlrepo.RevisionNotFound), e: return response.EntityNotFound().django_response({ 'reason': 'not-found', 'message': e.message}) except librarian.ValidationError, e: @@ -327,7 +329,7 @@ class DocumentHTMLHandler(BaseHandler): # class DocumentGalleryHandler(BaseHandler): - allowed_methods = ('GET') + allowed_methods = ('GET', 'POST') def read(self, request, docid): @@ -372,7 +374,27 @@ class DocumentGalleryHandler(BaseHandler): return galleries - + def create(self, request, docid): + if not request.user.is_superuser: + return rc.FORBIDDEN + + new_path = request.POST.get('path') + + if new_path: + gallery, created = GalleryForDocument.objects.get_or_create( + document = docid, + defaults = { + 'subpath': new_path, + } + ) + + if not created: + gallery.subpath = new_path + gallery.save() + + return rc.CREATED + + return rc.BAD_REQUEST # # Dublin Core handlers