From de24cae235a58974c755807125217ad464e6569a Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 9 Mar 2023 10:43:35 +0100 Subject: [PATCH 1/9] add placeholder --- ereuse_devicehub/inventory/forms.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index fc475f6e..a4504f17 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -1539,7 +1539,10 @@ class CustomerDetailsForm(FlaskForm): logo = URLField( 'Logo', [validators.Optional()], - render_kw={'class': "form-control"}, + render_kw={ + 'class': "form-control", + "placeholder": "Url where is the logo - acceptd only .png, .jpg, .gif, svg", + }, description="Url where is the logo", ) From 6b0110addab6e75f2a3c2878e61c9902f6ccfebb Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 9 Mar 2023 12:40:46 +0100 Subject: [PATCH 2/9] fix server report --- ereuse_devicehub/inventory/views.py | 3 ++- ereuse_devicehub/templates/inventory/erasure.html | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index 675409b4..081d42c4 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -1097,6 +1097,7 @@ class ExportsView(View): a, b = self.get_server_erasure_hosts(erasures) erasures_host, erasures_on_server = a, b + erasures_host = set(erasures_host) result = 'Success' if "Failed" in [e.severity.get_public_name() for e in erasures]: @@ -1104,7 +1105,7 @@ class ExportsView(View): erasures = sorted(erasures, key=lambda x: x.end_time) erasures_on_server = sorted(erasures_on_server, key=lambda x: x.end_time) - erasures_host = sorted(erasures_host, key=lambda x: x.end_time) + # import pdb; pdb.set_trace() erasures_normal = list(set(erasures) - set(erasures_on_server)) erasures_normal = sorted(erasures_normal, key=lambda x: x.end_time) diff --git a/ereuse_devicehub/templates/inventory/erasure.html b/ereuse_devicehub/templates/inventory/erasure.html index 76df0694..c6b40d12 100644 --- a/ereuse_devicehub/templates/inventory/erasure.html +++ b/ereuse_devicehub/templates/inventory/erasure.html @@ -366,12 +366,14 @@
Hid: {{ erasure.parent.hid }}
Tags: {{ erasure.parent.tags }}
+ {% if erasure.device.parent %}
Computer where it resides:
Title: {{ erasure.device.parent.__format__('ts') }}
DevicehubID: {{ erasure.device.parent.dhid }}
Hid: {{ erasure.device.parent.hid }}
Tags: {{ erasure.device.parent.tags }}
- {% endif %} + {% endif %} + {% endif %}
Erasure:
{{ erasure.__format__('ts') }}
From 93d6502a66709081d139ea8295f4aa3fa960b32d Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 9 Mar 2023 13:09:05 +0100 Subject: [PATCH 3/9] fix server report n_computers --- ereuse_devicehub/inventory/views.py | 4 ++-- ereuse_devicehub/templates/inventory/erasure.html | 13 +++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index 081d42c4..89d0bdac 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -1105,9 +1105,9 @@ class ExportsView(View): erasures = sorted(erasures, key=lambda x: x.end_time) erasures_on_server = sorted(erasures_on_server, key=lambda x: x.end_time) - # import pdb; pdb.set_trace() erasures_normal = list(set(erasures) - set(erasures_on_server)) erasures_normal = sorted(erasures_normal, key=lambda x: x.end_time) + n_computers = len({x.parent for x in erasures} - erasures_host) params = { 'title': 'Erasure Certificate', @@ -1117,7 +1117,7 @@ class ExportsView(View): 'uuid_report': '{}'.format(uuid.uuid4()), 'software': software, 'my_data': my_data, - 'n_computers': len(set([x.parent for x in erasures])), + 'n_computers': n_computers, 'result': result, 'customer_details': customer_details, 'erasure_hosts': erasures_host, diff --git a/ereuse_devicehub/templates/inventory/erasure.html b/ereuse_devicehub/templates/inventory/erasure.html index c6b40d12..7b8ae650 100644 --- a/ereuse_devicehub/templates/inventory/erasure.html +++ b/ereuse_devicehub/templates/inventory/erasure.html @@ -159,19 +159,20 @@ {% if erasure_hosts %} - {% for e in erasure_hosts %} - {% endfor %} - {% else %} + {% endif %} + {% if n_computers %}
- N° of sanitization server ({{ loop.index }}/{{ erasure_hosts|length }}): + N° of sanitization server {{ erasure_hosts|length }}: + {% for e in erasure_hosts %} {% if e.serial_number %} - {{ e.serial_number.upper() }} + {{ e.serial_number.upper() }}{% if not loop.last %},{% endif %} {% endif %} + {% endfor %}
N° of computers: @@ -245,7 +246,7 @@ -
+
From 6d722bb19f33c82f5b65923f09be669a5bb5e480 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 9 Mar 2023 18:07:16 +0100 Subject: [PATCH 4/9] feedback when there are one error in sanitization form --- ereuse_devicehub/forms.py | 6 ++++++ ereuse_devicehub/inventory/forms.py | 12 +++++++++++- ereuse_devicehub/views.py | 5 ++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/ereuse_devicehub/forms.py b/ereuse_devicehub/forms.py index 68485f33..4980b41e 100644 --- a/ereuse_devicehub/forms.py +++ b/ereuse_devicehub/forms.py @@ -141,6 +141,12 @@ class SanitizationEntityForm(FlaskForm): if not is_valid: return False + extensions = ["jpg", "jpeg", "png", "gif", "svg"] + if self.logo.data.lower().split(".")[-1] not in extensions: + txt = "Error in Url field - accepted only .PNG, .JPG and .GIF. extensions" + self.logo.errors = [txt] + return False + return True def save(self, commit=True): diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index a4504f17..dff4e87e 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -1561,7 +1561,17 @@ class CustomerDetailsForm(FlaskForm): def validate(self, extra_validators=None): is_valid = super().validate(extra_validators) - return is_valid + + if not is_valid: + return is_valid + + extensions = ["jpg", "jpeg", "png", "gif", "svg"] + if self.logo.data.lower().split(".")[-1] not in extensions: + txt = "Error in Url field - accepted only .PNG, .JPG and .GIF. extensions" + self.logo.errors = [txt] + return False + + return True def save(self, commit=True): self.populate_obj(self._obj) diff --git a/ereuse_devicehub/views.py b/ereuse_devicehub/views.py index 915a4dc4..65cb4d3a 100644 --- a/ereuse_devicehub/views.py +++ b/ereuse_devicehub/views.py @@ -143,8 +143,11 @@ class SanitizationEntityView(View): messages.success('Sanitization data updated successfully!') else: messages.error('Error modifying Sanitization data!') + if form.errors: + for k in form.errors.keys(): + txt = "{}: {}".format(k, form.errors[k]) + messages.error(txt) - # db.session.commit() return flask.redirect(flask.url_for('core.user-profile')) From 20ccb385d847827798dc652770606cf6a2151c8b Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 9 Mar 2023 18:38:54 +0100 Subject: [PATCH 5/9] add lots in list of erasures actions --- ereuse_devicehub/resources/device/models.py | 6 ++++++ ereuse_devicehub/templates/inventory/erasure_list.html | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index 8d2baec1..168c4371 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -676,6 +676,12 @@ class Device(Thing): return args def get_lots_for_template(self): + if self.binding: + return self.binding.device.get_lots_for_template() + + if not self.lots and hasattr(self, 'parent') and self.parent: + return self.parent.get_lots_for_template() + lots = [] for lot in self.lots: if lot.is_incoming: diff --git a/ereuse_devicehub/templates/inventory/erasure_list.html b/ereuse_devicehub/templates/inventory/erasure_list.html index 2f36de71..e2154c3e 100644 --- a/ereuse_devicehub/templates/inventory/erasure_list.html +++ b/ereuse_devicehub/templates/inventory/erasure_list.html @@ -187,9 +187,9 @@ {% endif %} {{ ac.device.serial_number.upper() }} {% endif %} - {% if ac.device.my_partner.lots | length > 0 %} + {% if ac.device.get_lots_for_template() | length > 0 %}
- {% for lot in ac.device.my_partner.get_lots_for_template() %} + {% for lot in ac.device.get_lots_for_template() %} {{ lot }} {% endfor %}
From 1c82fcfa3081909e29f725b98ed5a72829e0ecdb Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 10 Mar 2023 18:34:09 +0100 Subject: [PATCH 6/9] add customer details for default if there are more than one incoming lot --- ereuse_devicehub/inventory/views.py | 22 +++++++++++++++++++-- ereuse_devicehub/resources/device/models.py | 12 +++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index 89d0bdac..57bab6d7 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -1058,9 +1058,10 @@ class ExportsView(View): erasures.append(device.privacy) return erasures - def get_costum_details(self): + def get_costum_details(self, erasures): my_data = None customer_details = None + lot = None if hasattr(g.user, 'sanitization_entity'): my_data = g.user.sanitization_entity @@ -1071,6 +1072,23 @@ class ExportsView(View): customer_details = lot.transfer.customer_details except Exception: pass + + if lot or not erasures: + return my_data, customer_details + + init = erasures[0].device.get_set_lots() + for e in erasures: + init = init.intersection(e.device.get_set_lots()) + + if len(init) != 1: + return my_data, customer_details + + lot = init.pop() + try: + customer_details = lot.transfer.customer_details + except Exception: + pass + return my_data, customer_details def get_server_erasure_hosts(self, erasures): @@ -1093,7 +1111,7 @@ class ExportsView(View): erasures[0].snapshot.version, ) - my_data, customer_details = self.get_costum_details() + my_data, customer_details = self.get_costum_details(erasures) a, b = self.get_server_erasure_hosts(erasures) erasures_host, erasures_on_server = a, b diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index 168c4371..1e3d4b12 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -1021,6 +1021,18 @@ class Device(Thing): return + def get_set_lots(self): + if self.lots: + return set(self.lots) + + if hasattr(self, "parent") and self.parent and self.parent.lots: + return set(self.parent.lots) + + if self.binding: + return self.binding.device.get_set_lots() + + return set() + def __lt__(self, other): return self.id < other.id From ba02351f59082ce526be430ecf03d41ec31982d7 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 10 Mar 2023 20:13:54 +0100 Subject: [PATCH 7/9] fix lots --- ereuse_devicehub/resources/device/models.py | 13 ++--- .../templates/inventory/erasure.html | 52 ++----------------- 2 files changed, 11 insertions(+), 54 deletions(-) diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index 1e3d4b12..3bb98ffb 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -1022,16 +1022,17 @@ class Device(Thing): return def get_set_lots(self): - if self.lots: + if hasattr(self, "orphan") and self.orphan: + if self.binding: + return set(self.binding.device.lots) return set(self.lots) - if hasattr(self, "parent") and self.parent and self.parent.lots: + if hasattr(self, "parent") and self.parent: + if self.parent.binding: + return set(self.parent.binding.device.lots) return set(self.parent.lots) - if self.binding: - return self.binding.device.get_set_lots() - - return set() + return set(self.lots) def __lt__(self, other): return self.id < other.id diff --git a/ereuse_devicehub/templates/inventory/erasure.html b/ereuse_devicehub/templates/inventory/erasure.html index 7b8ae650..a5eb0039 100644 --- a/ereuse_devicehub/templates/inventory/erasure.html +++ b/ereuse_devicehub/templates/inventory/erasure.html @@ -161,7 +161,7 @@ {% if erasure_hosts %}
+ @@ -290,51 +286,12 @@ {% for erasure in erasures %} - {% if erasure.parent == server %} - - - - {% endif %} - {% endfor %} - -
- N° of sanitization server {{ erasure_hosts|length }}: + SNs; of sanitization server {{ erasure_hosts|length }}: {% for e in erasure_hosts %} @@ -267,14 +267,9 @@ {% if erasures %} - {% if erasure_hosts %} - {% for server in erasure_hosts %}
-

