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