Added some browsing abilities

This commit is contained in:
Correl Roush 2010-11-22 09:50:41 -05:00
parent eafa3947b9
commit 753b942d66
5 changed files with 39 additions and 7 deletions

View file

@ -1,3 +1,4 @@
import os
from django.template import Library
from django.template.defaultfilters import stringfilter
@ -8,3 +9,13 @@ register = Library()
def oneline(value):
line = value.split('\n')[0].strip()
return line
@register.filter
@stringfilter
def dirname(value):
return os.path.dirname(value)
@register.filter
@stringfilter
def basename(value):
return os.path.basename(value)

View file

@ -1,6 +1,7 @@
from django.conf.urls.defaults import *
urlpatterns = patterns('',
(r'^(?P<repository>.*?)/log/(?P<path>(.*?/)+)?$', 'codereview.browser.views.log'),
(r'^(?P<repository>.*?)/log/$', 'codereview.browser.views.log'),
(r'^(?P<repository>.*?)/log/(?P<path>.*?/?)$', 'codereview.browser.views.log'),
(r'^(?P<repository>.*?)/view/(?P<ref>.*?)/$', 'codereview.browser.views.view'),
)

View file

@ -14,9 +14,9 @@ def log(request,repository, path=None):
offset = int(request.GET['o']) if 'o' in request.GET else 0
limit = 20
path = os.path.dirname(path) if path else ''
path = path if path else ''
log = repo.log(ref, path=path, max=limit, offset=offset)
navigation = dict(zip(('dirs', 'files'), repo.browse()))
navigation = dict(zip(('dirs', 'files'), repo.browse(ref, os.path.dirname(path))))
newer = offset - limit if offset > limit else 0
# Inspect the last commit. If it has no parents, we can't go any further

View file

@ -6,14 +6,21 @@ a {
color: black;
}
div.navigation {
width: 200px;
width: 300px;
float: left;
background-color: #ddd;
overflow: hidden;
}
div.content {
margin-left: 200px;
margin-left: 300px;
background-color: #eee;
}
ul.tree li.dir {
list-style-type: circle;
}
ul.tree li.file {
list-style-type: square;
}
span.marker {
display: block;
float: left;

View file

@ -1,9 +1,22 @@
{% load vcs %}
<h2><a href="{% url codereview.browser.views.log repository=repository.name %}">{{ repository.name }}</a></h2>
{% if path|dirname %}
<strong>{{ path|dirname }}/</strong><br />
<a href="{% url codereview.browser.views.log repository=repository.name path=path|dirname %}">Up one</a>
{% endif %}
<ul class="tree">
{% for dir in navigation.dirs %}
<li class="dir">{{ dir }}</li>
<li class="dir">
<a href="{% url codereview.browser.views.log repository=repository.name path=dir %}/">{{ dir|basename }}</a>
</li>
{% endfor %}
{% for file in navigation.files %}
<li class="file">{{ file }}</li>
<li class="file">
{% if file == path %}
<strong>{{ file|basename }}</strong>
{% else %}
<a href="{% url codereview.browser.views.log repository=repository.name path=file %}">{{ file|basename }}</a>
{% endif %}
</li>
{% endfor %}
</ul>