From 0ff2bcae92745f567da98d6cc85cba7f3da3472e Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 7 Mar 2023 16:39:52 +0100 Subject: [PATCH 01/20] use populate_obj --- ereuse_devicehub/forms.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/ereuse_devicehub/forms.py b/ereuse_devicehub/forms.py index 895160c5..495446b8 100644 --- a/ereuse_devicehub/forms.py +++ b/ereuse_devicehub/forms.py @@ -141,15 +141,17 @@ class SanitizationEntityForm(FlaskForm): return True def save(self, commit=True): - sanitation_data = SanitizationEntity( - logo=URL(self.logo.data), - company_name=self.company_name.data, - location=self.location.data, - responsable_person=self.responsable_person.data, - supervisor_person=self.supervisor_person.data, - user=g.user, - ) - db.session.add(sanitation_data) + if isinstance(self.logo.data, str): + self.logo.data = URL(self.logo.data) + + sanitation_data = SanitizationEntity.query.filter_by(user_id=g.user.id).first() + + if not sanitation_data: + sanitation_data = SanitizationEntity(user_id=g.user.id) + self.populate_obj(sanitation_data) + db.session.add(sanitation_data) + else: + self.populate_obj(sanitation_data) if commit: db.session.commit() From 7534df083cf1e8eab498dc674eaf0ba5ca1256e8 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 7 Mar 2023 16:40:45 +0100 Subject: [PATCH 02/20] fix definition of model SanitizationEntity --- ereuse_devicehub/resources/user/models.py | 29 ++++++++++++++--------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/ereuse_devicehub/resources/user/models.py b/ereuse_devicehub/resources/user/models.py index 14e1c7ad..351907a8 100644 --- a/ereuse_devicehub/resources/user/models.py +++ b/ereuse_devicehub/resources/user/models.py @@ -1,11 +1,12 @@ from uuid import uuid4 from flask import current_app as app +from flask import g from flask_login import UserMixin from sqlalchemy import BigInteger, Boolean, Column, Sequence from sqlalchemy.dialects.postgresql import UUID from sqlalchemy_utils import EmailType, PasswordType -from teal.db import URL, IntEnum +from teal.db import CASCADE_OWN, URL, IntEnum from ereuse_devicehub.db import db from ereuse_devicehub.resources.enums import SessionType @@ -122,18 +123,24 @@ class Session(Thing): class SanitizationEntity(Thing): - id = Column(BigInteger, primary_key=True) - company_name = Column(db.String, nullable=True) - location = Column(db.String, nullable=True) - logo = Column(db.String, nullable=True) - logo = Column(URL(), nullable=True) - responsable_person = Column(db.String, nullable=True) - supervisor_person = Column(db.String, nullable=True) - user_id = db.Column(db.UUID(as_uuid=True), db.ForeignKey(User.id)) + id = db.Column(BigInteger, primary_key=True) + company_name = db.Column(db.String, nullable=True) + location = db.Column(db.String, nullable=True) + # logo = db.Column(db.String, nullable=True) + logo = db.Column(URL(), nullable=True) + responsable_person = db.Column(db.String, nullable=True) + supervisor_person = db.Column(db.String, nullable=True) + user_id = db.Column( + db.UUID(as_uuid=True), + db.ForeignKey(User.id), + default=lambda: g.user.id, + ) user = db.relationship( User, - backref=db.backref('sanitization_entity', lazy=True, collection_class=set), - collection_class=set, + backref=db.backref( + 'sanitization_entity', lazy=True, uselist=False, cascade=CASCADE_OWN + ), + primaryjoin=user_id == User.id, ) def __str__(self) -> str: From eed1075771dee95a673cda90328ad93318154d9f Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 7 Mar 2023 16:41:24 +0100 Subject: [PATCH 03/20] save with commit for default --- ereuse_devicehub/views.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/ereuse_devicehub/views.py b/ereuse_devicehub/views.py index f2cd4bc1..5d3861d9 100644 --- a/ereuse_devicehub/views.py +++ b/ereuse_devicehub/views.py @@ -102,7 +102,7 @@ class UserProfileView(GenericMixin): self.get_context() sanitization_form = SanitizationEntityForm() if g.user.sanitization_entity: - sanitization = list(g.user.sanitization_entity)[0] + sanitization = g.user.sanitization_entity sanitization_form = SanitizationEntityForm(obj=sanitization) self.context.update( { @@ -138,14 +138,13 @@ class SanitizationEntityView(View): def dispatch_request(self): form = SanitizationEntityForm() - db.session.commit() if form.validate_on_submit(): - form.save(commit=False) + form.save() messages.success('Sanitization datas updated successfully!') else: messages.error('Error modifying Sanitization datas!') - db.session.commit() + # db.session.commit() return flask.redirect(flask.url_for('core.user-profile')) From ab6f89c3d2e7231c389954613fac4563d277f902 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 8 Mar 2023 10:58:28 +0100 Subject: [PATCH 04/20] fix sanitization_entity in view --- ereuse_devicehub/inventory/views.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index 835f95e6..4522c5b5 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -1062,8 +1062,7 @@ class ExportsView(View): my_data = None customer_details = None if hasattr(g.user, 'sanitization_entity'): - if g.user.sanitization_entity: - my_data = list(g.user.sanitization_entity)[0] + my_data = g.user.sanitization_entity try: if len(request.referrer.split('/lot/')) > 1: From eb945ae348264eaf44f07a1e47c971b0e676c17b Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 8 Mar 2023 12:34:52 +0100 Subject: [PATCH 05/20] fix ortigraphy --- ereuse_devicehub/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ereuse_devicehub/views.py b/ereuse_devicehub/views.py index 5d3861d9..915a4dc4 100644 --- a/ereuse_devicehub/views.py +++ b/ereuse_devicehub/views.py @@ -140,9 +140,9 @@ class SanitizationEntityView(View): form = SanitizationEntityForm() if form.validate_on_submit(): form.save() - messages.success('Sanitization datas updated successfully!') + messages.success('Sanitization data updated successfully!') else: - messages.error('Error modifying Sanitization datas!') + messages.error('Error modifying Sanitization data!') # db.session.commit() return flask.redirect(flask.url_for('core.user-profile')) From 54372ad2f90ee674d66b7749cd10525644e4b9ba Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 8 Mar 2023 12:43:37 +0100 Subject: [PATCH 06/20] put comment as placeholder in field of logo --- ereuse_devicehub/forms.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ereuse_devicehub/forms.py b/ereuse_devicehub/forms.py index 495446b8..68485f33 100644 --- a/ereuse_devicehub/forms.py +++ b/ereuse_devicehub/forms.py @@ -116,7 +116,10 @@ class SanitizationEntityForm(FlaskForm): logo = URLField( 'Logo', [validators.Optional(), validators.URL()], - render_kw={'class': "form-control"}, + render_kw={ + 'class': "form-control", + "placeholder": "Url where is the logo - acceptd only .png, .jpg, .gif, svg", + }, ) company_name = StringField('Company Name', render_kw={'class': "form-control"}) location = StringField('Location', render_kw={'class': "form-control"}) From 40a151df5a434eb3a409ead174792c593035508a Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 8 Mar 2023 17:22:26 +0100 Subject: [PATCH 07/20] fix order of devices --- ereuse_devicehub/inventory/views.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index 4522c5b5..675409b4 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -1102,6 +1102,12 @@ class ExportsView(View): if "Failed" in [e.severity.get_public_name() for e in erasures]: result = 'Failed' + 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) + erasures_normal = list(set(erasures) - set(erasures_on_server)) + erasures_normal = sorted(erasures_normal, key=lambda x: x.end_time) + params = { 'title': 'Erasure Certificate', 'erasures': tuple(erasures), @@ -1114,7 +1120,7 @@ class ExportsView(View): 'result': result, 'customer_details': customer_details, 'erasure_hosts': erasures_host, - 'erasures_normal': list(set(erasures) - set(erasures_on_server)), + 'erasures_normal': erasures_normal, } return flask.render_template('inventory/erasure.html', **params) From de24cae235a58974c755807125217ad464e6569a Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 9 Mar 2023 10:43:35 +0100 Subject: [PATCH 08/20] 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 09/20] 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 10/20] 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 11/20] 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 12/20] 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 13/20] 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 14/20] 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 15/20] 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 16/20] 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 From d0688cc75172306f0e0f036a6b43a04c68482db3 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 13 Mar 2023 12:24:57 +0100 Subject: [PATCH 17/20] fix with last lot incoming --- ereuse_devicehub/inventory/views.py | 22 ++++++++----------- ereuse_devicehub/resources/device/models.py | 20 +++++++++++------ .../templates/inventory/erasure.html | 2 +- 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index 5ebabaa5..b03cd345 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -1071,22 +1071,18 @@ class ExportsView(View): 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()) + lots = {erasures[0].device.get_last_incoming_lot()} + for e in erasures[1:]: + lots.add(e.device.get_last_incoming_lot()) - if not len(init): + if len(lots) != 1: return my_data, customer_details - 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 + lot = lots.pop() + try: + customer_details = lot.transfer.customer_details + except Exception: + pass return my_data, customer_details diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index 3bb98ffb..a0ba0f20 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -1021,18 +1021,24 @@ class Device(Thing): return - def get_set_lots(self): + def get_last_incoming_lot(self): + lots = list(self.lots) if hasattr(self, "orphan") and self.orphan: + lots = list(self.lots) if self.binding: - return set(self.binding.device.lots) - return set(self.lots) + lots = list(self.binding.device.lots) - if hasattr(self, "parent") and self.parent: + elif hasattr(self, "parent") and self.parent: + lots = list(self.parent.lots) if self.parent.binding: - return set(self.parent.binding.device.lots) - return set(self.parent.lots) + lots = list(self.parent.binding.device.lots) - return set(self.lots) + lots = sorted(lots, key=lambda x: x.created) + lots.reverse() + for lot in lots: + if lot.is_incoming: + return lot + return None 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 a5eb0039..06ad6943 100644 --- a/ereuse_devicehub/templates/inventory/erasure.html +++ b/ereuse_devicehub/templates/inventory/erasure.html @@ -161,7 +161,7 @@ {% if erasure_hosts %}
- SNs; of sanitization server {{ erasure_hosts|length }}: + SNs of sanitization server: {% for e in erasure_hosts %} From b140dc5f899be61bca36b56914d0f72320d88a17 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 13 Mar 2023 17:04:57 +0100 Subject: [PATCH 18/20] fix without logo --- ereuse_devicehub/forms.py | 3 +++ ereuse_devicehub/inventory/forms.py | 3 +++ ereuse_devicehub/views.py | 3 ++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ereuse_devicehub/forms.py b/ereuse_devicehub/forms.py index 4980b41e..ef383588 100644 --- a/ereuse_devicehub/forms.py +++ b/ereuse_devicehub/forms.py @@ -141,6 +141,9 @@ class SanitizationEntityForm(FlaskForm): if not is_valid: return False + if not self.logo.data: + return True + 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" diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index dff4e87e..ffb8d13c 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -1565,6 +1565,9 @@ class CustomerDetailsForm(FlaskForm): if not is_valid: return is_valid + if not self.logo.data: + return True + 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" diff --git a/ereuse_devicehub/views.py b/ereuse_devicehub/views.py index 65cb4d3a..8f9a5e1d 100644 --- a/ereuse_devicehub/views.py +++ b/ereuse_devicehub/views.py @@ -145,7 +145,8 @@ class SanitizationEntityView(View): messages.error('Error modifying Sanitization data!') if form.errors: for k in form.errors.keys(): - txt = "{}: {}".format(k, form.errors[k]) + errors = ", ".join(form.errors[k]) + txt = "{}: {}".format(k, errors) messages.error(txt) return flask.redirect(flask.url_for('core.user-profile')) From 21d251e6c03008b878af45dc549d445ba86b576a Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 13 Mar 2023 17:52:00 +0100 Subject: [PATCH 19/20] add reopen transfer --- ereuse_devicehub/inventory/views.py | 19 +++++++++++++++ .../templates/inventory/device_list.html | 23 +++++++++++++------ 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index b03cd345..2526a850 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -841,6 +841,21 @@ class NewTransferView(GenericMixin): return flask.render_template(self.template_name, **self.context) +class OpenTransferView(GenericMixin): + methods = ['GET'] + + def dispatch_request(self, lot_id=None): + lot = Lot.query.filter_by(id=lot_id).one() + next_url = url_for('inventory.lotdevicelist', lot_id=str(lot_id)) + + if hasattr(lot, 'transfer'): + lot.transfer.date = None + db.session.commit() + messages.success('Transfer was reopen successfully!') + + return flask.redirect(next_url) + + class EditTransferView(GenericMixin): methods = ['POST'] form_class = EditTransferForm @@ -1601,3 +1616,7 @@ devices.add_url_rule( '/device/erasure//', view_func=ErasureListView.as_view('device_erasure_list_orphans'), ) +devices.add_url_rule( + '/lot//opentransfer/', + view_func=OpenTransferView.as_view('open_transfer'), +) diff --git a/ereuse_devicehub/templates/inventory/device_list.html b/ereuse_devicehub/templates/inventory/device_list.html index f89c93f6..7f5ac904 100644 --- a/ereuse_devicehub/templates/inventory/device_list.html +++ b/ereuse_devicehub/templates/inventory/device_list.html @@ -516,13 +516,13 @@ {% if lot and not lot.is_temporary %}
- +
Documents
@@ -565,6 +565,15 @@
+ {% if form_transfer.date.data %} + + {% endif %}
Transfer
{{ form_transfer.csrf_token }} From e7833c17275f4cf0b797b21d3045d0db4ab500d2 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 13 Mar 2023 17:59:08 +0100 Subject: [PATCH 20/20] fix test --- tests/test_basic.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_basic.py b/tests/test_basic.py index e9927a0e..4b734079 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -68,6 +68,7 @@ def test_api_docs(client: Client): '/inventory/lot/{lot_id}/receivernote/', '/inventory/lot/{lot_id}/trade-document/add/', '/inventory/lot/{lot_id}/transfer/{type_id}/', + '/inventory/lot/{lot_id}/opentransfer/', '/inventory/lot/{lot_id}/transfer/', '/inventory/lot/transfer/{type_id}/', '/inventory/lot/{lot_id}/upload-snapshot/',