Permalink
Browse files

claen up url structure; add functionality to display blob of file

  • Loading branch information...
1 parent 9eef335 commit 5077c7ceb3fa7d8839a948e4cc93b16af23026b3 @sethtrain committed Oct 30, 2008
@@ -0,0 +1,30 @@
+{% extends "base.html" %}
+
+{% load stylize %}
+{% load repositories %}
+
+{% block extra_head %}
+ <script src="/static/js/commit.js" type="text/javascript" charset="utf-8"></script>
+{% endblock %}
+
+{% block title %}
+ {{ repo.path|name }} : {{ commit|first_eight }}
+{% endblock %}
+
+{% block main_content %}
+ <p id="commit" style="display: none;">{{ commit }}</p>
+ {% if diffs %}
+ {% for d in diffs %}
+ <p>
+ <span id="f{{ forloop.counter }}">{{ d.a_path }}</span>
+ &nbsp;&nbsp;&nbsp;
+ <a href="#" onclick="$('#d{{ forloop.counter }}').toggle(); return false;">diff</a> |
+ <a href="#" id="{{ forloop.counter }}" class="blob-link">blob</a>
+ </p>
+ <div id="d{{ forloop.counter }}" style="display: none;">{% stylize 'diff' %}{{ d.diff|safe }}{% endstylize %}</div>
+ <div id="b{{ forloop.counter }}" style="display: none;"></div>
+ {% endfor %}
+ {% else %}
+ <p>No diff information.</p>
+ {% endif %}
+{% endblock %}
@@ -1,19 +0,0 @@
-{% extends "base.html" %}
-
-{% load stylize %}
-{% load repositories %}
-
-{% block title %}
- {{ repo.path|name }} : {{ commit|first_eight }}
-{% endblock %}
-
-{% block main_content %}
- {% if diffs %}
- {% for d in diffs %}
- <p>{{ d.a_path }} &nbsp;&nbsp;&nbsp;<a href="#" onclick="$('#d{{ forloop.counter }}').toggle(); return false;">diff</a></p>
- <div id="d{{ forloop.counter }}">{% stylize 'diff' %}{{ d.diff|safe }}{% endstylize %}</div>
- {% endfor %}
- {% else %}
- <p>No diff information.</p>
- {% endif %}
-{% endblock %}
@@ -16,11 +16,20 @@
</tr>
{% for commit in repo.commits %}
<tr>
- <td><a href="{% url django-git-diff repo.path|name commit %}">{{ commit|first_eight }}</a></td>
+ <td><a href="{% url django-git-commit repo.path|name commit %}">{{ commit|first_eight }}</a></td>
<td>{{ commit.message }}</td>
<td>{{ commit.committer.name }}</td>
<td>{{ commit.committed_date|tuple_to_date|date:"m/d/Y" }}</td>
</tr>
{% endfor %}
</table>
+
+ {% if repo.heads %}
+ <h3>Heads</h3>
+ <ul>
+ {% for head in repo.heads %}
+ <li>{{ head.name }}</li>
+ {% endfor %}
+ </ul>
+ {% endif %}
{% endblock %}
View
@@ -3,7 +3,8 @@
urlpatterns = []
urlpatterns += patterns('django_git.views',
- url(r'^(?P<repo>[\w_-]+)/diff/(?P<commit>[\w\d]+)/$', 'diff', name='django-git-diff'),
+ url(r'^(?P<repo>[\w_-]+)/commit/(?P<commit>[\w\d]+)/blob/$', 'blob', name='django-git-blob'),
+ url(r'^(?P<repo>[\w_-]+)/commit/(?P<commit>[\w\d]+)/$', 'commit', name='django-git-commit'),
url(r'^(?P<repo>[\w_-]+)/$', 'repo', name='django-git-repo'),
url(r'^$', 'index', name='django-git-index'),
)
View
@@ -9,7 +9,20 @@ def get_repos():
def get_repo(name):
return Repo(os.path.join(settings.REPOS_ROOT, name))
-def get_diff(name, commit):
+def get_commit(name, commit):
repo = get_repo(name)
commit = repo.commit(commit)
- return commit.diffs
+ return commit
+
+def get_blob(repo, commit, file):
+ repo = get_repo(repo)
+ commit = repo.commit(commit)
+ file = file.split('/')
+ length = len(file)
+ tree = commit.tree
+ for item in xrange(len(file)):
+ if isinstance(tree.get(file[item]), Tree):
+ tree = tree.get(file[item])
+ else:
+ blob = tree.get(file[item])
+ return blob
View
@@ -1,13 +1,24 @@
+from pygments import highlight
+from pygments.lexers import guess_lexer_for_filename
+from pygments.formatters import HtmlFormatter
+
+from django.http import HttpResponse
from django.shortcuts import render_to_response, get_object_or_404, get_list_or_404
from django.template import RequestContext
-from django_git.utils import get_repos, get_repo, get_diff
+from django_git.utils import *
def index(request, template_name='django_git/index.html'):
return render_to_response(template_name, {'repos': get_repos()}, context_instance=RequestContext(request))
def repo(request, repo, template_name='django_git/repo.html'):
return render_to_response(template_name, {'repo': get_repo(repo)}, context_instance=RequestContext(request))
-def diff(request, repo, commit, template_name='django_git/diff.html'):
- return render_to_response(template_name, {'diffs': get_diff(repo, commit), 'repo': get_repo(repo), 'commit': commit }, context_instance=RequestContext(request))
+def commit(request, repo, commit, template_name='django_git/commit.html'):
+ return render_to_response(template_name, {'diffs': get_commit(repo, commit).diffs, 'repo': get_repo(repo), 'commit': commit }, context_instance=RequestContext(request))
+
+def blob(request, repo, commit):
+ file = request.GET.get('file', '')
+ blob = get_blob(repo, commit, file)
+ lexer = guess_lexer_for_filename(blob.basename, blob.data)
+ return HttpResponse(highlight(blob.data, lexer, HtmlFormatter(cssclass="pygment_highlight")))

0 comments on commit 5077c7c

Please sign in to comment.