Refactoring
Jonas Haag
9 years ago
0 | 0 |
{% extends 'base.html' %}
|
1 | 1 |
|
2 | |
{% block extra_header %}{% endblock %} {# no branch selector on commits #}
|
|
2 |
{% block extra_header %}{% endblock %} {# hide branch selector #}
|
3 | 3 |
|
4 | 4 |
{% block title %}
|
5 | 5 |
Commit {{ rev }} - {{ repo.name }}
|
39 | 39 |
return current_app.send_static_file('robots.txt')
|
40 | 40 |
|
41 | 41 |
|
|
42 |
def _get_repo_and_rev(repo, rev=None):
|
|
43 |
try:
|
|
44 |
repo = current_app.repos[repo]
|
|
45 |
except KeyError:
|
|
46 |
raise NotFound("No such repository %r" % repo)
|
|
47 |
|
|
48 |
if rev is None:
|
|
49 |
rev = repo.get_default_branch()
|
|
50 |
if rev is None:
|
|
51 |
raise NotFound("Empty repository")
|
|
52 |
try:
|
|
53 |
commit = repo.get_commit(rev)
|
|
54 |
except KeyError:
|
|
55 |
raise NotFound("No such commit %r" % rev)
|
|
56 |
|
|
57 |
return repo, rev, commit
|
|
58 |
|
|
59 |
|
42 | 60 |
class BaseRepoView(View):
|
43 | 61 |
"""Base for all views with a repo context.
|
44 | 62 |
|
|
63 | 81 |
return render_template(self.template_name, **self.context)
|
64 | 82 |
|
65 | 83 |
def make_template_context(self, repo, rev, path):
|
66 | |
try:
|
67 | |
repo = current_app.repos[repo]
|
68 | |
except KeyError:
|
69 | |
raise NotFound("No such repository %r" % repo)
|
70 | |
|
71 | |
if rev is None:
|
72 | |
rev = repo.get_default_branch()
|
73 | |
if rev is None:
|
74 | |
raise NotFound("Empty repository")
|
75 | |
try:
|
76 | |
commit = repo.get_commit(rev)
|
77 | |
except KeyError:
|
78 | |
raise NotFound("No such commit %r" % rev)
|
79 | |
|
|
84 |
repo, rev, commit = _get_repo_and_rev(repo, rev)
|
80 | 85 |
try:
|
81 | 86 |
blob_or_tree = repo.get_blob_or_tree(commit, path)
|
82 | 87 |
except KeyError:
|