aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbnewbold <bnewbold@manus.(none)>2007-02-21 21:58:59 -0800
committerbnewbold <bnewbold@manus.(none)>2007-02-21 21:58:59 -0800
commitc719dcba2d37f1814aa2bae55947d77453f70b9c (patch)
tree1f6eb3bc497036c93b31118c58fbb142590cfcee
parenta1f72ac87a18fe1fcc0cf1a2eb8d69d89ba606df (diff)
downloadbnewnet-c719dcba2d37f1814aa2bae55947d77453f70b9c.tar.gz
bnewnet-c719dcba2d37f1814aa2bae55947d77453f70b9c.zip
fixed some xhtml nitty gritty, progress on git_wiki
-rw-r--r--bn_django/git_browse/templates/git_browse/base.html6
-rw-r--r--bn_django/git_wiki/models.py155
-rw-r--r--bn_django/git_wiki/settings.py3
-rw-r--r--bn_django/git_wiki/templates/git_wiki/base.html6
-rw-r--r--bn_django/git_wiki/templates/git_wiki/frontpage.html5
-rw-r--r--bn_django/git_wiki/templates/git_wiki/shortlog_table27
-rw-r--r--bn_django/git_wiki/urls.py5
-rw-r--r--bn_django/git_wiki/views.py46
-rw-r--r--bn_django/templates/about.html3
-rw-r--r--bn_django/templates/base.html12
-rw-r--r--bn_django/templates/frontpage.html3
-rw-r--r--bn_django/urls.py3
12 files changed, 222 insertions, 52 deletions
diff --git a/bn_django/git_browse/templates/git_browse/base.html b/bn_django/git_browse/templates/git_browse/base.html
index 1656ce0..89a0139 100644
--- a/bn_django/git_browse/templates/git_browse/base.html
+++ b/bn_django/git_browse/templates/git_browse/base.html
@@ -2,9 +2,9 @@
{% block stylesheets %}
{{ block.super }}
-<link rel="STYLESHEET" type="text/css" href="style/git_browse.css">
-<link rel="STYLESHEET" type="text/css" href="/style/git_browse.css">
-<!--<link rel="STYLESHEET" type="text/css" href="http://static.bryannewbold.com/style/git_browse.css">-->
+<link rel="STYLESHEET" type="text/css" href="style/git_browse.css" />
+<link rel="STYLESHEET" type="text/css" href="/style/git_browse.css" />
+<!--<link rel="STYLESHEET" type="text/css" href="http://static.bryannewbold.com/style/git_browse.css" />-->
{% endblock %}
diff --git a/bn_django/git_wiki/models.py b/bn_django/git_wiki/models.py
index 71a8362..4201a84 100644
--- a/bn_django/git_wiki/models.py
+++ b/bn_django/git_wiki/models.py
@@ -1,3 +1,156 @@
from django.db import models
+from settings import *
+from django.conf import settings
-# Create your models here.
+try:
+ ADMIN_URL = settings.ADMIN_URL
+except AttributeError:
+ ADMIN_URL='/admin'
+if ADMIN_URL[-1] == '/':
+ ADMIN_URL=ADMIN_URL[:-1]
+
+GITPREFIX = 'cd ' +str(GITWIKI_BASE) + '; ' + str(GITCOMMAND) + ' --git-dir=' \
+ + str(GITWIKI_BASE) + '/.git '
+
+def reposcan():
+ import os
+ heads = dict()
+ for h in os.listdir(GITWIKI_BASE + self.slug + '/.git/refs/heads/'):
+ f = open(GITWIKI_BASE + self.slug + '/.git/refs/heads/' + h,'r')
+ heads[h.strip()] = f.readline().strip()
+ f.close()
+ tags = dict()
+ for t in os.listdir(GITWIKI_BASE + self.slug + '/.git/refs/tags/'):
+ f = open(GITWIKI_BASE + self.slug + '/.git/refs/tags/' + t,'r')
+ tags[t.strip()] = f.readline().strip()
+ f.close()
+ return (heads, tags)
+
+def shortlog(hash=None,tree=None):
+ import commands
+
+ if tree:
+ hash=tree.id
+ logtxt = commands.getoutput(GITPREFIX \
+ + ' log --relative-date --max-count=6 | cat')
+ print GITPREFIX
+ print logtxt
+ log_items = logtxt.split('\ncommit ')
+ if (log_items[0] == ''):
+ log_items.pop(0)
+ if (log_items[0].startswith('commit ')):
+ log_items[0] = log_items[0][7:]
+ shortlog = list()
+ for li in log_items:
+ logobj = dict()
+ lines = li.splitlines()
+ if len(lines) < 3: continue
+ logobj['hash'] = lines[0].strip()
+ logobj['shorthash'] = lines[0].strip()[:5]
+ logobj['author'] = lines[1][8:]
+ logobj['date'] = lines[2][8:]
+ if len(lines) > 4:
+ logobj['description'] = lines[4][4:]
+ else:
+ logobj['description'] = '(none)'
+ # here we truncate commit comments for shortlogs
+ logobj['shortdescription'] = logobj['description'][:128]
+ shortlog.append(logobj)
+ return shortlog
+
+class Tree(models.Model):
+ mode = models.CharField("file mode/permissions", blank=False,maxlength=4)
+ path = models.CharField("relative path from repo base", maxlength=512)
+ id = models.CharField("hash", maxlength=40,blank=False,primary_key=True)
+ name = models.CharField("name of dir", maxlength=128,blank=False)
+ type = 'tree'
+ def slug(self):
+ #TODO: secure this
+ return self.name.strip().lower()
+
+ class Admin:
+ ordering = ['path','name']
+
+ def __str__(self):
+ return self.name
+ def get_absolute_url(self):
+ return "/k/%s/" % self.slug()
+ def get_admin_url(self):
+ return "%s/k/%s/" % (ADMIN_URL, self.id)
+
+class Item(models.Model):
+ mode = models.CharField("file mode/permissions", blank=False,maxlength=4)
+ path = models.CharField("relative path from repo base", maxlength=512)
+ id = models.CharField("hash", maxlength=40,blank=False,primary_key=True)
+ name = models.CharField("name of dir", maxlength=128,blank=False)
+ size = models.IntegerField("filesize in byte", maxlength=128,blank=False)
+ contents = models.TextField("ASCII contents of the file")
+ type='blob'
+
+ class Admin:
+ ordering = ['path','name']
+ def __str__(self):
+ return self.name
+ def get_absolute_url(self):
+ return "/k/%s/" % self.slug()
+ def get_admin_url(self):
+ return "%s/k/%s/" % (ADMIN_URL, self.id)
+
+ def update(self):
+ import commands
+ if (not self.id): return
+
+ self.id = self.id.strip()
+ self.contents = commands.getoutput(GITPREFIX + ' cat-file -p ' \
+ + self.id)
+ self.size = commands.getoutput(GITPREFIX + ' cat-file -s ' + self.id)
+ return
+
+class Commit(models.Model):
+ id = models.CharField("hash", maxlength=40,blank=False,primary_key=True)
+ rawdiff = models.TextField("ASCII contents of full commit diff")
+ commit_date = models.DateField("Date of commit to repository")
+ author_date = models.DateField("Date commit was writen/created")
+ author = models.CharField("Name of commit author")
+ author_email = models.DateField("Email address of commit author")
+ committer = models.CharField("Name of committer")
+ committer_email = models.DateField("Email address of committer")
+ comment = models.TextField("Notes on the commit")
+ parenthash = models.CharField("parent's hash", maxlength=40)
+ #TODO: parent = models.ForeignKey()
+ treehash = models.CharField("tree object's hash", maxlength=40)
+ tree = models.ForeignKey(Tree)
+ type='commit'
+
+ class Admin:
+ ordering = ['commit_date','author_date','author']
+ def __str__(self):
+ return self.id
+ def get_absolute_url(self):
+ return "/k/commit/%s/" % (self.id)
+ def get_admin_url(self):
+ return "%s/k/commit/%s/" % (ADMIN_URL, self.id)
+
+ def update(self):
+ import commands,time
+ if (not self.id): return
+
+ self.id = self.id.strip()
+ raw = commands.getoutput(GITPREFIX + ' cat-file -p ' + self.id)
+ self.rawdiff = commands.getoutput(GITPREFIX + ' diff ' + self.id \
+ +' | cat')
+
+ raw = raw.splitlines()
+ if len(raw) < 3: return
+ self.treehash = raw[0].split()[-1].strip()
+ self.parenthash = raw[1][6:].strip()
+ self.author = raw[2].split()[1]
+ self.author_date = time.ctime(int(raw[2].split()[-2]))
+ self.committer = raw[3].split()[1]
+ self.committer_date = time.ctime(int(raw[3].split()[-2]))
+ if len(raw) > 4:
+ for l in raw[4:]:
+ self.comment += str(l) + '\n'
+ else:
+ self.comment = '(none)'
+ return
diff --git a/bn_django/git_wiki/settings.py b/bn_django/git_wiki/settings.py
index bb81610..2aa9bb1 100644
--- a/bn_django/git_wiki/settings.py
+++ b/bn_django/git_wiki/settings.py
@@ -5,3 +5,6 @@ GITWIKI_BASE = '/home/bnewbold/knowledge/'
# fill path to the git command
GITCOMMAND = '/usr/local/bin/git'
+
+GITPREFIX = 'cd ' +str(GITWIKI_BASE) + '; ' + str(GITCOMMAND) + ' --git-dir=' \
+ + str(GITWIKI_BASE) + '/.git'
diff --git a/bn_django/git_wiki/templates/git_wiki/base.html b/bn_django/git_wiki/templates/git_wiki/base.html
index 6107c04..ed88aa1 100644
--- a/bn_django/git_wiki/templates/git_wiki/base.html
+++ b/bn_django/git_wiki/templates/git_wiki/base.html
@@ -2,9 +2,9 @@
{% block stylesheets %}
{{ block.super }}
-<link rel="STYLESHEET" type="text/css" href="style/git_wiki.css">
-<link rel="STYLESHEET" type="text/css" href="/style/git_wiki.css">
-<!--<link rel="STYLESHEET" type="text/css" href="http://static.bryannewbold.com/style/git_wiki.css">-->
+<link rel="STYLESHEET" type="text/css" href="style/git_wiki.css" />
+<link rel="STYLESHEET" type="text/css" href="/style/git_wiki.css" />
+<!--<link rel="STYLESHEET" type="text/css" href="http://static.bryannewbold.com/style/git_wiki.css" />-->
{% endblock %}
diff --git a/bn_django/git_wiki/templates/git_wiki/frontpage.html b/bn_django/git_wiki/templates/git_wiki/frontpage.html
index 897bf8b..b4c4cbd 100644
--- a/bn_django/git_wiki/templates/git_wiki/frontpage.html
+++ b/bn_django/git_wiki/templates/git_wiki/frontpage.html
@@ -22,10 +22,7 @@ For more recent content see the <a href="/timeline/">timeline</a>
</div>
<h3>Latest knowledge</h3>
-{% if latest_knowledge %}
-{% else %}
-None yet!
-{% endif %}
+{% include "git_wiki/shortlog_table" %}
<hr />
<h3>Latest comments</h3>
{% if latest_comments %}
diff --git a/bn_django/git_wiki/templates/git_wiki/shortlog_table b/bn_django/git_wiki/templates/git_wiki/shortlog_table
new file mode 100644
index 0000000..8d30f80
--- /dev/null
+++ b/bn_django/git_wiki/templates/git_wiki/shortlog_table
@@ -0,0 +1,27 @@
+{% if shortlog %}
+<table class="gitbrowser">
+{% for l in shortlog %}
+<tr>
+ <td class="date">
+ {{ l.date }}</td>
+ <td class="author">
+ {{ l.author }}</td>
+ <td class="description">
+ <a href="/k/commit/{{ l.hash }}/" class="description">
+ {{ l.description|truncatewords:10 }}</a></td>
+ <td class="shorthash">
+ {% if heads %}{% for h in heads.iteritems %}
+ {% ifequal h.1 l.hash %}
+ <span style="head">[{{ h.0 }}]</span>
+ {% endifequal %}
+ {% endfor %}{% endif %}
+ {% if tags %}{% for t in tags.iteritems %}
+ {% ifequal l.hash t.1 %}
+ <span style="tag">[{{ t.0 }}]</span>
+ {% endifequal %}{% endfor %}{% endif %}
+
+ <a href="/k/commit/{{ l.hash }}" class="subtle">
+ <span class="hash">{{ l.shorthash }}</span></a>...</td></tr>
+{% endfor %}
+</table>
+{% else %}No shortlog!{% endif %}
diff --git a/bn_django/git_wiki/urls.py b/bn_django/git_wiki/urls.py
index 98cedc4..d765aea 100644
--- a/bn_django/git_wiki/urls.py
+++ b/bn_django/git_wiki/urls.py
@@ -4,11 +4,6 @@ from django.conf import settings
from models import *
try:
- GITWIKI_BASE = settings.GITWIKI_BASE
-except AttributeError:
- GITWIKI_BASE='/home/usr/doc/'
-
-try:
ADMIN_URL = settings.ADMIN_URL
except AttributeError:
ADMIN_URL='/admin'
diff --git a/bn_django/git_wiki/views.py b/bn_django/git_wiki/views.py
index d9ce15f..1212f44 100644
--- a/bn_django/git_wiki/views.py
+++ b/bn_django/git_wiki/views.py
@@ -1,4 +1,3 @@
-import settings
from django import forms, http, template
from django.contrib.auth.decorators import login_required
from django.shortcuts import get_object_or_404, render_to_response
@@ -7,37 +6,34 @@ from django.http import HttpResponse
import os, commands
from models import *
-
-try:
- GITWIKI_BASE = settings.GITWIKI_BASE+'/'
-except AttributeError:
- GITWIKI_BASE='/home/'
-
-try:
- GITCOMMAND = settings.GITCOMMAND
-except AttributeError:
- GITCOMMAND='git'
-
+from settings import *
# Create your views here.
def frontpage(request):
-
+ t = fromslug('/')
+ t.update()
return render_to_response('git_wiki/frontpage.html', \
- dict())
-
-def item(request, req=''):
- #GITPREFIX = models.getGITPREFIX()
- #i = Item()
- #i.update()
-
- return render_to_response('git_browse/item.html',
+ dict(shortlog=shortlog(), tree=t))
+
+def tree(request, reqslug):
+ t = fromslug(reqslug)
+ if t.type == 'blob':
+ return item(request, reqslug)
+ t.update()
+ return render_to_response('git_wiki/tree.html',
+ dict(shortlog=shortlog(tree=t), tree=t))
+
+def item(request, reqslug):
+ i = fromslug(reqslug)
+ if i.type == 'tree':
+ return tree(request, reqslug)
+ i.update()
+ return render_to_response('git_wiki/item.html',
dict(item=i))
def olditem(request, hash):
- #GITPREFIX = models.getGITPREFIX()
- #i = Item()
- #i.update()
-
+ i = get_object_or_404(Item, id=hash)
+ i.update()
return render_to_response('git_browse/olditem.html',
dict(item=i))
diff --git a/bn_django/templates/about.html b/bn_django/templates/about.html
index ddca340..86755d5 100644
--- a/bn_django/templates/about.html
+++ b/bn_django/templates/about.html
@@ -10,7 +10,8 @@
{% block content %}
<p />
<div class="righty_content">
- <img src="http://static.bryannewbold.com/img/orange_small.jpg" />
+ <img src="http://static.bryannewbold.com/img/orange_small.jpg"
+ alt="the author" />
<br />
<div class="content_caption">the perp</div>
</div>
diff --git a/bn_django/templates/base.html b/bn_django/templates/base.html
index e40c27e..819d556 100644
--- a/bn_django/templates/base.html
+++ b/bn_django/templates/base.html
@@ -3,23 +3,21 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
{% block stylesheets %}
-<link rel="STYLESHEET" type="text/css" href="style/default.css">
-<link rel="STYLESHEET" type="text/css" href="/style/default.css">
-<!--<link rel="STYLESHEET" type="text/css" href="http://static.bryannewbold.com/style/default.css">-->
-{% endblock %}
-{% block externaljs %}
-
+<link rel="STYLESHEET" type="text/css" href="style/default.css" />
+<link rel="STYLESHEET" type="text/css" href="/style/default.css" />
+<!--<link rel="STYLESHEET" type="text/css" href="http://static.bryannewbold.com/style/default.css" />-->
{% endblock %}
+{% block externaljs %} {% endblock %}
<title>{% block windowtitle %}bryannewbold.com{% endblock %}</title>
</head>
<body>
<div id="top_bar">
<div id="top_bar_content">
- <span class="lefty"><a href="/">bryannewbold.com</a></span>
<span class="righty"><a href="/knowledge">knowledge</a>&nbsp;
<a href="/photos">photos</a>&nbsp;
<a href="/code">code</a></span>
<!-- <a href="/projects">projects</a> -->
+ <span class="lefty"><a href="/">bryannewbold.com</a></span>
</div>
</div>
<div class="content" id="main_title">
diff --git a/bn_django/templates/frontpage.html b/bn_django/templates/frontpage.html
index 057d0c8..dc3f450 100644
--- a/bn_django/templates/frontpage.html
+++ b/bn_django/templates/frontpage.html
@@ -60,7 +60,8 @@ None yet!
{% if latest_photos %}
<div class="centerize">
{% for photo in latest_photos %}
-<a href="{{ photo.get_absolute_url }}"><img src="{{ photo.thumburl }}" /></a>
+<a href="{{ photo.get_absolute_url }}"><img src="{{ photo.thumburl }}"
+ alt="{{ photo.title }}" /></a>
<br />
{% endfor %}
</div>
diff --git a/bn_django/urls.py b/bn_django/urls.py
index 59c7b0a..9ccf0a3 100644
--- a/bn_django/urls.py
+++ b/bn_django/urls.py
@@ -14,8 +14,7 @@ urlpatterns = patterns('',
(r'^copyright/$', 'django.views.generic.simple.direct_to_template', {'template': 'copyright.html'}),
- (r'^knowledge/', 'bn_django.git_wiki.views.frontpage',),
- (r'^k/$', 'bn_django.git_wiki.views.frontpage',),
+ (r'^knowledge/$', 'bn_django.git_wiki.views.frontpage',),
(r'^k/', include('bn_django.git_wiki.urls')),
(r'^code/', include('bn_django.git_browse.urls')),
(r'^photos/', include('bn_django.photos.urls')),