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