Merge branch 'master' of stigma.nowoczesnapolska.org.pl:platforma
[redakcja.git] / apps / api / handlers / text_handler.py
old mode 100644 (file)
new mode 100755 (executable)
index 5e34ab4..5f27a2a
@@ -44,7 +44,7 @@ class DocumentTextHandler(BaseHandler):
             user = form.cleaned_data['user'] or request.user.username
             format = form.cleaned_data['format']
 
             user = form.cleaned_data['user'] or request.user.username
             format = form.cleaned_data['format']
 
-            document = lib.document_for_rev(revision)
+            document = lib.document_for_revision(revision)
 
             if document.id != docid:
                 return response.BadRequest().django_response({
 
             if document.id != docid:
                 return response.BadRequest().django_response({
@@ -71,7 +71,7 @@ class DocumentTextHandler(BaseHandler):
 
             if xchunk is None:
                 return response.EntityNotFound().django_response({
 
             if xchunk is None:
                 return response.EntityNotFound().django_response({
-                      'reason': 'no-part-in-document',
+                      'reason': 'no-chunk-in-document',
                       'path': chunk
                 })
 
                       'path': chunk
                 })
 
@@ -92,6 +92,7 @@ class DocumentTextHandler(BaseHandler):
     @validate_form(forms.TextUpdateForm, 'POST')
     @hglibrary
     def create(self, request, form, docid, lib):
     @validate_form(forms.TextUpdateForm, 'POST')
     @hglibrary
     def create(self, request, form, docid, lib):
+        lock = lib.lock();
         try:
             revision = form.cleaned_data['revision']
             msg = form.cleaned_data['message']
         try:
             revision = form.cleaned_data['revision']
             msg = form.cleaned_data['message']
@@ -100,14 +101,13 @@ class DocumentTextHandler(BaseHandler):
             # do not allow changing not owned documents
             # (for now... )
 
             # do not allow changing not owned documents
             # (for now... )
 
-
             if user != request.user.username:
                 return response.AccessDenied().django_response({
                     'reason': 'insufficient-priviliges',
                 })
 
             current = lib.document(docid, user)
             if user != request.user.username:
                 return response.AccessDenied().django_response({
                     'reason': 'insufficient-priviliges',
                 })
 
             current = lib.document(docid, user)
-            orig = lib.document_for_rev(revision)
+            orig = lib.document_for_revision(revision)
 
             if current != orig:
                 return response.EntityConflict().django_response({
 
             if current != orig:
                 return response.EntityConflict().django_response({
@@ -115,11 +115,15 @@ class DocumentTextHandler(BaseHandler):
                         "provided_revision": orig.revision,
                         "latest_revision": current.revision })
 
                         "provided_revision": orig.revision,
                         "latest_revision": current.revision })
 
-            if form.cleaned_data.has_key('contents'):
+            if form.cleaned_data['contents']:
                 data = form.cleaned_data['contents']
             else:
                 chunks = form.cleaned_data['chunks']
                 data = form.cleaned_data['contents']
             else:
                 chunks = form.cleaned_data['chunks']
-                xdoc = parser.WLDocument.from_string(current.data('xml'))
+                data = current.data('xml')
+                log.info(data[:600])
+                log.info(chunks)
+
+                xdoc = parser.WLDocument.from_string(data)               
                 errors = xdoc.merge_chunks(chunks)
 
                 if len(errors):
                 errors = xdoc.merge_chunks(chunks)
 
                 if len(errors):
@@ -130,6 +134,7 @@ class DocumentTextHandler(BaseHandler):
 
                 data = xdoc.serialize()
 
 
                 data = xdoc.serialize()
 
+
             # try to find any Xinclude tags
             includes = [m.groupdict()['link'] for m in (re.finditer(\
                 XINCLUDE_REGEXP, data, flags=re.UNICODE) or []) ]
             # try to find any Xinclude tags
             includes = [m.groupdict()['link'] for m in (re.finditer(\
                 XINCLUDE_REGEXP, data, flags=re.UNICODE) or []) ]
@@ -182,3 +187,5 @@ class DocumentTextHandler(BaseHandler):
         except RevisionNotFound, e:
             return response.EntityNotFound(mimetype="text/plain").\
                 django_response(e.message)
         except RevisionNotFound, e:
             return response.EntityNotFound(mimetype="text/plain").\
                 django_response(e.message)
+        finally:
+                lock.release()