]> git.openstreetmap.org Git - osqa.git/blob - forum/registry.py
Handle redirects and other responses in parameter decorators.
[osqa.git] / forum / registry.py
1 from forum.modules import ui
2 from django.utils.translation import ugettext as _
3 from django.core.urlresolvers import reverse
4 from django.template.defaultfilters import slugify
5 from forum.templatetags.extra_tags import get_score_badge
6 from forum import settings
7
8
9 ui.register(ui.HEADER_LINKS,
10             ui.Link(_('faq'), ui.Url('faq'), weight=400),
11             ui.Link(_('about'), ui.Url('about'), weight=300),
12
13             ui.Link(
14                     text=lambda u, c: u.is_authenticated() and _('logout') or _('login'),
15                     url=lambda u, c: u.is_authenticated() and reverse('logout') or reverse('auth_signin'),
16                     weight=200),
17
18             ui.Link(
19                     visibility=ui.Visibility.AUTHENTICATED,
20                     text=lambda u, c: u.username,
21                     url=lambda u, c: u.get_profile_url(),
22                     post_code=lambda u, c: get_score_badge(u),
23                     weight=100),
24
25             ui.Link(
26                     visibility=ui.Visibility.SUPERUSER,
27                     text=_('administration'),
28                     url=lambda u, c: reverse('admin_index'),
29                     weight=0)
30
31 )
32
33 class SupportLink(ui.Link):
34     def can_render(self, context):
35         return bool(settings.SUPPORT_URL)
36
37
38 ui.register(ui.FOOTER_LINKS,
39             ui.Link(
40                     text=_('contact'),
41                     url=lambda u, c: settings.CONTACT_URL and settings.CONTACT_URL or "%s?next=%s" % (reverse('feedback'), c['request'].path),
42                     weight=400),
43             SupportLink(_('support'), settings.SUPPORT_URL, attrs={'target': '_blank'}, weight=300),
44             ui.Link(_('privacy'), ui.Url('privacy'), weight=200),
45             ui.Link(_('faq'), ui.Url('faq'), weight=100),
46             ui.Link(_('about'), ui.Url('about'), weight=0),
47 )
48
49 class ModerationMenuGroup(ui.AjaxMenuGroup):
50     def can_render(self, context):
51         return context['user'] != context['viewer'] and super(ModerationMenuGroup, self).can_render(context)
52
53 class SuperUserSwitchMenuItem(ui.UserMenuItem):
54     def can_render(self, context):
55         return context['viewer'].is_siteowner or not context['user'].is_superuser
56
57 ui.register(ui.USER_MENU,
58             ui.UserMenuItem(
59                 label=_("edit profile"),
60                 url=lambda u, c: reverse('edit_user', kwargs={'id': c['user'].id}),
61                 span_attrs={'class': 'user-edit'},
62                 weight=0
63             ),
64             ui.UserMenuItem(
65                 label=_("authentication settings"),
66                 url=lambda u, c: reverse('user_authsettings', kwargs={'id': c['user'].id}),
67                 span_attrs={'class': 'user-auth'},
68                 weight=100
69             ),
70             ui.UserMenuItem(
71                 label=_("email notification settings"),
72                 url=lambda u, c: reverse('user_subscriptions', kwargs={'id': c['user'].id, 'slug': slugify(c['user'].username)}),
73                 span_attrs={'class': 'user-subscriptions'},
74                 weight=200
75             ),
76             ui.UserMenuItem(
77                 label=_("other preferences"),
78                 url=lambda u, c: reverse('user_preferences', kwargs={'id': c['user'].id, 'slug': slugify(c['user'].username)}),
79                 weight=200
80             ),
81             ModerationMenuGroup(_("Moderation tools"), items=(
82                 ui.UserMenuItem(
83                     label=lambda u, c: c['user'].is_suspended() and _("withdraw suspension") or _("suspend this user"),
84                     url=lambda u, c: reverse('user_suspend', kwargs={'id': c['user'].id}),
85                     a_attrs=lambda u, c: {'class': c['user'].is_suspended() and 'ajax-command confirm' or 'ajax-command withprompt'},
86                     render_to=lambda u: not u.is_superuser,
87                 ),
88                 ui.UserMenuItem(
89                     label=lambda u, c: _("give/take karma"),
90                     url=lambda u, c: reverse('user_award_points', kwargs={'id': c['user'].id}),
91                     a_attrs=lambda u, c: {'id': 'award-rep-points', 'class': 'ajax-command withprompt'},
92                     span_attrs={'class': 'user-award_rep'},
93                     render_to=lambda u: not u.is_suspended(),
94                 ),
95                 ui.UserMenuItem(
96                     label=lambda u, c: c['user'].is_staff and _("remove moderator status") or _("grant moderator status"),
97                     url=lambda u, c: reverse('user_powers', kwargs={'id': c['user'].id, 'action':c['user'].is_staff and 'remove' or 'grant', 'status': 'staff'}),
98                     a_attrs=lambda u, c: {'class': 'ajax-command confirm'},
99                     span_attrs={'class': 'user-moderator'},
100                 ),
101                 SuperUserSwitchMenuItem(
102                     label=lambda u, c: c['user'].is_superuser and _("remove super user status") or _("grant super user status"),
103                     url=lambda u, c: reverse('user_powers', kwargs={'id': c['user'].id, 'action':c['user'].is_superuser and 'remove' or 'grant', 'status': 'super'}),
104                     a_attrs=lambda u, c: {'class': 'ajax-command confirm'},
105                     span_attrs={'class': 'user-superuser'},
106                 ),
107             ), visibility=ui.Visibility.SUPERUSER, weight=500)
108 )