resolve conflict

This commit is contained in:
Cayo Puigdefabregas 2022-02-09 10:18:56 +01:00
commit d102eaed9c
5 changed files with 104 additions and 20 deletions

View File

@ -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: |

View File

@ -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,
@ -294,31 +293,42 @@ class TagUnlinkDeviceView(View):
class NewActionView(View):
methods = ['POST']
decorators = [login_required]
_form = NewActionForm
form_class = NewActionForm
def dispatch_request(self):
self.form = self._form()
next_url = url_for('inventory.devices.devicelist')
lot_id = self.form.lot.data
if lot_id:
next_url = url_for('inventory.devices.lotdevicelist', lot_id=lot_id)
self.form = self.form_class()
if self.form.validate_on_submit():
self.form.save()
instance = self.form.save()
messages.success('Action "{}" created successfully!'.format(instance.type))
next_url = self.get_next_url()
return flask.redirect(next_url)
def get_next_url(self):
lot_id = self.form.lot.data
if lot_id:
return url_for('inventory.devices.lotdevicelist', lot_id=lot_id)
return url_for('inventory.devices.devicelist')
class NewAllocateView(NewActionView, DeviceListMix):
methods = ['POST']
_form = AllocateForm
form_class = AllocateForm
def dispatch_request(self):
lot_id = self.form.lot.data
dispatch = super().dispatch_request()
if dispatch:
return dispatch
self.form = self.form_class()
if self.form.validate_on_submit():
instance = self.form.save()
messages.success('Action "{}" created successfully!'.format(instance.type))
next_url = self.get_next_url()
return flask.redirect(next_url)
lot_id = self.form.lot.data
self.get_context(lot_id)
self.context['form_new_allocate'] = self.form
return flask.render_template(self.template_name, **self.context)

View File

@ -0,0 +1,64 @@
from flask import flash, 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 = {
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):
level_tag = DEFAULT_TAGS[level]
if '_message_icon' not in session:
session['_message_icon'] = DEFAULT_ICONS
flash(message, level_tag)
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)

View File

@ -175,6 +175,15 @@
</aside><!-- End Sidebar-->
<main id="main" class="main">
{% block messages %}
{% for level, message in get_flashed_messages(with_categories=true) %}
<div class="alert alert-{{ level}} alert-dismissible fade show" role="alert">
<i class="bi bi-{{ session['_message_icon'][level]}} me-1"></i>
{{ message }}
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
{% endfor %}
{% endblock %}
{% block main %}
{% endblock main %}

View File

@ -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-Login==0.5.0
Flask-SQLAlchemy==2.3.2
Flask-WTF==1.0.0
@ -23,13 +23,13 @@ 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
teal==0.2.0a38
webargs==4.0.0
Werkzeug==0.14.1
webargs==5.5.3
Werkzeug==0.15.3
sqlalchemy-citext==1.3.post0
flask-weasyprint==0.5
weasyprint==44