by_group_url.py 617 Bytes
Newer Older
1
2
3
from django import template
from django.core.urlresolvers import reverse

Arnaud Fabre's avatar
Arnaud Fabre committed
4
from representatives.models import Mandate, Group
Arnaud Fabre's avatar
Arnaud Fabre committed
5

6
7
8
9
10
register = template.Library()


@register.filter
def by_group_url(group):
Arnaud Fabre's avatar
Arnaud Fabre committed
11
12
    if isinstance(group, Mandate):
        group = group.group
Arnaud Fabre's avatar
Arnaud Fabre committed
13
14
15
16

    if not isinstance(group, Group):
        return ''
    
17
18
19
    kwargs = {'group_kind': group.kind}

    if group.abbreviation:
20
        kwargs['group'] = group.abbreviation
21
    else:
22
        kwargs['group'] = group.name
23

24
    # kwargs['group_id'] = group.id
Arnaud Fabre's avatar
Arnaud Fabre committed
25
    
26
    return reverse(
27
        'legislature:representative_index',
28
29
        kwargs=kwargs
    )