diff --git a/SWSCloudCore/application.py b/SWSCloudCore/application.py index 74922d1..c30f586 100644 --- a/SWSCloudCore/application.py +++ b/SWSCloudCore/application.py @@ -73,28 +73,30 @@ def page_not_found(e): @app.before_request def before_request(): - # app.logger.debug("db.connect") - g.errors = {'total': 0, 'items': []} g.settings = dict() - - try: - database.connect() - except Exception as e: - # TODO: code to email alert - # g.endpoint = request.endpoint.replace('.', '/') - return render_template('errors/500.html'), 500 - # извлекаем настройки и определяем их в глобальную переменную for setting in models.Settings.select(models.Settings.key, models.Settings.val).execute(): g.settings[setting.key] = setting.val +@app.before_first_request +def before_first_request(): + try: + database.connect() + except Exception as e: + app.logger.error(e) + # TODO: code to email alert + # g.endpoint = request.endpoint.replace('.', '/') + return render_template('errors/500.html'), 500 + + @app.after_request def after_request(response): # app.logger.debug("db.close") - try: - database.close() - except Exception as e: - # TODO: code to email alert - pass + # try: + # database.close() + # except Exception as e: + # app.logger.error(e) + # TODO: code to email alert + # pass return response diff --git a/SWSCloudCore/templates/administrator/login.html b/SWSCloudCore/templates/administrator/login.html index 498d54a..4af2071 100644 --- a/SWSCloudCore/templates/administrator/login.html +++ b/SWSCloudCore/templates/administrator/login.html @@ -3,17 +3,20 @@ {% block content %}
- {% if g.errors['total'] > 0 %} -
-
    - {% for error in g.errors['items'] %}
  • {{ error }}
  • {% endfor %} -
-
- {% endif %} + {% with messages = get_flashed_messages() %} + {% if messages %} +
+
    + {% for message in messages %} +
  • {{ message }}
  • + {% endfor %} +
+
+ {% endif %} + {% endwith %}