X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/b348abeb083671e831f711d3d41949a9b3f3a7b4..826d67400c317836cd9dd02bb03b39a390e4514b:/apps/api/handlers/library_handlers.py diff --git a/apps/api/handlers/library_handlers.py b/apps/api/handlers/library_handlers.py index 7db7b795..d2c6ec32 100644 --- a/apps/api/handlers/library_handlers.py +++ b/apps/api/handlers/library_handlers.py @@ -52,33 +52,32 @@ class LibraryHandler(BaseHandler): documents = {} for docid in lib.documents(): + docid = docid.decode('utf-8') documents[docid] = { 'url': reverse('document_view', args=[docid]), 'name': docid, 'parts': [] } - related = PartCache.objects.defer('part_id')\ + parts = PartCache.objects.defer('part_id')\ .values_list('part_id', 'document_id').distinct() + + document_tree = dict(documents) - for part, docid in related: + for part, docid in parts: # this way, we won't display broken links if not documents.has_key(part): + print "NOT FOUND:", part continue - child = documents[part] parent = documents[docid] + child = documents[part] + + # not top-level anymore + document_tree.pop(part) + parent['parts'].append(child) - if isinstance(parent, dict): # the parent is top-level - documents.pop(part) - parent['parts'].append(child) - documents[part] = child['parts'] - else: # not top-level - parent.append(child) - - return { - 'documents': [d for d in documents.itervalues() if isinstance(d, dict)] - } + return {'documents': sorted(document_tree.values()) } @validate_form(forms.DocumentUploadForm, 'POST') @hglibrary @@ -175,6 +174,7 @@ class DocumentHandler(BaseHandler): '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]), + #'gallery_url': reverse('docdc_view', args=[udoc.id,udoc.revision]), 'user_revision': udoc.revision, 'public_revision': doc.revision, } @@ -204,9 +204,6 @@ class DocumentHTMLHandler(BaseHandler): except RevisionNotFound: return response.EntityNotFound().django_response() - - - # # Document Text View # @@ -214,6 +211,7 @@ class DocumentHTMLHandler(BaseHandler): XINCLUDE_REGEXP = r"""<(?:\w+:)?include\s+[^>]*?href=("|')wlrepo://(?P[^\1]+?)\1\s*[^>]*?>""" # # +# class DocumentTextHandler(BaseHandler): allowed_methods = ('GET', 'PUT') @@ -254,6 +252,8 @@ class DocumentTextHandler(BaseHandler): includes = [m.groupdict()['link'] for m in (re.finditer(\ XINCLUDE_REGEXP, data, flags=re.UNICODE) or []) ] + print "INCLUDES: ", includes + # TODO: provide useful routines to make this simpler def xml_update_action(lib, resolve): try: @@ -276,7 +276,7 @@ class DocumentTextHandler(BaseHandler): # now that the parts are ok, write xml f = lib._fileopen(resolve('xml'), 'w+') - f.write(data) + f.write(data.encode('utf-8')) f.close() ndoc = None @@ -296,7 +296,9 @@ class DocumentTextHandler(BaseHandler): if ndoc: lib._rollback() raise e except RevisionNotFound, e: - return response.EntityNotFound().django_response(e) + return response.EntityNotFound(mimetype="text/plain").\ + django_response(e.message) + # # Dublin Core handlers @@ -352,16 +354,15 @@ class DocumentDublinCoreHandler(BaseHandler): "document": ndoc.id, "subview": "dc", "previous_revision": current.revision, - "updated_revision": ndoc.revision + "updated_revision": ndoc.revision, + "url": reverse("docdc_view", args=[ndoc.id, ndoc.revision]) } except Exception, e: - lib._rollback() + if ndoc: lib._rollback() raise e except RevisionNotFound: return response.EntityNotFound().django_response() - - class MergeHandler(BaseHandler): allowed_methods = ('POST',)