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
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
@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
@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
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()
@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()))
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
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