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