Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix user initials view #476

Merged
merged 1 commit into from
Sep 11, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 43 additions & 17 deletions rero_ils/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from functools import partial, wraps

from flask import Blueprint, abort, current_app, jsonify, redirect, \
render_template, request, url_for
render_template, request, session, url_for
from flask_babelex import gettext as _
from flask_login import current_user
from flask_menu import current_menu
Expand All @@ -46,9 +46,8 @@
)


@blueprint.before_app_request
def init_menu():
"""Create the header menus."""
def init_menu_lang():
"""Create the header language menu."""
item = current_menu.submenu('main.menu')
item.register(
endpoint=None,
Expand Down Expand Up @@ -86,22 +85,34 @@ def hide_language(lang):
)
order += 1

item = current_menu.submenu('main.menu.help')
item.register(
endpoint='rero_ils.help',
text='{icon} {help}'.format(
icon='<i class="fa fa-info"></i>',
help=_('Help')
),
order=100
)
item = current_menu.submenu('main.menu.help')
item.register(
endpoint='rero_ils.help',
text='{icon} {help}'.format(
icon='<i class="fa fa-info"></i>',
help=_('Help')
),
order=100
)


def init_menu_profile():
"""Create the profile header menu."""
item = current_menu.submenu('main.profile')
account = _('My Account')
if current_user.is_authenticated:
patron = Patron.get_patron_by_email(current_user.email)
if patron:
account = patron.initial
user_initials = session.get('user_initials')
if session.get('user_id'):
if user_initials:
account = user_initials
else:
patron = Patron.get_patron_by_email(current_user.email)
if patron:
account = patron.initial
session['user_initials'] = account
else:
if user_initials:
del session['user_initials']

item.register(
endpoint=None,
text='{icon} <span class="{visible}">{account}</span>'.format(
Expand Down Expand Up @@ -155,6 +166,21 @@ def hide_language(lang):
)


@blueprint.before_app_request
def init_menu():
"""Create the header menus."""
if (request.endpoint not in ['patrons.logged_user',
'rero_ils.schemaform',
'invenio_i18n.set_lang',
'static',
'security.login',
'patrons.logged_user',
'_debug_toolbar.static'] and
request.method == 'GET'):
init_menu_lang()
init_menu_profile()


def check_organisation_viewcode(fn):
"""Check if viewcode parameter is defined."""
@wraps(fn)
Expand Down