codereview/browser/views.py

56 lines
1.7 KiB
Python
Raw Normal View History

2010-11-22 06:13:50 +00:00
import os
2010-11-19 05:12:29 +00:00
from django.http import Http404
from django.shortcuts import render_to_response
from codereview.dashboard.models import Repository
from codereview.browser import vcs
2010-11-19 05:12:29 +00:00
2010-11-22 06:13:50 +00:00
def log(request,repository, path=None):
2010-11-19 05:12:29 +00:00
try:
repository = Repository.objects.get(name=repository)
2010-11-19 05:12:29 +00:00
except:
raise Http404
repo = vcs.create(repository.type, repository.path)
ref = request.GET['c'] if 'c' in request.GET else repo.ref()
2010-11-19 05:12:29 +00:00
offset = int(request.GET['o']) if 'o' in request.GET else 0
limit = 20
2010-11-22 06:13:50 +00:00
path = os.path.dirname(path) if path else ''
log = repo.log(ref, path=path, max=limit, offset=offset)
navigation = dict(zip(('dirs', 'files'), repo.browse()))
2010-11-19 05:12:29 +00:00
newer = offset - limit if offset > limit else 0
# Inspect the last commit. If it has no parents, we can't go any further
# back.
last = log[-1]
older = offset + limit if last.parents else 0
return render_to_response('browser/log.html',
{
'repository': repository,
2010-11-22 06:13:50 +00:00
'path': path,
'repo': repo,
2010-11-19 05:12:29 +00:00
'log': log,
2010-11-22 06:13:50 +00:00
'navigation': navigation,
2010-11-19 05:12:29 +00:00
'ref': ref,
'offset': offset,
'newer': newer,
'older': older,
})
def view(request, repository, ref):
try:
repository = Repository.objects.get(name=repository)
2010-11-19 05:12:29 +00:00
except:
raise Http404
repo = vcs.create(repository.type, repository.path)
commit = repo.commit(ref)
diffs = repo.diff(ref)
2010-11-19 05:12:29 +00:00
return render_to_response('browser/view.html',
{
'repository': repository,
'repo': repo,
2010-11-19 05:12:29 +00:00
'ref': ref,
'commit': commit,
'diffs': diffs,
})