From: Radek Czajka Date: Tue, 24 May 2011 10:57:19 +0000 (+0200) Subject: librarian in submodule, HTML and TXT book previews, URL fixes X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/af0693ddb5e4f6240d273c8a66fd1e6ef2a52872?ds=inline librarian in submodule, HTML and TXT book previews, URL fixes --- diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..56b9c425 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "lib/librarian"] + path = lib/librarian + url = git://github.com/fnp/librarian.git diff --git a/apps/wiki/templates/wiki/book_detail.html b/apps/wiki/templates/wiki/book_detail.html index ee645f13..f30ed363 100755 --- a/apps/wiki/templates/wiki/book_detail.html +++ b/apps/wiki/templates/wiki/book_detail.html @@ -3,15 +3,29 @@ {% block leftcolumn %} -

{{ object.title }}

+

{{ book.title }}

- - {% for chunk in object.chunk_set.all %} - +

+ {% for chunk in book.chunk_set.all %} + {{ chunk.comment }}
{% endfor %} -

{{ chunk.number }}{{ chunk.slug }}
+

+ +

+{% trans "Full XML" %}
+{% trans "HTML version" %}
+{% trans "TXT version" %}
+{% comment %} +{% trans "EPUB version" %}
+{% trans "PDF version" %}
+{% endcomment %} +

+ +

