Skip to content

Commit 12faa4a

Browse files
committed
Summary: Rewrite community tags to use the much simpler built-in tag parser
- Legacy-Id: 8968
1 parent 703d999 commit 12faa4a

1 file changed

Lines changed: 20 additions & 56 deletions

File tree

ietf/community/templatetags/community_tags.py

Lines changed: 20 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -8,47 +8,25 @@
88

99
register = template.Library()
1010

11-
12-
class CommunityListNode(template.Node):
13-
14-
def __init__(self, user, var_name):
15-
self.user = user
16-
self.var_name = var_name
17-
18-
def render(self, context):
19-
user = self.user.resolve(context)
20-
if not (user and hasattr(user, "is_authenticated") and user.is_authenticated() ):
21-
return ''
22-
lists = {'personal': CommunityList.objects.get_or_create(user=user)[0]}
23-
try:
24-
person = user.person
25-
groups = []
26-
managed_areas = [i.group for i in Role.objects.filter(name__slug='ad', email__in=person.email_set.all())]
27-
for area in managed_areas:
28-
groups.append(CommunityList.objects.get_or_create(group=area)[0])
29-
managed_wg = [i.group for i in Role.objects.filter(name__slug='chair', group__type__slug='wg', email__in=person.email_set.all())]
30-
for wg in managed_wg:
31-
groups.append(CommunityList.objects.get_or_create(group=wg)[0])
32-
lists['group'] = groups
33-
except:
34-
pass
35-
context.update({self.var_name: lists})
11+
@register.assignment_tag
12+
def get_user_managed_lists(user):
13+
if not (user and hasattr(user, "is_authenticated") and user.is_authenticated()):
3614
return ''
37-
38-
39-
@register.tag
40-
def get_user_managed_lists(parser, token):
41-
firstbits = token.contents.split(None, 2)
42-
if len(firstbits) != 3:
43-
raise template.TemplateSyntaxError("'get_user_managed_lists' tag takes three arguments")
44-
user = parser.compile_filter(firstbits[1])
45-
lastbits_reversed = firstbits[2][::-1].split(None, 2)
46-
if lastbits_reversed[1][::-1] != 'as':
47-
raise template.TemplateSyntaxError("next-to-last argument to 'get_user_managed_lists' tag must"
48-
" be 'as'")
49-
var_name = lastbits_reversed[0][::-1]
50-
return CommunityListNode(user, var_name)
51-
15+
lists = {'personal': CommunityList.objects.get_or_create(user=user)[0]}
16+
print lists
17+
try:
18+
person = user.person
19+
groups = []
20+
managed_areas = [i.group for i in Role.objects.filter(name__slug='ad', email__in=person.email_set.all())]
21+
for area in managed_areas:
22+
groups.append(CommunityList.objects.get_or_create(group=area)[0])
23+
managed_wg = [i.group for i in Role.objects.filter(name__slug='chair', group__type__slug='wg', email__in=person.email_set.all())]
24+
for wg in managed_wg:
25+
groups.append(CommunityList.objects.get_or_create(group=wg)[0])
26+
lists['group'] = groups
27+
except:
28+
pass
29+
return lists
5230

5331
@register.inclusion_tag('community/display_field.html', takes_context=False)
5432
def show_field(field, doc):
@@ -57,25 +35,11 @@ def show_field(field, doc):
5735
}
5836

5937

60-
class CommunityListViewNode(template.Node):
61-
62-
def __init__(self, clist):
63-
self.clist = clist
64-
65-
def render(self, context):
66-
clist = self.clist.resolve(context)
38+
@register.simple_tag
39+
def get_clist_view(clist):
6740
if settings.DEBUG or not clist.cached:
6841
clist.cached = render_to_string('community/raw_view.html',
6942
{'cl': clist,
7043
'dc': clist.get_display_config()})
7144
clist.save()
7245
return clist.cached
73-
74-
75-
@register.tag
76-
def get_clist_view(parser, token):
77-
firstbits = token.contents.split(None, 1)
78-
if len(firstbits) != 2:
79-
raise template.TemplateSyntaxError("'get_clist_view' tag takes one argument")
80-
clist = parser.compile_filter(firstbits[1])
81-
return CommunityListViewNode(clist)

0 commit comments

Comments
 (0)