From a45fd815a27c88e5d73df27576cbc60412a84e72 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 28 Feb 2022 11:46:31 +0100 Subject: [PATCH 01/24] task #2741 fix Handle error message, provider connection when we are creating an unnamed tag --- ereuse_devicehub/inventory/forms.py | 7 ++++++- ereuse_devicehub/inventory/views.py | 5 ++++- 2 files changed, 10 insertions(+), 2 deletions(-) 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) From c6538333f7dd75402fb41a2d4d0bb5be6a8df417 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 28 Feb 2022 12:02:56 +0100 Subject: [PATCH 02/24] task #2739 Manufacter and Model empty instead of None --- ereuse_devicehub/templates/inventory/device_list.html | 2 +- ereuse_devicehub/templates/inventory/tag_detail.html | 2 +- ereuse_devicehub/templates/inventory/tag_list.html | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ereuse_devicehub/templates/inventory/device_list.html b/ereuse_devicehub/templates/inventory/device_list.html index a165e387..249d3d17 100644 --- a/ereuse_devicehub/templates/inventory/device_list.html +++ b/ereuse_devicehub/templates/inventory/device_list.html @@ -246,7 +246,7 @@ - {{ dev.type }} {{ dev.manufacturer }} {{ dev.model }} + {{ dev.type }} {{ dev.manufacturer|d('', true) }} {{ dev.model|d('', true) }} diff --git a/ereuse_devicehub/templates/inventory/tag_detail.html b/ereuse_devicehub/templates/inventory/tag_detail.html index 331ae80c..15197118 100644 --- a/ereuse_devicehub/templates/inventory/tag_detail.html +++ b/ereuse_devicehub/templates/inventory/tag_detail.html @@ -35,7 +35,7 @@ diff --git a/ereuse_devicehub/templates/inventory/tag_list.html b/ereuse_devicehub/templates/inventory/tag_list.html index 8653605d..b2e31d11 100644 --- a/ereuse_devicehub/templates/inventory/tag_list.html +++ b/ereuse_devicehub/templates/inventory/tag_list.html @@ -59,7 +59,7 @@ {% if tag.device %} - {{ tag.device.type }} {{ tag.device.manufacturer }} {{ tag.device.model }} + {{ tag.device.type }} {{ tag.device.manufacturer|d('', true) }} {{ tag.device.model|d('', true) }} {% endif %} From 560d9fae051e92b61c4c7874c288ab47c13fc8a8 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 28 Feb 2022 12:16:33 +0100 Subject: [PATCH 03/24] task #2740 add tag code in name of pdf file --- ereuse_devicehub/static/js/print.pdf.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ereuse_devicehub/static/js/print.pdf.js b/ereuse_devicehub/static/js/print.pdf.js index d7d9833a..5316e1ef 100644 --- a/ereuse_devicehub/static/js/print.pdf.js +++ b/ereuse_devicehub/static/js/print.pdf.js @@ -65,5 +65,5 @@ function printpdf() { min_tag_side = (Math.min(height, width)/2) + border; pdf.addImage(imgData, 'PNG', border, border, img_side, img_side); pdf.text(tag, max_tag_side, min_tag_side); - pdf.save('Tags.pdf'); + pdf.save('Tag_'+tag+'.pdf'); } From 9a95587cf3d1d126115968bddbe04fd96d2f3c7c Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 28 Feb 2022 13:05:36 +0100 Subject: [PATCH 04/24] remove lot in top --- .../templates/inventory/device_list.html | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/ereuse_devicehub/templates/inventory/device_list.html b/ereuse_devicehub/templates/inventory/device_list.html index 249d3d17..8b5f030f 100644 --- a/ereuse_devicehub/templates/inventory/device_list.html +++ b/ereuse_devicehub/templates/inventory/device_list.html @@ -33,8 +33,34 @@
-
-

{{ lot.name }}

