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
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,
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,
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
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)
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"),
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):
# 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 =
{% 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 %}