From 0b075d1277620350ff7642f8aa9c8e5734cf86be Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Mon, 7 Feb 2022 13:08:21 +0100 Subject: [PATCH 01/11] Enable pip cache on GitHub Actions --- .github/workflows/flask.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/flask.yml b/.github/workflows/flask.yml index bb192c94..d94c15d8 100644 --- a/.github/workflows/flask.yml +++ b/.github/workflows/flask.yml @@ -37,9 +37,10 @@ jobs: steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v1 + uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} + cache: 'pip' - name: Install dependencies run: | From 0d278009481bc79bce0a6044352f1ee752d11e5d Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Mon, 7 Feb 2022 14:50:19 +0100 Subject: [PATCH 02/11] Create module to store user messages using sessions Module ereuse_devicehub.messages inspired by django.contrib.messages --- ereuse_devicehub/messages.py | 68 ++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 ereuse_devicehub/messages.py diff --git a/ereuse_devicehub/messages.py b/ereuse_devicehub/messages.py new file mode 100644 index 00000000..29412060 --- /dev/null +++ b/ereuse_devicehub/messages.py @@ -0,0 +1,68 @@ +from audioop import add +from curses import ERR +from flask import session + + +DEBUG = 10 +INFO = 20 +SUCCESS = 25 +WARNING = 30 +ERROR = 40 + +DEFAULT_LEVELS = { + 'DEBUG': DEBUG, + 'INFO': INFO, + 'SUCCESS': SUCCESS, + 'WARNING': WARNING, + 'ERROR': ERROR, +} + +DEFAULT_TAGS = { + DEBUG: 'light', + INFO: 'info', + SUCCESS: 'success', + WARNING: 'warning', + ERROR: 'danger', +} + +DEFAULT_ICONS = { + DEBUG: 'tools', + INFO: 'info-circle', + SUCCESS: 'check-circle', + WARNING: 'exclamation-triangle', + ERROR: 'exclamation-octagon', +} + + +def add_message(level, message): + messages = session.get('_messages', []) + + icon = DEFAULT_ICONS[level] + level_tag = DEFAULT_TAGS[level] + + messages.append({'level': level_tag, 'icon': icon, 'content': message}) + + +def debug(message): + """Add a message with the ``DEBUG`` level.""" + add_message(DEBUG, message) + + +def info(message): + """Add a message with the ``INFO`` level.""" + add_message(INFO, message) + + +def success(message): + """Add a message with the ``SUCCESS`` level.""" + add_message(SUCCESS, message) + + +def warning(message): + """Add a message with the ``WARNING`` level.""" + add_message(WARNING, message) + + +def error(message): + """Add a message with the ``ERROR`` level.""" + add_message(ERROR, message) From 574ac4123929099119cbdfc94420af16ccf2be19 Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Mon, 7 Feb 2022 14:52:17 +0100 Subject: [PATCH 03/11] Render messages on base_site.html & add new action message --- ereuse_devicehub/inventory/views.py | 6 ++++-- .../templates/ereuse_devicehub/base_site.html | 9 +++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index bd52eb77..3f6640aa 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -1,10 +1,9 @@ -import datetime - import flask from flask import Blueprint, request, url_for from flask.views import View from flask_login import current_user, login_required +from ereuse_devicehub import messages from ereuse_devicehub.inventory.forms import (AllocateForm, LotDeviceForm, LotForm, NewActionForm, NewDeviceForm, TagDeviceForm, @@ -303,6 +302,9 @@ class NewActionView(View): if self.form.validate_on_submit(): self.form.save() + + # TODO(@slamora): include details of created action + messages.success('Action created!') return flask.redirect(next_url) diff --git a/ereuse_devicehub/templates/ereuse_devicehub/base_site.html b/ereuse_devicehub/templates/ereuse_devicehub/base_site.html index 99cf0cf5..b0baf853 100644 --- a/ereuse_devicehub/templates/ereuse_devicehub/base_site.html +++ b/ereuse_devicehub/templates/ereuse_devicehub/base_site.html @@ -175,6 +175,15 @@
+ {% block messages %} + {% for message in session['_messages'] %} + + {% endfor %} + {% endblock %} {% block main %} {% endblock main %} From a864bfc78d0098984a0142b319204304a8bf5a41 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 7 Feb 2022 18:07:53 +0100 Subject: [PATCH 04/11] Bump flask-cors from 3.0.6 to 3.0.9 (#142) * Bump flask-cors from 3.0.6 to 3.0.9 Bumps [flask-cors](https://github.com/corydolphin/flask-cors) from 3.0.6 to 3.0.9. - [Release notes](https://github.com/corydolphin/flask-cors/releases) - [Changelog](https://github.com/corydolphin/flask-cors/blob/master/CHANGELOG.md) - [Commits](https://github.com/corydolphin/flask-cors/compare/3.0.6...3.0.9) Signed-off-by: dependabot[bot] * Bump flask-cors from 3.0.9 to 3.0.10 Bumps [flask-cors](https://github.com/corydolphin/flask-cors) from 3.0.9 to 3.0.10 - [Release notes](https://github.com/corydolphin/flask-cors/releases) - [Changelog](https://github.com/corydolphin/flask-cors/blob/master/CHANGELOG.md) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Santiago Lamora --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index bd7e7980..1ee55de6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,7 +8,7 @@ colorama==0.3.9 colour==0.1.5 ereuse-utils[naming,test,session,cli]==0.4.0b49 Flask==1.0.2 -Flask-Cors==3.0.6 +Flask-Cors==3.0.10 Flask-SQLAlchemy==2.3.2 hashids==1.2.0 inflection==0.3.1 From c965ead7edc649f2d7f908b479320946775f66ee Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 7 Feb 2022 18:20:01 +0100 Subject: [PATCH 05/11] Bump werkzeug from 0.14.1 to 0.15.3 (#2) Bumps [werkzeug](https://github.com/pallets/werkzeug) from 0.14.1 to 0.15.3. - [Release notes](https://github.com/pallets/werkzeug/releases) - [Changelog](https://github.com/pallets/werkzeug/blob/master/CHANGES.rst) - [Commits](https://github.com/pallets/werkzeug/compare/0.14.1...0.15.3) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Santiago Lamora --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 1ee55de6..7b729117 100644 --- a/requirements.txt +++ b/requirements.txt @@ -27,7 +27,7 @@ SQLAlchemy==1.2.17 SQLAlchemy-Utils==0.33.11 teal==0.2.0a38 webargs==4.0.0 -Werkzeug==0.14.1 +Werkzeug==0.15.3 sqlalchemy-citext==1.3.post0 flask-weasyprint==0.5 weasyprint==44 From d95e6a5f299d58887ed3580766ad8a173502a0f8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 7 Feb 2022 18:30:16 +0100 Subject: [PATCH 06/11] Bump requests from 2.19.1 to 2.27.1 (#5) * Bump requests from 2.19.1 to 2.20.0 Bumps [requests](https://github.com/requests/requests) from 2.19.1 to 2.20.0. - [Release notes](https://github.com/requests/requests/releases) - [Changelog](https://github.com/psf/requests/blob/master/HISTORY.md) - [Commits](https://github.com/requests/requests/compare/v2.19.1...v2.20.0) Signed-off-by: dependabot[bot] * Bump requests from 2.20.0 to 2.27.1 Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Santiago Lamora --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 7b729117..6c83262f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -21,7 +21,7 @@ pytest-runner==4.2 python-dateutil==2.7.3 python-stdnum==1.9 PyYAML==3.13 -requests[security]==2.19.1 +requests[security]==2.27.1 requests-mock==1.5.2 SQLAlchemy==1.2.17 SQLAlchemy-Utils==0.33.11 From b9c5ae08221dd1e7c89e58cf72a021c1409141f3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 7 Feb 2022 18:34:14 +0100 Subject: [PATCH 07/11] Bump webargs from 4.0.0 to 5.5.3 (#198) Bumps [webargs](https://github.com/marshmallow-code/webargs) from 4.0.0 to 5.5.3. - [Release notes](https://github.com/marshmallow-code/webargs/releases) - [Changelog](https://github.com/marshmallow-code/webargs/blob/dev/CHANGELOG.rst) - [Commits](https://github.com/marshmallow-code/webargs/compare/4.0.0...5.5.3) --- updated-dependencies: - dependency-name: webargs dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 6c83262f..f4349c18 100644 --- a/requirements.txt +++ b/requirements.txt @@ -26,7 +26,7 @@ requests-mock==1.5.2 SQLAlchemy==1.2.17 SQLAlchemy-Utils==0.33.11 teal==0.2.0a38 -webargs==4.0.0 +webargs==5.5.3 Werkzeug==0.15.3 sqlalchemy-citext==1.3.post0 flask-weasyprint==0.5 From aeb765dcd7eda12f7edd34c296afa47008990013 Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Tue, 8 Feb 2022 11:39:08 +0100 Subject: [PATCH 08/11] Use built-in flask.flash to implement messages --- ereuse_devicehub/messages.py | 22 ++++++++----------- .../templates/ereuse_devicehub/base_site.html | 8 +++---- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/ereuse_devicehub/messages.py b/ereuse_devicehub/messages.py index 29412060..ba3bf089 100644 --- a/ereuse_devicehub/messages.py +++ b/ereuse_devicehub/messages.py @@ -1,7 +1,4 @@ -from audioop import add -from curses import ERR -from flask import session - +from flask import flash, session DEBUG = 10 INFO = 20 @@ -26,21 +23,20 @@ DEFAULT_TAGS = { } DEFAULT_ICONS = { - DEBUG: 'tools', - INFO: 'info-circle', - SUCCESS: 'check-circle', - WARNING: 'exclamation-triangle', - ERROR: 'exclamation-octagon', + DEFAULT_TAGS[DEBUG]: 'tools', + DEFAULT_TAGS[INFO]: 'info-circle', + DEFAULT_TAGS[SUCCESS]: 'check-circle', + DEFAULT_TAGS[WARNING]: 'exclamation-triangle', + DEFAULT_TAGS[ERROR]: 'exclamation-octagon', } def add_message(level, message): - messages = session.get('_messages', []) - - icon = DEFAULT_ICONS[level] level_tag = DEFAULT_TAGS[level] + if '_message_icon' not in session: + session['_message_icon'] = DEFAULT_ICONS - messages.append({'level': level_tag, 'icon': icon, 'content': message}) + flash(message, level_tag) def debug(message): diff --git a/ereuse_devicehub/templates/ereuse_devicehub/base_site.html b/ereuse_devicehub/templates/ereuse_devicehub/base_site.html index b0baf853..5bd1994c 100644 --- a/ereuse_devicehub/templates/ereuse_devicehub/base_site.html +++ b/ereuse_devicehub/templates/ereuse_devicehub/base_site.html @@ -176,10 +176,10 @@
{% block messages %} - {% for message in session['_messages'] %} -