diff options
Diffstat (limited to 'bn_django/git_wiki/views.py')
-rw-r--r-- | bn_django/git_wiki/views.py | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/bn_django/git_wiki/views.py b/bn_django/git_wiki/views.py index b0dde21..1cad5be 100644 --- a/bn_django/git_wiki/views.py +++ b/bn_django/git_wiki/views.py @@ -60,6 +60,113 @@ def item(request, reqslug, blob=None): return render_to_response('git_wiki/item.html', dict(item=i,doc=parts,user=request.user)) +def latexitem(request, reqslug, blob=None): + if not blob: + i = fromslug(reqslug) + if not i: + raise Http404 + if i.type == 'tree': + return tree(request, reqslug) + else: + i = blob + i.update() + + try: + from docutils.core import publish_parts + except ImportError: + if settings.DEBUG: + raise HttpResponseServerError(request) + else: + docutils_settings = getattr(settings, "GITWIKI_REST_SETTINGS", {}) + parts = publish_parts(source=i.contents, writer_name="latex", settings_overrides=docutils_settings) + hr = HttpResponse(mimetype="text/plain") + hr['Content-Disposition'] = 'filename=%s.tex' % reqslug + hr.write(parts['whole'].replace('{\$}','$')) + #hr.write(parts['whole']) + return hr + +def pdfitem(request, reqslug, blob=None): + if not blob: + i = fromslug(reqslug) + if not i: + raise Http404 + if i.type == 'tree': + return tree(request, reqslug) + else: + i = blob + i.update() + + try: + from docutils.core import publish_parts + except ImportError: + if settings.DEBUG: + raise HttpResponseServerError(request) + else: + docutils_settings = getattr(settings, "GITWIKI_REST_SETTINGS", {}) + parts = publish_parts(source=i.contents, writer_name="latex", settings_overrides=docutils_settings) + hr = HttpResponse(mimetype="text/plain") + hr['Content-Disposition'] = 'filename=%s.tex' % reqslug + hr.write(parts['whole']) + return hr + +def rawitem(request, reqslug, blob=None): + if reqslug.endswith('/'): + reqslug=reqslug[:-1] + if not blob: + i = fromslug(reqslug) + if not i: + raise Http404 + if i.type == 'tree': + return tree(request, reqslug) + else: + i = blob + i.update() + slug = i.slug() + r = HttpResponse(mimetype="text/plain") + r['Content-Disposition'] = 'filename=%s.txt' % reqslug + r.write(i.contents) + return r + +def figure(request, reqslug, blob=None, download=False): + if reqslug.endswith('/'): + reqslug=reqslug[:-1] + if not blob: + i = fromslug(reqslug) + if not i: + l = reqslug.split('/') + if l[-2] == 'fig': + l = l[:-3] + l[-2:] + else: + l = l[:-2] + l[-1:] + i = fromslug('/'.join(l)) + if not i: + raise Http404 + if i.type == 'tree': + return tree(request, reqslug) + else: + i = blob + mime = "image/image" + slug = i.slug() + i.update() + if slug.endswith('.jpg') or slug.endswith('.jpeg'): + mime = "image/jpeg" + elif slug.endswith('.png'): + mime = "image/jpeg" + elif slug.endswith('.gif'): + mime = "image/jpeg" + elif slug.endswith('.svg'): + mime = "image/svg+xml" + r = HttpResponse(mimetype=mime) + if download: + r['Content-Disposition'] = 'attachment; filename=%s' % reqslug + else: + r['Content-Disposition'] = 'filename=%s' % reqslug + f = i.getfile() + t = f.readlines() + print "hello!" + r.write(i.contents) + return r + def olditem(request, hash): i = get_object_or_404(Item, id=hash) i.update() |