+
+ +
+ {% if lot and lot.is_temporary and not lot.devices %} + + + Remove Lot + + {% endif %} +
+
+ {% if lot and lot.is_temporary %} + + + Add selected Devices to a lot + + {% endif %} +
+
+ {% if lot and lot.is_temporary %} + + + Remove selected devices from a lot + + {% endif %} +
From 823594dce45ba03f1ab76ddca745d0b6f404a498 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 28 Feb 2022 13:27:12 +0100 Subject: [PATCH 05/24] add tab documents --- .../templates/inventory/device_list.html | 71 ++++++++----------- 1 file changed, 28 insertions(+), 43 deletions(-) diff --git a/ereuse_devicehub/templates/inventory/device_list.html b/ereuse_devicehub/templates/inventory/device_list.html index 124241f8..9b160df4 100644 --- a/ereuse_devicehub/templates/inventory/device_list.html +++ b/ereuse_devicehub/templates/inventory/device_list.html @@ -39,7 +39,7 @@
{% if lot and lot.is_temporary and not lot.devices %} - + Remove Lot @@ -47,18 +47,18 @@
{% if lot and lot.is_temporary %} - - - Add selected Devices to a lot - + + + Add supplier + {% endif %}
{% if lot and lot.is_temporary %} - - - Remove selected devices from a lot - + + + Add receiver + {% endif %}
@@ -92,16 +92,6 @@ - {% endblock main %} diff --git a/ereuse_devicehub/templates/inventory/device_list.html b/ereuse_devicehub/templates/inventory/device_list.html index 9b160df4..bbb1a14d 100644 --- a/ereuse_devicehub/templates/inventory/device_list.html +++ b/ereuse_devicehub/templates/inventory/device_list.html @@ -395,6 +395,5 @@ - {% endblock main %} diff --git a/ereuse_devicehub/templates/inventory/tag_detail.html b/ereuse_devicehub/templates/inventory/tag_detail.html index 15197118..88ca8681 100644 --- a/ereuse_devicehub/templates/inventory/tag_detail.html +++ b/ereuse_devicehub/templates/inventory/tag_detail.html @@ -106,7 +106,6 @@ - diff --git a/ereuse_devicehub/templates/inventory/tag_list.html b/ereuse_devicehub/templates/inventory/tag_list.html index b2e31d11..1401ff62 100644 --- a/ereuse_devicehub/templates/inventory/tag_list.html +++ b/ereuse_devicehub/templates/inventory/tag_list.html @@ -86,5 +86,4 @@ - {% endblock main %} From ab89b7eff05718f2c65c3459ef0d50ff8e412eac Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 1 Mar 2022 10:30:47 +0100 Subject: [PATCH 08/24] #2736 Move simple-datatables to base --- ereuse_devicehub/templates/ereuse_devicehub/base.html | 2 ++ ereuse_devicehub/templates/inventory/device_detail.html | 1 - ereuse_devicehub/templates/inventory/device_list.html | 6 ------ ereuse_devicehub/templates/inventory/tag_detail.html | 1 - ereuse_devicehub/templates/inventory/tag_list.html | 6 ------ 5 files changed, 2 insertions(+), 14 deletions(-) diff --git a/ereuse_devicehub/templates/ereuse_devicehub/base.html b/ereuse_devicehub/templates/ereuse_devicehub/base.html index 32ee90cb..7b56a1ec 100644 --- a/ereuse_devicehub/templates/ereuse_devicehub/base.html +++ b/ereuse_devicehub/templates/ereuse_devicehub/base.html @@ -19,10 +19,12 @@ + + diff --git a/ereuse_devicehub/templates/inventory/device_detail.html b/ereuse_devicehub/templates/inventory/device_detail.html index 5112efb9..98b04fb9 100644 --- a/ereuse_devicehub/templates/inventory/device_detail.html +++ b/ereuse_devicehub/templates/inventory/device_detail.html @@ -1,6 +1,5 @@ {% extends "ereuse_devicehub/base_site.html" %} {% block main %} -

Inventory

diff --git a/ereuse_devicehub/templates/inventory/device_list.html b/ereuse_devicehub/templates/inventory/device_list.html index bbb1a14d..7f31a60a 100644 --- a/ereuse_devicehub/templates/inventory/device_list.html +++ b/ereuse_devicehub/templates/inventory/device_list.html @@ -1,6 +1,5 @@ {% extends "ereuse_devicehub/base_site.html" %} {% block main %} -

Inventory

@@ -386,14 +385,9 @@ {% include "inventory/trade.html" %} {% include "inventory/alert_export_error.html" %} - - - {% endblock main %} diff --git a/ereuse_devicehub/templates/inventory/tag_detail.html b/ereuse_devicehub/templates/inventory/tag_detail.html index 88ca8681..356220d5 100644 --- a/ereuse_devicehub/templates/inventory/tag_detail.html +++ b/ereuse_devicehub/templates/inventory/tag_detail.html @@ -1,6 +1,5 @@ {% extends "ereuse_devicehub/base_site.html" %} {% block main %} -

Inventory

diff --git a/ereuse_devicehub/templates/inventory/tag_list.html b/ereuse_devicehub/templates/inventory/tag_list.html index 1401ff62..519debab 100644 --- a/ereuse_devicehub/templates/inventory/tag_list.html +++ b/ereuse_devicehub/templates/inventory/tag_list.html @@ -1,6 +1,5 @@ {% extends "ereuse_devicehub/base_site.html" %} {% block main %} -

Inventory

