task #2741 fix Handle error message, provider connection when we are creating an unnamed tag

This commit is contained in:
Cayo Puigdefabregas 2022-02-28 11:46:31 +01:00
parent b85f4f298c
commit a45fd815a2
2 changed files with 10 additions and 2 deletions

View file

@ -1,6 +1,7 @@
import copy
import json
from json.decoder import JSONDecodeError
from requests.exceptions import ConnectionError
from boltons.urlutils import URL
from ereuse_devicehub.db import db
@ -411,7 +412,11 @@ class TagUnnamedForm(FlaskForm):
def save(self):
num = self.amount.data
tags_id, _ = g.tag_provider.post('/', {}, query=[('num', num)])
try:
tags_id, _ = g.tag_provider.post('/', {}, query=[('num', num)])
except ConnectionError:
pass
return []
tags = [Tag(id=tag_id, provider=g.inventory.tag_provider) for tag_id in tags_id]
db.session.add_all(tags)
db.session.commit()

View file

@ -256,7 +256,10 @@ class TagAddUnnamedView(View):
context = {'page_title': 'New Unnamed Tag', 'lots': lots}
form = TagUnnamedForm()
if form.validate_on_submit():
form.save()
tags = form.save()
if not tags:
msg = 'Sorry, the communication with the tag server is not possible now!'
messages.error(msg)
next_url = url_for('inventory.devices.taglist')
return flask.redirect(next_url)