1 # This file is part of Indico.
2 # Copyright (C) 2002 - 2015 European Organization for Nuclear Research (CERN).
4 # Indico is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 3 of the
7 # License, or (at your option) any later version.
9 # Indico is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with Indico; if not, see <http://www.gnu.org/licenses/>.
17 from __future__
import unicode_literals
19 from operator
import attrgetter
21 from flask
import request
23 from indico
.core
import signals
24 from indico
.modules
.users
import User
25 from indico
.util
.i18n
import _
26 from indico
.util
.signals
import values_from_signal
27 from indico
.web
.menu
import MenuItem
29 from MaKaC
.webinterface
.pages
.admins
import WPAdminsBase
30 from MaKaC
.webinterface
.pages
.base
import WPJinjaMixin
31 from MaKaC
.webinterface
.pages
.main
import WPMainBase
32 from MaKaC
.webinterface
.wcomponents
import WSimpleNavigationDrawer
35 class WPUser(WPJinjaMixin
, WPMainBase
):
36 """Base WP for user profile pages.
38 Whenever you use this, you MUST include `user` in the params passed to
39 `render_template`. Any RH using this should inherit from `RHUserBase`
40 which already handles user/admin access. In this case, simply add
41 ``user=self.user`` to your `render_template` call.
44 template_prefix
= 'users/'
46 def _getNavigationDrawer(self
):
47 if 'user_id' in request
.view_args
:
48 user
= User
.get(request
.view_args
['user_id'])
49 profile_breadcrumb
= _('Profile of {name}').format(name
=user
.full_name
)
51 profile_breadcrumb
= _('My Profile')
52 return WSimpleNavigationDrawer(profile_breadcrumb
)
54 def _getBody(self
, params
):
55 extra_items
= sorted(values_from_signal(signals
.users
.profile_sidemenu
.send(params
['user'])),
56 key
=attrgetter('title'))
57 params
['user_menu_items'] = [
58 MenuItem(_('Dashboard'), 'users.user_dashboard'),
59 MenuItem(_('Personal data'), 'users.user_profile'),
60 MenuItem(_('Emails'), 'users.user_emails'),
61 MenuItem(_('Preferences'), 'users.user_preferences'),
62 MenuItem(_('Favorites'), 'users.user_favorites'),
64 return self
._getPageContent
(params
)
67 class WPUserDashboard(WPUser
):
68 def getCSSFiles(self
):
69 return WPUser
.getCSSFiles(self
) + self
._asset
_env
['dashboard_sass'].urls()
72 class WPUsersAdmin(WPJinjaMixin
, WPAdminsBase
):
73 template_prefix
= 'users/'
75 def _setActiveSideMenuItem(self
):
76 self
.extra_menu_items
['users'].setActive()