diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index 8959ae93..d551bb0d 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -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() diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index cb80b895..40764189 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -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)