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
import librarian
import librarian.html
import difflib
-from librarian import dcparser, parser
+import wlrepo
-from wlrepo import *
-from api.models import PullRequest
from explorer.models import GalleryForDocument
# internal imports
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])
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",
#
# Document Handlers
#
-class BasicDocumentHandler(AnonymousBaseHandler):
- allowed_methods = ('GET',)
-
- @hglibrary
- def read(self, request, docid, lib):
- try:
- doc = lib.document(docid)
- except 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',)
#
class DocumentHandler(BaseHandler):
allowed_methods = ('GET', 'PUT')
- anonymous = BasicDocumentHandler
@validate_form(forms.DocumentRetrieveForm, 'GET')
@hglibrary
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',
'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
'docid': docid,
'user': user,
})
- except RevisionNotFound, e:
+ except wlrepo.RevisionNotFound, e:
return response.EntityNotFound().django_response({
'reason': 'document-not-found',
'message': e.message,
"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:
#
class DocumentGalleryHandler(BaseHandler):
- allowed_methods = ('GET')
+ allowed_methods = ('GET', 'POST')
def read(self, request, docid):
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