HTML dodany do API.
authorŁukasz Rekucki <lrekucki@gmail.com>
Sat, 26 Sep 2009 12:22:39 +0000 (14:22 +0200)
committerŁukasz Rekucki <lrekucki@gmail.com>
Sat, 26 Sep 2009 12:22:39 +0000 (14:22 +0200)
apps/api/handlers/library_handlers.py
apps/api/resources.py
apps/api/urls.py
apps/api/utils.py
apps/explorer/views.py
project/templates/explorer/file_list.html

index 0651352..8862de0 100644 (file)
@@ -7,14 +7,14 @@ __doc__ = "Module documentation."
 from piston.handler import BaseHandler, AnonymousBaseHandler
 
 
-import settings
 import librarian
+import librarian.html
 import api.forms as forms
 from datetime import date
 
 from django.core.urlresolvers import reverse
 
-from wlrepo import MercurialLibrary, RevisionNotFound, DocumentAlreadyExists
+from wlrepo import RevisionNotFound, DocumentAlreadyExists
 from librarian import dcparser
 
 import api.response as response
@@ -98,6 +98,7 @@ class BasicDocumentHandler(AnonymousBaseHandler):
 
         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]),
             'public_revision': doc.revision,
@@ -126,6 +127,7 @@ class DocumentHandler(BaseHandler):
 
         result = {
             'name': udoc.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]),
             'user_revision': udoc.revision,
@@ -138,6 +140,25 @@ class DocumentHandler(BaseHandler):
     def update(self, request, docid, lib):
         """Update information about the document, like display not"""
         return
+#
+#
+#
+
+class DocumentHTMLHandler(BaseHandler):
+    allowed_methods = ('GET', 'PUT')
+
+    @hglibrary
+    def read(self, request, docid, revision, lib):
+        """Read document as html text"""
+        try:
+            if revision == 'latest':
+                document = lib.document(docid)
+            else:
+                document = lib.document_for_rev(revision)
+
+            return librarian.html.transform(document.data('xml'))
+        except RevisionNotFound:
+            return response.EntityNotFound().django_response()
 
 #
 # Document Text View
index 7681436..113d4b6 100644 (file)
@@ -20,6 +20,7 @@ import api.handlers.library_handlers as dh
 library_resource = Resource(dh.LibraryHandler, **authdata)
 document_resource = Resource(dh.DocumentHandler, **authdata)
 document_text_resource = Resource(dh.DocumentTextHandler, **authdata)
+document_html_resource = Resource(dh.DocumentHTMLHandler, **authdata)
 document_dc_resource = Resource(dh.DocumentDublinCoreHandler, **authdata)
 document_merge = Resource(dh.MergeHandler, **authdata)
 
index 8c10158..b36cbe3 100644 (file)
@@ -41,6 +41,10 @@ urlpatterns = patterns('',
         document_text_resource, {'emitter_format': 'rawxml'},
         name="doctext_view"),
 
+    url(urlpath(r'documents', DOC, 'html', REVISION, format=False),
+        document_text_resource, {'emitter_format': 'rawhtml'},
+        name="dochtml_view"),
+
     url(urlpath(r'documents', DOC, 'dc', REVISION),
         document_dc_resource,
         name="docdc_view_withformat"),
index 0e0468a..d8177ab 100644 (file)
@@ -18,8 +18,9 @@ class TextEmitter(Emitter):
     def render(self, request):
         return unicode(self.construct())
 
-Emitter.register('text', TextEmitter, 'text/plain; charset=utf-8')
-Emitter.register('rawxml', TextEmitter, 'application/xml; charset=UTF-8')
+Emitter.register('raw', TextEmitter, 'text/plain; charset=utf-8')
+Emitter.register('rawhtml', TextEmitter, 'text/html; charset=utf-8')
+Emitter.register('rawxml', TextEmitter, 'application/xml; charset=utf-8')
 
 class DjangoAuth(object):
 
index e3ca63a..c10e33b 100644 (file)
@@ -348,27 +348,26 @@ def file_dc(request, path, repo):
 # Display the main editor view
 
 @login_required
-@with_repo
-def display_editor(request, path, repo):    
-
+# @with_repo
+def display_editor(request, path):    
     # this is the only entry point where we create an autobranch for the user
     # if it doesn't exists. All other views SHOULD fail.
-    def ensure_branch_exists():
-        parent = repo.get_branch_tip('default')
-        repo._create_branch(file_branch(path, request.user), parent)
+    #def ensure_branch_exists():
+    #    parent = repo.get_branch_tip('default')
+    #    repo._create_branch(file_branch(path, request.user), parent)
         
-    try:
-        repo.with_wlock(ensure_branch_exists)
+#    try:
+    #    repo.with_wlock(ensure_branch_exists)
         
-        return direct_to_template(request, 'explorer/editor.html', extra_context={
-            'fileid': path,
-            'panel_list': ['lewy', 'prawy'],
-            'availble_panels': models.EditorPanel.objects.all(),
-            'scriptlets': toolbar_models.Scriptlet.objects.all()
-        })
-    except KeyError:
-        return direct_to_template(request, 'explorer/nofile.html', \
-            extra_context = { 'fileid': path })
+    return direct_to_template(request, 'explorer/editor.html', extra_context={
+        'fileid': path,
+        'panel_list': ['lewy', 'prawy'],
+        'availble_panels': models.EditorPanel.objects.all(),
+        # 'scriptlets': toolbar_models.Scriptlet.objects.all()
+    })
+#    except KeyError:
+#        return direct_to_template(request, 'explorer/nofile.html', \
+#            extra_context = { 'fileid': path })
 
 # ===============
 # = Panel views =
index bf6758f..9628f04 100644 (file)
@@ -81,10 +81,12 @@ $(function() {
 {% if perms.explorer.can_add_files %}
 <div class="upload-file-widget">
 <h2>Dodaj nowy utwór</h2>
+
 <form action="/api/documents" method="POST" enctype="multipart/form-data">
     {{ bookform }}
     <p><button type="submit">Dodaj książkę</button></p>
 </form>
+
 </div>
 {% endif %}