by_mandate_url.py 443 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
from django import template
from django.core.urlresolvers import reverse

register = template.Library()


@register.filter
def by_mandate_url(mandate):
    kwargs = {'mandate_kind': mandate.group.kind}

    if mandate.group.abbreviation:
        kwargs['mandate_abbr'] = mandate.group.abbreviation
    else:
        kwargs['mandate_name'] = mandate.group.name

    return reverse(
        'representatives:listby',
        kwargs=kwargs
    )