diff options
Diffstat (limited to 'bn_django')
-rw-r--r-- | bn_django/git_browse/settings.py | 2 | ||||
-rw-r--r-- | bn_django/git_wiki/models.py | 12 | ||||
-rw-r--r-- | bn_django/git_wiki/settings.py | 6 | ||||
-rw-r--r-- | bn_django/git_wiki/templates/git_wiki/item.html | 1 | ||||
-rw-r--r-- | bn_django/git_wiki/templates/git_wiki/tree.html | 6 | ||||
-rw-r--r-- | bn_django/git_wiki/templates/git_wiki/tree_table | 10 | ||||
-rw-r--r-- | bn_django/git_wiki/urls.py | 6 | ||||
-rw-r--r-- | bn_django/git_wiki/views.py | 107 |
8 files changed, 139 insertions, 11 deletions
diff --git a/bn_django/git_browse/settings.py b/bn_django/git_browse/settings.py index 8e63667..87b957d 100644 --- a/bn_django/git_browse/settings.py +++ b/bn_django/git_browse/settings.py @@ -1,2 +1,2 @@ # fill path to the git command -GITCOMMAND = '/usr/bin/git' +GITCOMMAND = '/usr/local/bin/git' diff --git a/bn_django/git_wiki/models.py b/bn_django/git_wiki/models.py index 78a26f6..ba133b6 100644 --- a/bn_django/git_wiki/models.py +++ b/bn_django/git_wiki/models.py @@ -83,7 +83,12 @@ class Item(models.Model): def get_admin_url(self): return "%s/k/%s/" % (ADMIN_URL, self.id) - + def isfig(self): + if self.name.find('.') != -1: + return True + else: + return False + def update(self): import commands if (not self.id): return @@ -94,6 +99,11 @@ class Item(models.Model): self.size = commands.getoutput(GITPREFIX + ' cat-file -s ' + self.id) self.save() + def getfile(self): + import commands + if (not self.id): return + return open(str(GITWIKI_DIR + '/objects/' + self.id[:2] + '/' + self.id[2:]),'r') + class Commit(models.Model): id = models.CharField("hash", maxlength=40,blank=False,primary_key=True) rawdiff = models.TextField("ASCII contents of full commit diff") diff --git a/bn_django/git_wiki/settings.py b/bn_django/git_wiki/settings.py index b94d318..965ac26 100644 --- a/bn_django/git_wiki/settings.py +++ b/bn_django/git_wiki/settings.py @@ -1,13 +1,13 @@ # full path to directory holding the wiki repository (or sys links to # the repositories) -GITWIKI_BASE = '/srv/git/' +GITWIKI_BASE = '/home/bnewbold/knowledge/' # leave this blank (NO WHITE SPACE) unless you're using a bare repo -GITWIKI_NAME = 'knowledge' +GITWIKI_NAME = '' # fill path to the git command -GITCOMMAND = '/usr/bin/git' +GITCOMMAND = '/usr/local/bin/git' GITWIKI_DIR = str(GITWIKI_BASE) + '/' + str(GITWIKI_NAME) + '.git' GITPREFIX = 'cd ' +str(GITWIKI_BASE) + '; ' + str(GITCOMMAND) + ' --git-dir=' \ diff --git a/bn_django/git_wiki/templates/git_wiki/item.html b/bn_django/git_wiki/templates/git_wiki/item.html index d9d33c9..e26722d 100644 --- a/bn_django/git_wiki/templates/git_wiki/item.html +++ b/bn_django/git_wiki/templates/git_wiki/item.html @@ -22,6 +22,7 @@ <br /> <span class="righty"> <a href="/k/{{ item.slug }}/raw/">raw</a> - + <a href="/k/{{ item.slug }}/latex/">latex</a> - <a href="/k/{{ item.slug }}/pdf/">pdf</a> - <a href="/k/{{ item.slug }}/log">log</a> </span> diff --git a/bn_django/git_wiki/templates/git_wiki/tree.html b/bn_django/git_wiki/templates/git_wiki/tree.html index 1c33a98..08f6e35 100644 --- a/bn_django/git_wiki/templates/git_wiki/tree.html +++ b/bn_django/git_wiki/templates/git_wiki/tree.html @@ -6,12 +6,10 @@ {% block title %}Knowledge Category: {{ tree.path }}{% endblock %} {% block gitwiki %} - <h3>Tree sha1 hash:</h3> - <span class="hash">{{ tree.id }}</span> - <h3>Tree path:</h3> - <span class="hash">{{ tree.path }}</span> <h3>Directory listing:</h3> {% include "git_wiki/tree_table" %} + <h3>Tree sha1 hash:</h3> + <span class="hash">{{ tree.id }}</span> <h3>Shortlog:</h3> {% include "git_wiki/shortlog_table" %} {% endblock %} diff --git a/bn_django/git_wiki/templates/git_wiki/tree_table b/bn_django/git_wiki/templates/git_wiki/tree_table index 82d169a..c1f9a82 100644 --- a/bn_django/git_wiki/templates/git_wiki/tree_table +++ b/bn_django/git_wiki/templates/git_wiki/tree_table @@ -8,7 +8,13 @@ <a href='/k/{{ o.slug }}/' class="item"> {{o.path}}</a> </td><td type="links"> - <a href='/k/{{ o.slug }}/pdf/'>pdf</a> + {% if o.isfig %} + <a href='/k/{{ o.slug }}'>download</a> + {% else %} + <a href='/k/{{ o.slug }}/pdf/'>pdf</a> + <a href='/k/{{ o.slug }}/latex/'>latex</a> + <a href='/k/{{ o.slug }}/raw/'>raw</a> + {% endif %} </td> {% else %} {% ifequal o.type 'tree' %} <a href='/k/{{ o.slug }}/' class="tree"> @@ -17,7 +23,7 @@ <a href='/k/{{ o.slug }}/'>browse</a> </td> {% else %} - <a href='/k/{{ o.slug }}/' class="item"> + <a href='/k/{{ o.slug }}' class="item"> {{o.name}}</a> </td><td type="links"> </td> diff --git a/bn_django/git_wiki/urls.py b/bn_django/git_wiki/urls.py index 0cd2031..2570f05 100644 --- a/bn_django/git_wiki/urls.py +++ b/bn_django/git_wiki/urls.py @@ -19,5 +19,11 @@ urlpatterns = patterns('bn_django.git_wiki.views', (r'^(?P<reqslug>[\w\-\_\/]*)/log/$', 'tree',), (r'^(?P<reqslug>[\w\-\_\/]*)/edit/$', 'tree',), (r'^(?P<reqslug>[\w\-\_\/]*)/pdf/$', 'tree',), + (r'^(?P<reqslug>[\w\-\_\/]*)/raw/$', 'rawitem',), + (r'^(?P<reqslug>[\w\-\_\/]*)/latex/$', 'latexitem',), + (r'^(?P<reqslug>[\w\-\_\/]*\.png/?)$', 'figure',), + (r'^(?P<reqslug>[\w\-\_\/]*\.gif/?)$', 'figure',), + (r'^(?P<reqslug>[\w\-\_\/]*\.jpg/?)$', 'figure',), + (r'^(?P<reqslug>[\w\-\_\/]*\.jpeg/?)$', 'figure',), (r'^(?P<reqslug>[\w\-\_\/]*)$', 'tree',), ) 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() |