X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/793b39c86e9583467f1cbc41f8b1a4677d079f23..f20c260cfc805924834ea7e545ac2a84a4042b28:/apps/wiki/views.py?ds=inline diff --git a/apps/wiki/views.py b/apps/wiki/views.py index 45ded5bf..b3035422 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 @@ -201,7 +206,7 @@ def upload(request): @decorator_from_middleware(GZipMiddleware) def text(request, slug, chunk=None): try: - doc = Chunk.get(slug, chunk).doc + doc = Chunk.get(slug, chunk) except (Chunk.MultipleObjectsReturned, Chunk.DoesNotExist): raise Http404 @@ -247,21 +252,45 @@ 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): form = DocumentTextRevertForm(request.POST, prefix="textrevert") if form.is_valid(): try: - doc = Chunk.get(slug, chunk).doc + doc = Chunk.get(slug, chunk) except (Chunk.MultipleObjectsReturned, Chunk.DoesNotExist): raise Http404 @@ -327,7 +356,7 @@ def diff(request, slug, chunk=None): revB = None try: - doc = Chunk.get(slug, chunk).doc + doc = Chunk.get(slug, chunk) except (Chunk.MultipleObjectsReturned, Chunk.DoesNotExist): raise Http404 docA = doc.at_revision(revA).materialize() @@ -340,7 +369,7 @@ def diff(request, slug, chunk=None): @never_cache def revision(request, slug, chunk=None): try: - doc = Chunk.get(slug, chunk).doc + doc = Chunk.get(slug, chunk) except (Chunk.MultipleObjectsReturned, Chunk.DoesNotExist): raise Http404 return http.HttpResponse(str(doc.revision())) @@ -350,7 +379,7 @@ def revision(request, slug, chunk=None): def history(request, slug, chunk=None): # TODO: pagination try: - doc = Chunk.get(slug, chunk).doc + doc = Chunk.get(slug, chunk) except (Chunk.MultipleObjectsReturned, Chunk.DoesNotExist): raise Http404 @@ -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