@@ -77,13 +76,8 @@
- - - {% endblock main %} From ad09d298a08b223607cbf1692ab951134ce98902 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 2 Mar 2022 13:07:04 +0100 Subject: [PATCH 09/24] add order by code in tags lists and select --- ereuse_devicehub/inventory/forms.py | 4 ++-- ereuse_devicehub/inventory/views.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index 62f295d0..da035520 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -464,9 +464,9 @@ class TagDeviceForm(FlaskForm): if self.delete: tags = Tag.query.filter(Tag.owner_id == g.user.id).filter_by( device_id=self.device_id - ) + ).order_by(Tag.id) else: - tags = Tag.query.filter(Tag.owner_id == g.user.id).filter_by(device_id=None) + tags = Tag.query.filter(Tag.owner_id == g.user.id).filter_by(device_id=None).order_by(Tag.id) self.tag.choices = [(tag.id, tag.id) for tag in tags] diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index 5df42ac3..8bb9633b 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -47,7 +47,7 @@ class DeviceListMix(View): tags = ( Tag.query.filter(Tag.owner_id == current_user.id) .filter(Tag.device_id.is_(None)) - .order_by(Tag.created.desc()) + .order_by(Tag.id.asc()) ) if lot_id: @@ -236,7 +236,7 @@ class TagListView(View): def dispatch_request(self): lots = Lot.query.filter(Lot.owner_id == current_user.id) - tags = Tag.query.filter(Tag.owner_id == current_user.id) + tags = Tag.query.filter(Tag.owner_id == current_user.id).order_by(Tag.id) context = { 'lots': lots, 'tags': tags, From c52480231bc1aaf90528e0bc4a5474b379960be8 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 2 Mar 2022 13:08:23 +0100 Subject: [PATCH 10/24] add error msg when there are more than one device selected for add or remove one tag --- ereuse_devicehub/static/js/main_inventory.js | 17 ++++++++++++--- .../templates/inventory/addDevicestag.html | 2 +- .../inventory/alert_unlink_tag_error.html | 21 +++++++++++++++++++ .../templates/inventory/device_list.html | 9 +++++--- .../inventory/tag_unlink_device.html | 2 +- 5 files changed, 43 insertions(+), 8 deletions(-) create mode 100644 ereuse_devicehub/templates/inventory/alert_unlink_tag_error.html diff --git a/ereuse_devicehub/static/js/main_inventory.js b/ereuse_devicehub/static/js/main_inventory.js index d790af81..333bf049 100644 --- a/ereuse_devicehub/static/js/main_inventory.js +++ b/ereuse_devicehub/static/js/main_inventory.js @@ -62,15 +62,26 @@ function deviceSelect() { function removeTag() { var devices = $(".deviceSelect").filter(':checked'); var devices_id = $.map(devices, function(x) { return $(x).attr('data')}); - if (devices_id.length > 0) { + if (devices_id.length == 1) { var url = "/inventory/tag/devices/"+devices_id[0]+"/del/"; window.location.href = url; + } else { + $("#unlinkTagAlertModal").click(); } } function addTag() { - deviceSelect(); - $("#addingTagModal").click(); + var devices = $(".deviceSelect").filter(':checked'); + var devices_id = $.map(devices, function(x) { return $(x).attr('data')}); + if (devices_id.length == 1) { + $("#addingTagModal .pol").hide(); + $("#addingTagModal .btn-primary").show(); + } else { + $("#addingTagModal .pol").show(); + $("#addingTagModal .btn-primary").hide(); + } + + $("#addTagAlertModal").click(); } function newTrade(action) { diff --git a/ereuse_devicehub/templates/inventory/addDevicestag.html b/ereuse_devicehub/templates/inventory/addDevicestag.html index cb929d37..5170b454 100644 --- a/ereuse_devicehub/templates/inventory/addDevicestag.html +++ b/ereuse_devicehub/templates/inventory/addDevicestag.html @@ -18,7 +18,7 @@

- You need select first some device for adding this in a tag + You need select first one device and only one for add this in a tag

diff --git a/ereuse_devicehub/templates/inventory/alert_unlink_tag_error.html b/ereuse_devicehub/templates/inventory/alert_unlink_tag_error.html new file mode 100644 index 00000000..b05fb40f --- /dev/null +++ b/ereuse_devicehub/templates/inventory/alert_unlink_tag_error.html @@ -0,0 +1,21 @@ + diff --git a/ereuse_devicehub/templates/inventory/device_list.html b/ereuse_devicehub/templates/inventory/device_list.html index 7f31a60a..3cf54939 100644 --- a/ereuse_devicehub/templates/inventory/device_list.html +++ b/ereuse_devicehub/templates/inventory/device_list.html @@ -231,17 +231,19 @@ Tags + + @@ -384,6 +386,7 @@ {% include "inventory/data_wipe.html" %} {% include "inventory/trade.html" %} {% include "inventory/alert_export_error.html" %} +{% include "inventory/alert_unlink_tag_error.html" %}