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
6 from forum.templatetags.extra_tags import get_score_badge
7 from forum.utils.html import cleanup_urls
8 from forum import settings
12 from django.template import get_templatetags_modules
13 modules_template_tags = get_modules_script('templatetags')
14 django_template_tags = get_templatetags_modules()
16 for m in modules_template_tags:
17 django_template_tags.append(m.__name__)
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'),
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'),
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'),
38 visibility=ui.Visibility.SUPERUSER,
39 text=_('administration'),
40 url=lambda u, c: reverse('admin_index'),
41 weight=0, name='ADMINISTRATION')
45 class SupportLink(ui.Link):
46 def can_render(self, context):
47 return bool(settings.SUPPORT_URL)
50 ui.register(ui.FOOTER_LINKS,
53 url=lambda u, c: settings.CONTACT_URL and settings.CONTACT_URL or "%s?next=%s" % (reverse('feedback'), cleanup_urls( c['request'].path)),
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),
61 class ModerationMenuGroup(ui.AjaxMenuGroup):
62 def can_render(self, context):
63 return context['user'] != context['viewer'] and super(ModerationMenuGroup, self).can_render(context)
65 class SuperUserSwitchMenuItem(ui.UserMenuItem):
66 def can_render(self, context):
67 return context['viewer'].is_siteowner or not context['user'].is_superuser
69 ui.register(ui.USER_MENU,
71 label=_("edit profile"),
72 url=lambda u, c: reverse('edit_user', kwargs={'id': c['user'].id}),
73 span_attrs={'class': 'user-edit'},
78 label=_("authentication settings"),
79 url=lambda u, c: reverse('user_authsettings', kwargs={'id': c['user'].id}),
80 span_attrs={'class': 'user-auth'},
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'},
92 label=_("other preferences"),
93 url=lambda u, c: reverse('user_preferences', kwargs={'id': c['user'].id, 'slug': slugify(c['user'].username)}),
97 ModerationMenuGroup(_("Moderation tools"), items=(
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,
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(),
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'},
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'},
127 ), visibility=ui.Visibility.SUPERUSER, weight=500, name='MOD_TOOLS')