~edwargix/git.sr.ht

e1ec176f46314eea695b41c8cb422be146c6b46f — Ivan Habunek 7 years ago 4502aa7
Add url helpers
4 files changed, 19 insertions(+), 7 deletions(-)

M gitsrht/app.py
M gitsrht/templates/log.html
M gitsrht/templates/refs.html
A gitsrht/urls.py
M gitsrht/app.py => gitsrht/app.py +4 -0
@@ 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)

M gitsrht/templates/log.html => gitsrht/templates/log.html +1 -4
@@ 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 %}

M gitsrht/templates/refs.html => gitsrht/templates/refs.html +1 -3
@@ 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 %}

A gitsrht/urls.py => gitsrht/urls.py +13 -0
@@ 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)