X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/b2dfa52bb8e6aeb20dd6a9d397d3b87e71aa7a4e..62f4867f53b4397e820e0e59c240fbe27582f26e:/apps/api/handlers.py?ds=sidebyside diff --git a/apps/api/handlers.py b/apps/api/handlers.py index 352e35e4..2f2bea12 100644 --- a/apps/api/handlers.py +++ b/apps/api/handlers.py @@ -9,6 +9,8 @@ from datetime import date from django.core.urlresolvers import reverse from wlrepo import MercurialLibrary, CabinetNotFound +from librarian import dcparser + # # Document List Handlers # @@ -98,7 +100,10 @@ class BasicDocumentHandler(AnonymousBaseHandler): result['parts'] = document.parts() return result - + +# +# Document Meta Data +# class DocumentHandler(BaseHandler): allowed_methods = ('GET', 'PUT') anonymous = BasicDocumentHandler @@ -113,6 +118,9 @@ class DocumentHandler(BaseHandler): document = lib.cabinet(docid, request.user.username, \ create=opts.cleaned_data['autocabinet'] ).retrieve() + + if not document: + return rc.NOT_HERE shared = lib.main_cabinet.retrieve(docid) @@ -154,4 +162,35 @@ class DocumentTextHandler(BaseHandler): lib.document(docid, request.user.username).write(data) return rc.ALL_OK except (CabinetNotFound, KeyError): - return rc.NOT_HERE \ No newline at end of file + return rc.NOT_HERE + + +# +# Dublin Core handlers +# +# @requires librarian +# +class DocumentDublinCoreHandler(BaseHandler): + allowed_methods = ('GET', 'PUT') + + def read(self, request, docid): + """Read document as raw text""" + lib = MercurialLibrary(path=settings.REPOSITORY_PATH) + try: + doc = lib.document(docid, request.user.username) + + # TODO: RAL:document should support file-like ops + bookinfo = dcparser.BookInfo.from_string(doc.read()) + return bookinfo.serialize() + except CabinetNotFound: + return rc.NOT_HERE + + def update(self, request, docid): + lib = MercurialLibrary(path=settings.REPOSITORY_PATH) + try: + data = request.PUT['contents'] + lib.document(docid, request.user.username).write(data) + return rc.ALL_OK + except (CabinetNotFound, KeyError): + return rc.NOT_HERE +