diff --git a/cps/admin.py b/cps/admin.py index 1d1bf4c2..b3af0f8a 100644 --- a/cps/admin.py +++ b/cps/admin.py @@ -109,7 +109,7 @@ def before_request(): # log.info("before logout {}".format(request.path)) # logout_user() g.constants = constants - g.user = current_user + # g.user = current_user g.google_site_verification = os.getenv('GOOGLE_SITE_VERIFICATION','') g.allow_registration = config.config_public_reg g.allow_anonymous = config.config_anonbrowse diff --git a/cps/babel.py b/cps/babel.py index 5a6136a5..e6c32806 100644 --- a/cps/babel.py +++ b/cps/babel.py @@ -1,7 +1,8 @@ from babel import negotiate_locale from flask_babel import Babel, Locale from babel.core import UnknownLocaleError -from flask import request, g +from flask import request +from flask_login import current_user from . import logger @@ -11,10 +12,10 @@ babel = Babel() def get_locale(): # if a user is logged in, use the locale from the user settings - user = getattr(g, 'user', None) - if user is not None and hasattr(user, "locale"): - if user.name != 'Guest': # if the account is the guest account bypass the config lang settings - return user.locale + if current_user is not None and hasattr(current_user, "locale"): + # if the account is the guest account bypass the config lang settings + if current_user.name != 'Guest': + return current_user.locale preferred = list() if request.accept_languages: diff --git a/cps/render_template.py b/cps/render_template.py index 74462f9f..70faaa13 100644 --- a/cps/render_template.py +++ b/cps/render_template.py @@ -45,12 +45,12 @@ def get_sidebar_config(kwargs=None): "show_text": _('Show Hot Books'), "config_show": True}) if current_user.role_admin(): sidebar.append({"glyph": "glyphicon-download", "text": _('Downloaded Books'), "link": 'web.download_list', - "id": "download", "visibility": constants.SIDEBAR_DOWNLOAD, 'public': (not g.user.is_anonymous), + "id": "download", "visibility": constants.SIDEBAR_DOWNLOAD, 'public': (not current_user.is_anonymous), "page": "download", "show_text": _('Show Downloaded Books'), "config_show": content}) else: sidebar.append({"glyph": "glyphicon-download", "text": _('Downloaded Books'), "link": 'web.books_list', - "id": "download", "visibility": constants.SIDEBAR_DOWNLOAD, 'public': (not g.user.is_anonymous), + "id": "download", "visibility": constants.SIDEBAR_DOWNLOAD, 'public': (not current_user.is_anonymous), "page": "download", "show_text": _('Show Downloaded Books'), "config_show": content}) sidebar.append( @@ -58,11 +58,11 @@ def get_sidebar_config(kwargs=None): "visibility": constants.SIDEBAR_BEST_RATED, 'public': True, "page": "rated", "show_text": _('Show Top Rated Books'), "config_show": True}) sidebar.append({"glyph": "glyphicon-eye-open", "text": _('Read Books'), "link": 'web.books_list', "id": "read", - "visibility": constants.SIDEBAR_READ_AND_UNREAD, 'public': (not g.user.is_anonymous), + "visibility": constants.SIDEBAR_READ_AND_UNREAD, 'public': (not current_user.is_anonymous), "page": "read", "show_text": _('Show Read and Unread'), "config_show": content}) sidebar.append( {"glyph": "glyphicon-eye-close", "text": _('Unread Books'), "link": 'web.books_list', "id": "unread", - "visibility": constants.SIDEBAR_READ_AND_UNREAD, 'public': (not g.user.is_anonymous), "page": "unread", + "visibility": constants.SIDEBAR_READ_AND_UNREAD, 'public': (not current_user.is_anonymous), "page": "unread", "show_text": _('Show unread'), "config_show": False}) sidebar.append({"glyph": "glyphicon-random", "text": _('Discover'), "link": 'web.books_list', "id": "rand", "visibility": constants.SIDEBAR_RANDOM, 'public': True, "page": "discover", @@ -81,7 +81,7 @@ def get_sidebar_config(kwargs=None): "visibility": constants.SIDEBAR_PUBLISHER, 'public': True, "page": "publisher", "show_text": _('Show Publisher Section'), "config_show":True}) sidebar.append({"glyph": "glyphicon-flag", "text": _('Languages'), "link": 'web.language_overview', "id": "lang", - "visibility": constants.SIDEBAR_LANGUAGE, 'public': (g.user.filter_language() == 'all'), + "visibility": constants.SIDEBAR_LANGUAGE, 'public': (current_user.filter_language() == 'all'), "page": "language", "show_text": _('Show Language Section'), "config_show": True}) sidebar.append({"glyph": "glyphicon-star-empty", "text": _('Ratings'), "link": 'web.ratings_list', "id": "rate", @@ -92,12 +92,12 @@ def get_sidebar_config(kwargs=None): "page": "format", "show_text": _('Show File Formats Section'), "config_show": True}) sidebar.append( {"glyph": "glyphicon-trash", "text": _('Archived Books'), "link": 'web.books_list', "id": "archived", - "visibility": constants.SIDEBAR_ARCHIVED, 'public': (not g.user.is_anonymous), "page": "archived", + "visibility": constants.SIDEBAR_ARCHIVED, 'public': (not current_user.is_anonymous), "page": "archived", "show_text": _('Show Archived Books'), "config_show": content}) if not simple: sidebar.append( {"glyph": "glyphicon-th-list", "text": _('Books List'), "link": 'web.books_table', "id": "list", - "visibility": constants.SIDEBAR_LIST, 'public': (not g.user.is_anonymous), "page": "list", + "visibility": constants.SIDEBAR_LIST, 'public': (not current_user.is_anonymous), "page": "list", "show_text": _('Show Books List'), "config_show": content}) return sidebar, simple diff --git a/cps/templates/book_edit.html b/cps/templates/book_edit.html index 3ce1dbfa..bfb8efdd 100644 --- a/cps/templates/book_edit.html +++ b/cps/templates/book_edit.html @@ -6,7 +6,7 @@ -{% if g.user.role_delete_books() %} +{% if current_user.role_delete_books() %}
{% endif %} | @@ -66,37 +66,37 @@ {{ text_table_row('authors', _('Enter Authors'),_('Authors'), true, true) }} {{ text_table_row('tags', _('Enter Categories'),_('Categories'), false, true) }} {{ text_table_row('series', _('Enter Series'),_('Series'), false, true) }} - | {{_('Series Index')}} | +{{_('Series Index')}} | {{ text_table_row('languages', _('Enter Languages'),_('Languages'), false, true) }} {{ text_table_row('publishers', _('Enter Publishers'),_('Publishers'), false, true) }} -{{_('Comments')}} | - {% if g.user.check_visibility(32768) %} +{{_('Comments')}} | + {% if current_user.check_visibility(32768) %} {{ book_checkbox_row('is_archived', _('Archive Status'), false)}} {% endif %} {{ book_checkbox_row('read_status', _('Read Status'), false)}} {% for c in cc %} {% if c.datatype == "int" %} -{{c.name}} | +{{c.name}} | {% elif c.datatype == "rating" %} -{{c.name}} | +{{c.name}} | {% elif c.datatype == "float" %} -{{c.name}} | +{{c.name}} | {% elif c.datatype == "enumeration" %} -{{c.name}} | +{{c.name}} | {% elif c.datatype in ["datetime"] %} {% elif c.datatype == "text" %} {{ text_table_row('custom_column_' + c.id|string, _('Enter ') + c.name, c.name, false, false) }} {% elif c.datatype == "comments" %} -{{c.name}} | +{{c.name}} | {% elif c.datatype == "bool" %} {{ book_checkbox_row('custom_column_' + c.id|string, c.name, false)}} {% else %} {% endif %} {% endfor %} - {% if g.user.role_delete_books() and g.user.role_edit()%} + {% if current_user.role_delete_books() and current_user.role_edit()%}{{_('Delete')}} | {% endif %}
---|