|
32 | 32 |
|
33 | 33 | from django import template |
34 | 34 | from django.core.cache import cache |
35 | | -from django.template import loader |
| 35 | +from django.template.loader import render_to_string |
36 | 36 |
|
37 | 37 | from ietf.group.models import Group |
38 | 38 |
|
|
43 | 43 | 'rai':'RAI' |
44 | 44 | } |
45 | 45 |
|
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 |
54 | 51 |
|
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") |
59 | 54 |
|
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")] |
61 | 59 |
|
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] |
63 | 61 |
|
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] |
70 | 63 |
|
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