Skip to content

Commit 8afd3fa

Browse files
committed
Rewrite wg_menu tag to use simple_tag instead of a full template Node,
also fix a bug in the cache apparently not being filled in correctly - Legacy-Id: 6971
1 parent e2e6c24 commit 8afd3fa

1 file changed

Lines changed: 17 additions & 22 deletions

File tree

ietf/doc/templatetags/wg_menu.py

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
from django import template
3434
from django.core.cache import cache
35-
from django.template import loader
35+
from django.template.loader import render_to_string
3636

3737
from ietf.group.models import Group
3838

@@ -43,29 +43,24 @@
4343
'rai':'RAI'
4444
}
4545

46-
class WgMenuNode(template.Node):
47-
def render(self, context):
48-
x = cache.get('base_left_wgmenu')
49-
if x:
50-
return x
51-
52-
areas = Group.objects.filter(type="area", state="active").order_by('acronym')
53-
groups = Group.objects.filter(type="wg", state="active", parent__in=areas).order_by("acronym")
46+
@register.simple_tag
47+
def wg_menu():
48+
res = cache.get('base_left_wgmenu')
49+
if res:
50+
return res
5451

55-
for a in areas:
56-
a.short_area_name = area_short_names.get(a.acronym) or a.name
57-
if a.short_area_name.endswith(" Area"):
58-
a.short_area_name = a.short_area_name[:-len(" Area")]
52+
areas = Group.objects.filter(type="area", state="active").order_by('acronym')
53+
groups = Group.objects.filter(type="wg", state="active", parent__in=areas).order_by("acronym")
5954

60-
a.active_groups = [g for g in groups if g.parent_id == a.id]
55+
for a in areas:
56+
a.short_area_name = area_short_names.get(a.acronym) or a.name
57+
if a.short_area_name.endswith(" Area"):
58+
a.short_area_name = a.short_area_name[:-len(" Area")]
6159

62-
areas = [a for a in areas if a.active_groups]
60+
a.active_groups = [g for g in groups if g.parent_id == a.id]
6361

64-
res = loader.render_to_string('base/wg_menu.html', {'areas':areas})
65-
cache.set('base_left_wgmenu', x, 30*60)
66-
return res
67-
68-
def do_wg_menu(parser, token):
69-
return WgMenuNode()
62+
areas = [a for a in areas if a.active_groups]
7063

71-
register.tag('wg_menu', do_wg_menu)
64+
res = render_to_string('base/wg_menu.html', {'areas':areas})
65+
cache.set('base_left_wgmenu', res, 30*60)
66+
return res

0 commit comments

Comments
 (0)