X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/8705c980a8a35af6c4fc6e309f389bc1aae0b6d7..312d803612945fabb774fc959bc36e654c872e1a:/apps/api/handlers/library_handlers.py diff --git a/apps/api/handlers/library_handlers.py b/apps/api/handlers/library_handlers.py index 27ff47d3..e2d986ee 100755 --- a/apps/api/handlers/library_handlers.py +++ b/apps/api/handlers/library_handlers.py @@ -4,12 +4,8 @@ import os.path import logging log = logging.getLogger('platforma.api.library') -__author__= "Łukasz Rekucki" -__date__ = "$2009-09-25 15:49:50$" -__doc__ = "Module documentation." - from piston.handler import BaseHandler, AnonymousBaseHandler -from django.http import HttpResponse +from piston.utils import rc from datetime import date @@ -19,10 +15,8 @@ from django.db import IntegrityError import librarian import librarian.html import difflib -from librarian import dcparser, parser +import wlrepo -import wlrepo -from api.models import PullRequest from explorer.models import GalleryForDocument # internal imports @@ -184,26 +178,6 @@ class LibraryHandler(BaseHandler): # # Document Handlers # -class BasicDocumentHandler(AnonymousBaseHandler): - allowed_methods = ('GET',) - - @hglibrary - def read(self, request, docid, lib): - try: - doc = lib.document(docid) - except wlrepo.RevisionNotFound: - return rc.NOT_FOUND - - result = { - 'name': doc.id, - 'html_url': reverse('dochtml_view', args=[doc.id]), - 'text_url': reverse('doctext_view', args=[doc.id]), - 'dc_url': reverse('docdc_view', args=[doc.id]), - 'public_revision': doc.revision, - } - - return result - class DiffHandler(BaseHandler): allowed_methods = ('GET',) @@ -233,7 +207,6 @@ class DiffHandler(BaseHandler): # class DocumentHandler(BaseHandler): allowed_methods = ('GET', 'PUT') - anonymous = BasicDocumentHandler @validate_form(forms.DocumentRetrieveForm, 'GET') @hglibrary @@ -356,7 +329,7 @@ class DocumentHTMLHandler(BaseHandler): # class DocumentGalleryHandler(BaseHandler): - allowed_methods = ('GET') + allowed_methods = ('GET', 'POST') def read(self, request, docid): @@ -401,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