Server Summary

-
-
-

SN Server {{ server.serial_number and server.serial_number.upper() }}

+

Summary

@@ -283,6 +278,7 @@
SN StorageSN Host Method Result Date
{{ erasure.device.serial_number.upper() }} - {{ erasure.get_public_name() }} - - {{ erasure.severity.get_public_name() }} - - {{ erasure.date_str }} -
-
-
- {% endfor %} - {% endif %} - {% if erasures_normal %} -
-
-

Devices Summary

-
-
-
-
- - - - - - - - - - - {% for erasure in erasures_normal %} - -
SN StorageMethodResultDate
- {{ erasure.device.serial_number.upper() }} + {{ erasure.parent.serial_number.upper() }} {{ erasure.get_public_name() }} @@ -351,7 +308,6 @@
- {% endif %}
{% for erasure in erasures %}
From cf5150b7c9d93cad2032c7753f8e7a89ba8ceb0f Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 10 Mar 2023 21:15:00 +0100 Subject: [PATCH 8/9] fix lots --- ereuse_devicehub/inventory/views.py | 38 ++++++++++++++++++----------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index 57bab6d7..91ea99cc 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -1062,35 +1062,45 @@ class ExportsView(View): my_data = None customer_details = None lot = None + if hasattr(g.user, 'sanitization_entity'): my_data = g.user.sanitization_entity - try: - if len(request.referrer.split('/lot/')) > 1: - lot_id = request.referrer.split('/lot/')[-1].split('/')[0] - lot = Lot.query.filter_by(owner=g.user).filter_by(id=lot_id).first() - customer_details = lot.transfer.customer_details - except Exception: - pass + customer_details = self.get_customer_details_from_request() - if lot or not erasures: + if not erasures or customer_details: return my_data, customer_details init = erasures[0].device.get_set_lots() for e in erasures: init = init.intersection(e.device.get_set_lots()) - if len(init) != 1: + if not len(init): return my_data, customer_details - lot = init.pop() - try: - customer_details = lot.transfer.customer_details - except Exception: - pass + lots = sorted(list(init), key=lambda x: x.created) + lots.reverse() + for lot in lots: + try: + customer_details = lot.transfer.customer_details + if customer_details: + return my_data, customer_details + except Exception: + continue return my_data, customer_details + def get_customer_details_from_request(self): + if len(request.referrer.split('/lot/')) < 2: + return + + try: + lot_id = request.referrer.split('/lot/')[-1].split('/')[0] + lot = Lot.query.filter_by(owner=g.user).filter_by(id=lot_id).first() + return lot.transfer.customer_details + except Exception: + pass + def get_server_erasure_hosts(self, erasures): erasures_host = [] erasures_on_server = [] From 498d2ec92ff66bc5ac5c608a5f5e39891a937974 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 10 Mar 2023 21:56:17 +0100 Subject: [PATCH 9/9] fix test --- ereuse_devicehub/inventory/views.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index 91ea99cc..5ebabaa5 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -1091,10 +1091,10 @@ class ExportsView(View): return my_data, customer_details def get_customer_details_from_request(self): - if len(request.referrer.split('/lot/')) < 2: - return - try: + if len(request.referrer.split('/lot/')) < 2: + return + lot_id = request.referrer.split('/lot/')[-1].split('/')[0] lot = Lot.query.filter_by(owner=g.user).filter_by(id=lot_id).first() return lot.transfer.customer_details