diff options
author | Ivan Habunek <ivan@habunek.com> | 2018-11-18 13:25:05 +0100 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2018-11-18 08:54:09 -0500 |
commit | e1ec176f46314eea695b41c8cb422be146c6b46f (patch) | |
tree | 47f94a1bce2d27532ce8b7cf8fe6b1b442bb2a48 /gitsrht | |
parent | 4502aa711cf239b018646aa46ee283619b04ab55 (diff) |
Add url helpers
Diffstat (limited to 'gitsrht')
-rw-r--r-- | gitsrht/app.py | 4 | ||||
-rw-r--r-- | gitsrht/templates/log.html | 5 | ||||
-rw-r--r-- | gitsrht/templates/refs.html | 4 | ||||
-rw-r--r-- | gitsrht/urls.py | 13 |
4 files changed, 19 insertions, 7 deletions
diff --git a/gitsrht/app.py b/gitsrht/app.py index 0cf23f6..491801b 100644 --- a/gitsrht/app.py +++ b/gitsrht/app.py @@ -14,6 +14,7 @@ from gitsrht.types import User db.init() import gitsrht.oauth +from gitsrht import urls from gitsrht.git import commit_time, trim_commit def lookup_user(email): @@ -78,3 +79,6 @@ class GitApp(SrhtFlask): return user app = GitApp() + +app.add_template_filter(urls.log_rss_url) +app.add_template_filter(urls.refs_rss_url) diff --git a/gitsrht/templates/log.html b/gitsrht/templates/log.html index 90740d3..0f1e3fc 100644 --- a/gitsrht/templates/log.html +++ b/gitsrht/templates/log.html @@ -8,10 +8,7 @@ <link rel="alternate" title="{{ repo.owner.canonical_name }}/{{ repo.name }}: {{ ref }} log" type="application/rss+xml" - href="{{ root }}{{ url_for('repo.log_rss', - owner=repo.owner.canonical_name, - repo=repo.name, - ref=ref if ref != "master" else None) }}"> + href="{{ root }}{{ repo|log_rss_url(ref=ref) }}"> {% endblock %} {% block content %} diff --git a/gitsrht/templates/refs.html b/gitsrht/templates/refs.html index f63f025..9fbea6d 100644 --- a/gitsrht/templates/refs.html +++ b/gitsrht/templates/refs.html @@ -8,9 +8,7 @@ <link rel="alternate" title="{{ repo.owner.canonical_name }}/{{ repo.name }} refs" type="application/rss+xml" - href="{{ root }}{{ url_for('repo.refs_rss', - owner=repo.owner.canonical_name, - repo=repo.name) }}"> + href="{{ root }}{{ repo|refs_rss_url }}"> {% endblock %} {% block content %} diff --git a/gitsrht/urls.py b/gitsrht/urls.py new file mode 100644 index 0000000..24b4df8 --- /dev/null +++ b/gitsrht/urls.py @@ -0,0 +1,13 @@ +from flask import url_for + +def log_rss_url(repo, ref=None): + ref = ref if ref != "master" else None + return url_for("repo.log_rss", + owner=repo.owner.canonical_name, + repo=repo.name, + ref=ref) + +def refs_rss_url(repo): + return url_for("repo.refs_rss", + owner=repo.owner.canonical_name, + repo=repo.name) |