task #2741 fix Handle error message, provider connection when we are creating an unnamed tag
This commit is contained in:
parent
b85f4f298c
commit
a45fd815a2
|
@ -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
|
||||
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()
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Reference in New Issue