From: Łukasz Rekucki Date: Sat, 26 Sep 2009 12:22:39 +0000 (+0200) Subject: HTML dodany do API. X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/60734259bb91a3ff24ba8a757bb3748648f74366?hp=-c HTML dodany do API. --- 60734259bb91a3ff24ba8a757bb3748648f74366 diff --git a/apps/api/handlers/library_handlers.py b/apps/api/handlers/library_handlers.py index 06513522..8862de0c 100644 --- a/apps/api/handlers/library_handlers.py +++ b/apps/api/handlers/library_handlers.py @@ -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 diff --git a/apps/api/resources.py b/apps/api/resources.py index 7681436b..113d4b6d 100644 --- a/apps/api/resources.py +++ b/apps/api/resources.py @@ -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) diff --git a/apps/api/urls.py b/apps/api/urls.py index 8c10158a..b36cbe30 100644 --- a/apps/api/urls.py +++ b/apps/api/urls.py @@ -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"), diff --git a/apps/api/utils.py b/apps/api/utils.py index 0e0468a0..d8177ab0 100644 --- a/apps/api/utils.py +++ b/apps/api/utils.py @@ -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): diff --git a/apps/explorer/views.py b/apps/explorer/views.py index e3ca63a7..c10e33ba 100644 --- a/apps/explorer/views.py +++ b/apps/explorer/views.py @@ -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 = diff --git a/project/templates/explorer/file_list.html b/project/templates/explorer/file_list.html index bf6758f2..9628f042 100644 --- a/project/templates/explorer/file_list.html +++ b/project/templates/explorer/file_list.html @@ -81,10 +81,12 @@ $(function() { {% if perms.explorer.can_add_files %}

Dodaj nowy utwór

+
{{ bookform }}

+
{% endif %}