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