librarian in submodule, HTML and TXT book previews, URL fixes
authorRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Tue, 24 May 2011 10:57:19 +0000 (12:57 +0200)
committerRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Tue, 24 May 2011 10:57:19 +0000 (12:57 +0200)
.gitmodules [new file with mode: 0644]
apps/wiki/templates/wiki/book_detail.html
apps/wiki/urls.py
apps/wiki/views.py
lib/librarian [new submodule]
redakcja.wsgi.template
redakcja/manage.py
redakcja/static/js/wiki/wikiapi.js
requirements.txt

diff --git a/.gitmodules b/.gitmodules
new file mode 100644 (file)
index 0000000..56b9c42
--- /dev/null
@@ -0,0 +1,3 @@
+[submodule "lib/librarian"]
+       path = lib/librarian
+       url = git://github.com/fnp/librarian.git
index ee645f1..f30ed36 100755 (executable)
@@ -3,15 +3,29 @@
 
 {% block leftcolumn %}
 
-    <h1>{{ object.title }}</h1>
+    <h1>{{ book.title }}</h1>
 
-    <table>
-    {% for chunk in object.chunk_set.all %}
-        <tr><td>{{ chunk.number }}</td><td>{{ chunk.slug }}</td></tr>
+<p>
+    {% for chunk in book.chunk_set.all %}
+        <a target="_blank" href="{% url wiki_editor book.slug chunk.slug %}">{{ chunk.comment }}</a><br/>
     {% endfor %}
-    </table>
+</p>
+
+<p>
+<a href="{% url wiki_book_xml book.slug %}">{% trans "Full XML" %}</a><br/>
+<a target="_blank" href="{% url wiki_book_html book.slug %}">{% trans "HTML version" %}</a><br/>
+<a href="{% url wiki_book_txt book.slug %}">{% trans "TXT version" %}</a><br/>
+{% comment %}
+<a href="{% url wiki_book_epub book.slug %}">{% trans "EPUB version" %}</a><br/>
+<a href="{% url wiki_book_pdf book.slug %}">{% trans "PDF version" %}</a><br/>
+{% endcomment %}
+</p>
+
+<p style='width:200px; height: 75px; border: 1px dotted gray; border-corners: 4px;'></p>
 
 {% endblock leftcolumn %}
 
 {% block rightcolumn %}
+
+
 {% endblock rightcolumn %}
index 7ed47a0..ac731ef 100644 (file)
@@ -49,8 +49,11 @@ urlpatterns = patterns('wiki.views',
     url(r'^diff/(?P<slug>[^/]+)/(?:(?P<chunk>[^/]+)/)?$', 'diff', name="wiki_diff"),
     #url(r'^(?P<name>[^/]+)/tags$', 'add_tag', name="wiki_add_tag"),
 
-    url(r'^full/(?P<slug>[^/]+)/$', 'compiled', name="wiki_compiled"),
+    url(r'^book/(?P<slug>[^/]+)/$', 'book', name="wiki_book"),
+    url(r'^book/(?P<slug>[^/]+)/xml$', 'book_xml', name="wiki_book_xml"),
+    url(r'^book/(?P<slug>[^/]+)/txt$', 'book_txt', name="wiki_book_txt"),
+    url(r'^book/(?P<slug>[^/]+)/html$', 'book_html', name="wiki_book_html"),
+    #url(r'^book/(?P<slug>[^/]+)/epub$', 'book_epub', name="wiki_book_epub"),
+    #url(r'^book/(?P<slug>[^/]+)/pdf$', 'book_pdf', name="wiki_book_pdf"),
 
-    url(r'^book/(?P<slug>[^/]+)/$', object_detail, 
-        {"queryset": Book.objects.all()}, name="wiki_book"),
 )
index 45ded5b..378701c 100644 (file)
@@ -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 (submodule)
index 0000000..2887829
--- /dev/null
@@ -0,0 +1 @@
+Subproject commit 28878296bacad453735a520f350ba5a971f8ffc8
index d271fa1..ef19f5a 100644 (file)
@@ -14,6 +14,7 @@ sys.stdout = sys.stderr
 sys.path = [
     '$APP_DIR',
        '$APP_DIR/lib',
+       '$APP_DIR/lib/librarian',
        '$APP_DIR/apps',
 ] + sys.path
 
index 28b571d..7647675 100755 (executable)
@@ -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')
 )]
 
index d8ade93..5786f15 100644 (file)
                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";
index 02ae641..c2ed840 100644 (file)
@@ -1,5 +1,5 @@
 ## Python libraries
-lxml>=2.2
+lxml>=2.2.2
 mercurial>=1.6,<1.7
 PyYAML>=3.0
 PIL>=1.1