{% endblock leftcolumn %} {% block rightcolumn %} + + {% endblock rightcolumn %} diff --git a/apps/wiki/urls.py b/apps/wiki/urls.py index 7ed47a01..ac731eff 100644 --- a/apps/wiki/urls.py +++ b/apps/wiki/urls.py @@ -49,8 +49,11 @@ urlpatterns = patterns('wiki.views', url(r'^diff/(?P[^/]+)/(?:(?P[^/]+)/)?$', 'diff', name="wiki_diff"), #url(r'^(?P[^/]+)/tags$', 'add_tag', name="wiki_add_tag"), - url(r'^full/(?P[^/]+)/$', 'compiled', name="wiki_compiled"), + url(r'^book/(?P[^/]+)/$', 'book', name="wiki_book"), + url(r'^book/(?P[^/]+)/xml$', 'book_xml', name="wiki_book_xml"), + url(r'^book/(?P[^/]+)/txt$', 'book_txt', name="wiki_book_txt"), + url(r'^book/(?P[^/]+)/html$', 'book_html', name="wiki_book_html"), + #url(r'^book/(?P[^/]+)/epub$', 'book_epub', name="wiki_book_epub"), + #url(r'^book/(?P[^/]+)/pdf$', 'book_pdf', name="wiki_book_pdf"), - url(r'^book/(?P[^/]+)/$', object_detail, - {"queryset": Book.objects.all()}, name="wiki_book"), ) diff --git a/apps/wiki/views.py b/apps/wiki/views.py index 45ded5bf..378701c2 100644 --- a/apps/wiki/views.py +++ b/apps/wiki/views.py @@ -1,7 +1,10 @@ import os +from StringIO import StringIO import logging logger = logging.getLogger("fnp.wiki") +from lxml import etree + from django.conf import settings from django.views.generic.simple import direct_to_template @@ -21,6 +24,8 @@ from django.utils.translation import ugettext_lazy as _ from django.utils.decorators import decorator_from_middleware from django.middleware.gzip import GZipMiddleware +import librarian.html +import librarian.text # # Quick hack around caching problems, TODO: use ETags @@ -247,14 +252,38 @@ def text(request, slug, chunk=None): @never_cache -def compiled(request, slug): - text = get_object_or_404(Book, slug=slug).materialize() +def book_xml(request, slug): + xml = get_object_or_404(Book, slug=slug).materialize() - response = http.HttpResponse(text, content_type='application/xml', mimetype='application/wl+xml') + response = http.HttpResponse(xml, content_type='application/xml', mimetype='application/wl+xml') response['Content-Disposition'] = 'attachment; filename=%s.xml' % slug return response +@never_cache +def book_txt(request, slug): + xml = get_object_or_404(Book, slug=slug).materialize() + output = StringIO() + # errors? + librarian.text.transform(StringIO(xml), output) + text = output.getvalue() + response = http.HttpResponse(text, content_type='text/plain', mimetype='text/plain') + response['Content-Disposition'] = 'attachment; filename=%s.txt' % slug + return response + + +@never_cache +def book_html(request, slug): + xml = get_object_or_404(Book, slug=slug).materialize() + output = StringIO() + # errors? + librarian.html.transform(StringIO(xml), output, parse_dublincore=False, + flags=['full-page']) + html = output.getvalue() + response = http.HttpResponse(html, content_type='text/html', mimetype='text/html') + return response + + @never_cache @require_POST def revert(request, slug, chunk=None): @@ -373,6 +402,14 @@ def history(request, slug, chunk=None): return JSONResponse(changes) +def book(request, slug): + book = get_object_or_404(Book, slug=slug) + + return direct_to_template(request, "wiki/book_detail.html", extra_context={ + "book": book, + }) + + """ import wlapi diff --git a/lib/librarian b/lib/librarian new file mode 160000 index 00000000..28878296 --- /dev/null +++ b/lib/librarian @@ -0,0 +1 @@ +Subproject commit 28878296bacad453735a520f350ba5a971f8ffc8 diff --git a/redakcja.wsgi.template b/redakcja.wsgi.template index d271fa16..ef19f5a7 100644 --- a/redakcja.wsgi.template +++ b/redakcja.wsgi.template @@ -14,6 +14,7 @@ sys.stdout = sys.stderr sys.path = [ '$APP_DIR', '$APP_DIR/lib', + '$APP_DIR/lib/librarian', '$APP_DIR/apps', ] + sys.path diff --git a/redakcja/manage.py b/redakcja/manage.py index 28b571d4..7647675f 100755 --- a/redakcja/manage.py +++ b/redakcja/manage.py @@ -11,6 +11,7 @@ PROJECT_ROOT = os.path.realpath(os.path.dirname(__file__)) sys.path += [os.path.realpath(os.path.join(*x)) for x in ( (PROJECT_ROOT, '..'), (PROJECT_ROOT, '..', 'apps'), + (PROJECT_ROOT, '..', 'lib/librarian'), (PROJECT_ROOT, '..', 'lib') )] diff --git a/redakcja/static/js/wiki/wikiapi.js b/redakcja/static/js/wiki/wikiapi.js index d8ade93f..5786f151 100644 --- a/redakcja/static/js/wiki/wikiapi.js +++ b/redakcja/static/js/wiki/wikiapi.js @@ -18,40 +18,40 @@ var base_path = "/documents"; if (vname == "ajax_document_text") { - var path = "/text/" + arguments[1]; + var path = "/text/" + arguments[1] + '/'; if (arguments[2] !== undefined) - path += "/" + arguments[2]; + path += arguments[2] + '/'; return base_path + path; } if (vname == "ajax_document_revert") { - return base_path + "/revert/" + arguments[1]; + return base_path + "/revert/" + arguments[1] + '/'; } if (vname == "ajax_document_history") { - return base_path + "/history/" + arguments[1]; + return base_path + "/history/" + arguments[1] + '/'; } if (vname == "ajax_document_gallery") { - return base_path + "/gallery/" + arguments[1]; + return base_path + "/gallery/" + arguments[1] + '/'; } if (vname == "ajax_document_diff") - return base_path + "/diff/" + arguments[1]; + return base_path + "/diff/" + arguments[1] + '/'; if (vname == "ajax_document_rev") - return base_path + "/rev/" + arguments[1]; + return base_path + "/rev/" + arguments[1] + '/'; if (vname == "ajax_document_addtag") - return base_path + "/tags/" + arguments[1]; + return base_path + "/tags/" + arguments[1] + '/'; if (vname == "ajax_publish") - return base_path + "/publish/" + arguments[1]; + return base_path + "/publish/" + arguments[1] + '/'; console.log("Couldn't reverse match:", vname); return "/404.html"; diff --git a/requirements.txt b/requirements.txt index 02ae6410..c2ed8400 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ ## Python libraries -lxml>=2.2 +lxml>=2.2.2 mercurial>=1.6,<1.7 PyYAML>=3.0 PIL>=1.1