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() %}
@@ -99,7 +99,7 @@ - {% if g.user.role_upload() and g.allow_upload %} + {% if current_user.role_upload() and g.allow_upload %}
@@ -196,7 +196,7 @@
{% endfor %} {% endif %} - {% if g.user.role_upload() and g.allow_upload %} + {% if current_user.role_upload() and g.allow_upload %}
@@ -291,7 +291,7 @@ 'description': {{_('Description')|safe|tojson}}, 'source': {{_('Source')|safe|tojson}}, }; - var language = '{{ g.user.locale }}'; + var language = '{{ current_user.locale }}'; $("#add-identifier-line").click(function() { // create a random identifier type to have a valid name in form. This will not be used when dealing with the form @@ -313,8 +313,8 @@ -{% if not g.user.locale == 'en' %} - +{% if not current_user.locale == 'en' %} + {% endif %} diff --git a/cps/templates/book_table.html b/cps/templates/book_table.html index 518b3227..ae32332b 100644 --- a/cps/templates/book_table.html +++ b/cps/templates/book_table.html @@ -4,7 +4,7 @@ {% if sort %}data-sortable="true" {% endif %} data-visible = "{{visiblility.get(parameter)}}" data-escape="true" - {% if g.user.role_edit() %} + {% if current_user.role_edit() %} data-editable-type="text" data-editable-url="{{ url_for('edit-book.edit_list_book', param=parameter)}}" data-editable-title="{{ edit_text }}" @@ -53,10 +53,10 @@
+ data-url="{{url_for('web.list_books')}}" data-locale="{{ current_user.locale }}"> - {% if g.user.role_edit() %} + {% if current_user.role_edit() %} {% 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) }} - + {{ text_table_row('languages', _('Enter Languages'),_('Languages'), false, true) }} {{ text_table_row('publishers', _('Enter Publishers'),_('Publishers'), false, true) }} - - {% if g.user.check_visibility(32768) %} + + {% 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" %} - + {% elif c.datatype == "rating" %} - + {% elif c.datatype == "float" %} - + {% elif c.datatype == "enumeration" %} - + {% 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" %} - + {% 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()%} {% endif %} @@ -105,7 +105,7 @@ {% endblock %} {% block modal %} {{ delete_book() }} -{% if g.user.role_edit() %} +{% if current_user.role_edit() %}
{{_('Series Index')}}{{_('Series Index')}}{{_('Comments')}}{{_('Comments')}}{{c.name}}{{c.name}}{{c.name}}{{c.name}}{{c.name}}{{c.name}}{{c.name}}{{c.name}}{{c.name}}{{c.name}}{{_('Delete')}}
+
@@ -90,7 +90,7 @@

{{_('Denied Domains (Blacklist)')}}

- +
diff --git a/cps/templates/index.html b/cps/templates/index.html index 0bb3da72..464a1461 100644 --- a/cps/templates/index.html +++ b/cps/templates/index.html @@ -1,7 +1,7 @@ {% import 'image.html' as image %} {% extends "layout.html" %} {% block body %} -{% if g.user.show_detail_random() and page != "discover" %} +{% if current_user.show_detail_random() and page != "discover" %}

{{_('Discover (Random Books)')}}

diff --git a/cps/templates/layout.html b/cps/templates/layout.html index fc32bcd8..07adbabd 100644 --- a/cps/templates/layout.html +++ b/cps/templates/layout.html @@ -1,7 +1,7 @@ {% from 'modal_dialogs.html' import restrict_modal, delete_book, filechooser_modal, delete_confirm_modal, change_confirm_modal %} {% import 'image.html' as image %} - + {{instance}} | {{title}} @@ -40,7 +40,7 @@
{% endif %} - {% if g.user.is_authenticated or g.allow_anonymous %} + {% if current_user.is_authenticated or g.allow_anonymous %}
@@ -52,28 +52,28 @@ {% endif %}
-{% if g.user.role_admin() %} +{% if current_user.role_admin() %}

{{_('System Statistics')}}

diff --git a/cps/templates/tasks.html b/cps/templates/tasks.html index 5cbc5f8b..386577a6 100644 --- a/cps/templates/tasks.html +++ b/cps/templates/tasks.html @@ -5,10 +5,10 @@ {% block body %}

{{_('Tasks')}}

-
+
- {% if g.user.role_admin() %} + {% if current_user.role_admin() %} {% endif %} @@ -16,7 +16,7 @@ - {% if g.user.role_admin() %} + {% if current_user.role_admin() %} {% endif %} @@ -28,7 +28,7 @@ {% endblock %} {% block modal %} {{ delete_book() }} -{% if g.user.role_admin() %} +{% if current_user.role_admin() %}
{{_('User')}}{{_('Task')}}{{_('Progress')}} {{_('Run Time')}} {{_('Start Time')}}{{_('Actions')}}
+ data-url="{{url_for('admin.list_users')}}" data-locale="{{ current_user.locale }}"> @@ -185,8 +185,8 @@ -{% if not g.user.locale == 'en' %} - +{% if not current_user.locale == 'en' %} + {% endif %} {% endblock %}
{{_('Edit')}}