-import os.path
# -*- encoding: utf-8 -*-
+import os.path
+import logging
__author__= "Ćukasz Rekucki"
__date__ = "$2009-09-25 15:49:50$"
#
import settings
+
+log = logging.getLogger('platforma.api')
+
+
#
# Document List Handlers
#
for part, docid in parts:
# this way, we won't display broken links
if not documents.has_key(part):
- print "NOT FOUND:", part
+ log.info("NOT FOUND: %s", part)
continue
parent = documents[docid]
try:
lock = lib.lock()
try:
- print "DOCID", docid
+ log.info("DOCID %s", docid)
doc = lib.document_create(docid)
# document created, but no content yet
result = {
'name': doc.id,
- 'html_url': reverse('dochtml_view', args=[doc.id,doc.revision]),
- 'text_url': reverse('doctext_view', args=[doc.id,doc.revision]),
- 'dc_url': reverse('docdc_view', args=[doc.id,doc.revision]),
+ '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,
}
@hglibrary
def read(self, request, docid, lib):
"""Read document's meta data"""
+ log.info("Read %s", docid)
try:
doc = lib.document(docid)
udoc = doc.take(request.user.username)
result = {
'name': udoc.id,
- 'html_url': reverse('dochtml_view', args=[udoc.id,udoc.revision]),
- 'text_url': reverse('doctext_view', args=[udoc.id,udoc.revision]),
- 'dc_url': reverse('docdc_view', args=[udoc.id,udoc.revision]),
+ 'html_url': reverse('dochtml_view', args=[udoc.id]),
+ 'text_url': reverse('doctext_view', args=[udoc.id]),
+ 'dc_url': reverse('docdc_view', args=[udoc.id]),
'gallery_url': reverse('docgallery_view', args=[udoc.id]),
'merge_url': reverse('docmerge_view', args=[udoc.id]),
'user_revision': udoc.revision,
allowed_methods = ('GET')
@hglibrary
- def read(self, request, docid, revision, lib):
+ def read(self, request, docid, lib):
"""Read document as html text"""
try:
+ revision = request.GET.get('revision', 'latest')
+
if revision == 'latest':
document = lib.document(docid)
else:
return response.BadRequest().django_response({'reason': 'name-mismatch',
'message': 'Provided revision refers, to document "%s", but provided "%s"' % (document.id, docid) })
- return librarian.html.transform(document.data('xml'), is_file=False)
+ return librarian.html.transform(document.data('xml'), is_file=False, parse_dublincore=False)
except (EntryNotFound, RevisionNotFound), e:
return response.EntityNotFound().django_response({
'exception': type(e), 'message': e.message})
dirpath = os.path.join(settings.MEDIA_ROOT, assoc.subpath)
if not os.path.isdir(dirpath):
- print u"[WARNING]: missing gallery %s" % dirpath
+ log.info(u"[WARNING]: missing gallery %s", dirpath)
continue
gallery = {'name': assoc.name, 'pages': []}
for file in sorted(os.listdir(dirpath), key=natural_order()):
- print file
+ log.info(file)
name, ext = os.path.splitext(os.path.basename(file))
if ext.lower() not in ['.png', '.jpeg', '.jpg']:
- print "Ignoring:", name, ext
+ log.info("Ignoring: %s %s", name, ext)
continue
url = settings.MEDIA_URL + assoc.subpath + u'/' + file.decode('utf-8');
#
#
class DocumentTextHandler(BaseHandler):
- allowed_methods = ('GET', 'PUT')
+ allowed_methods = ('GET', 'POST')
@hglibrary
- def read(self, request, docid, revision, lib):
- """Read document as raw text"""
+ def read(self, request, docid, lib):
+ """Read document as raw text"""
+ revision = request.GET.get('revision', 'latest')
try:
if revision == 'latest':
document = lib.document(docid)
'exception': type(e), 'message': e.message})
@hglibrary
- def update(self, request, docid, revision, lib):
+ def create(self, request, docid, lib):
try:
- data = request.PUT['contents']
+ data = request.POST['contents']
+ revision = request.POST['revision']
- if request.PUT.has_key('message'):
- msg = u"$USER$ " + request.PUT['message']
+ if request.POST.has_key('message'):
+ msg = u"$USER$ " + request.POST['message']
else:
msg = u"$AUTO$ XML content update."
includes = [m.groupdict()['link'] for m in (re.finditer(\
XINCLUDE_REGEXP, data, flags=re.UNICODE) or []) ]
- print "INCLUDES: ", includes
+ log.info("INCLUDES: %s", includes)
# TODO: provide useful routines to make this simpler
def xml_update_action(lib, resolve):
"previous_revision": current.revision,
"revision": ndoc.revision,
'timestamp': ndoc.revision.timestamp,
- "url": reverse("doctext_view", args=[ndoc.id, ndoc.revision])
+ "url": reverse("doctext_view", args=[ndoc.id])
})
except Exception, e:
if ndoc: lib._rollback()
# @requires librarian
#
class DocumentDublinCoreHandler(BaseHandler):
- allowed_methods = ('GET', 'PUT')
+ allowed_methods = ('GET', 'POST')
@hglibrary
- def read(self, request, docid, revision, lib):
+ def read(self, request, docid, lib):
"""Read document as raw text"""
try:
+ revision = request.GET.get('revision', 'latest')
+
if revision == 'latest':
doc = lib.document(docid)
else:
'exception': type(e), 'message': e.message})
@hglibrary
- def update(self, request, docid, revision, lib):
+ def create(self, request, docid, lib):
try:
- bi_json = request.PUT['contents']
- if request.PUT.has_key('message'):
+ bi_json = request.POST['contents']
+ revision = request.POST['revision']
+
+ if request.POST.has_key('message'):
msg = u"$USER$ " + request.PUT['message']
else:
msg = u"$AUTO$ Dublin core update."
"previous_revision": current.revision,
"revision": ndoc.revision,
'timestamp': ndoc.revision.timestamp,
- "url": reverse("docdc_view", args=[ndoc.id, ndoc.revision])
+ "url": reverse("docdc_view", args=[ndoc.id])
}
except Exception, e:
if ndoc: lib._rollback()
success, changed = udoc.share(form.cleaned_data['message'])
if not success:
- return response.EntityConflict().django_response({})
+ return response.EntityConflict().django_response({
+ 'reason': 'merge-failure',
+ })
if not changed:
return response.SuccessNoContent().django_response()