Merge pull request #432 from eReuse/bugfix/4279-pdf

Bugfix/4279 pdf
This commit is contained in:
cayop 2023-03-10 22:14:03 +01:00 committed by GitHub
commit 25794f2fb4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 97 additions and 68 deletions

View File

@ -141,6 +141,12 @@ class SanitizationEntityForm(FlaskForm):
if not is_valid: if not is_valid:
return False 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 return True
def save(self, commit=True): def save(self, commit=True):

View File

@ -1539,7 +1539,10 @@ class CustomerDetailsForm(FlaskForm):
logo = URLField( logo = URLField(
'Logo', 'Logo',
[validators.Optional()], [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", description="Url where is the logo",
) )
@ -1558,7 +1561,17 @@ class CustomerDetailsForm(FlaskForm):
def validate(self, extra_validators=None): def validate(self, extra_validators=None):
is_valid = super().validate(extra_validators) 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): def save(self, commit=True):
self.populate_obj(self._obj) self.populate_obj(self._obj)

View File

@ -1058,20 +1058,48 @@ class ExportsView(View):
erasures.append(device.privacy) erasures.append(device.privacy)
return erasures return erasures
def get_costum_details(self): def get_costum_details(self, erasures):
my_data = None my_data = None
customer_details = None customer_details = None
lot = None
if hasattr(g.user, 'sanitization_entity'): if hasattr(g.user, 'sanitization_entity'):
my_data = g.user.sanitization_entity my_data = g.user.sanitization_entity
try: customer_details = self.get_customer_details_from_request()
if len(request.referrer.split('/lot/')) > 1:
lot_id = request.referrer.split('/lot/')[-1].split('/')[0] if not erasures or customer_details:
lot = Lot.query.filter_by(owner=g.user).filter_by(id=lot_id).first() 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 not len(init):
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 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):
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
except Exception: except Exception:
pass pass
return my_data, customer_details
def get_server_erasure_hosts(self, erasures): def get_server_erasure_hosts(self, erasures):
erasures_host = [] erasures_host = []
@ -1093,10 +1121,11 @@ class ExportsView(View):
erasures[0].snapshot.version, 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) a, b = self.get_server_erasure_hosts(erasures)
erasures_host, erasures_on_server = a, b erasures_host, erasures_on_server = a, b
erasures_host = set(erasures_host)
result = 'Success' result = 'Success'
if "Failed" in [e.severity.get_public_name() for e in erasures]: if "Failed" in [e.severity.get_public_name() for e in erasures]:
@ -1104,9 +1133,9 @@ class ExportsView(View):
erasures = sorted(erasures, key=lambda x: x.end_time) erasures = sorted(erasures, key=lambda x: x.end_time)
erasures_on_server = sorted(erasures_on_server, 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 = list(set(erasures) - set(erasures_on_server))
erasures_normal = sorted(erasures_normal, key=lambda x: x.end_time) erasures_normal = sorted(erasures_normal, key=lambda x: x.end_time)
n_computers = len({x.parent for x in erasures} - erasures_host)
params = { params = {
'title': 'Erasure Certificate', 'title': 'Erasure Certificate',
@ -1116,7 +1145,7 @@ class ExportsView(View):
'uuid_report': '{}'.format(uuid.uuid4()), 'uuid_report': '{}'.format(uuid.uuid4()),
'software': software, 'software': software,
'my_data': my_data, 'my_data': my_data,
'n_computers': len(set([x.parent for x in erasures])), 'n_computers': n_computers,
'result': result, 'result': result,
'customer_details': customer_details, 'customer_details': customer_details,
'erasure_hosts': erasures_host, 'erasure_hosts': erasures_host,

View File

@ -676,6 +676,12 @@ class Device(Thing):
return args return args
def get_lots_for_template(self): 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 = [] lots = []
for lot in self.lots: for lot in self.lots:
if lot.is_incoming: if lot.is_incoming:
@ -1015,6 +1021,19 @@ class Device(Thing):
return return
def get_set_lots(self):
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:
if self.parent.binding:
return set(self.parent.binding.device.lots)
return set(self.parent.lots)
return set(self.lots)
def __lt__(self, other): def __lt__(self, other):
return self.id < other.id return self.id < other.id

View File

@ -159,19 +159,20 @@
<table class="body_content"> <table class="body_content">
<tbody> <tbody>
{% if erasure_hosts %} {% if erasure_hosts %}
{% for e in erasure_hosts %}
<tr style="padding-top:5px;"> <tr style="padding-top:5px;">
<td style="width:20%;"> <td style="width:20%;">
<span>N&deg; of sanitization server ({{ loop.index }}/{{ erasure_hosts|length }}):</span> <span>SNs; of sanitization server {{ erasure_hosts|length }}:</span>
</td> </td>
<td style="width:80%;"> <td style="width:80%;">
{% for e in erasure_hosts %}
{% if e.serial_number %} {% if e.serial_number %}
<span>{{ e.serial_number.upper() }}</span> <span>{{ e.serial_number.upper() }}</span>{% if not loop.last %},{% endif %}
{% endif %} {% endif %}
{% endfor %}
</td> </td>
</tr> </tr>
{% endfor %} {% endif %}
{% else %} {% if n_computers %}
<tr style="padding-top:5px;"> <tr style="padding-top:5px;">
<td style="width:20%;"> <td style="width:20%;">
<span>N&deg; of computers:</span> <span>N&deg; of computers:</span>
@ -245,7 +246,7 @@
</div> </div>
</div> </div>
<div class="row" style="margin-top:225px;"> <div class="row" style="margin-top:200px;">
<div class="col-12"> <div class="col-12">
<table class="body_content" style="border-top: 1px solid #000;"> <table class="body_content" style="border-top: 1px solid #000;">
<tbody> <tbody>
@ -266,14 +267,9 @@
</div> </div>
{% if erasures %} {% if erasures %}
{% if erasure_hosts %}
{% for server in erasure_hosts %}
<div class="row mt-3 page-break"> <div class="row mt-3 page-break">
<div class="col"> <div class="col">
<h1>Server Summary</h1> <h1>Summary</h1>
</div>
<div class="col">
<h4>SN Server {{ server.serial_number and server.serial_number.upper() }}</h4>
</div> </div>
</div> </div>
<div class="row mt-3"> <div class="row mt-3">
@ -282,6 +278,7 @@
<thead style="border-bottom: 1px solid #000;"> <thead style="border-bottom: 1px solid #000;">
<tr> <tr>
<th scope="col" style="text-align: center;">SN Storage</th> <th scope="col" style="text-align: center;">SN Storage</th>
<th scope="col" style="text-align: center;">SN Host</th>
<th scope="col" style="text-align: center;">Method</th> <th scope="col" style="text-align: center;">Method</th>
<th scope="col" style="text-align: center;">Result</th> <th scope="col" style="text-align: center;">Result</th>
<th scope="col" style="text-align: center;">Date</th> <th scope="col" style="text-align: center;">Date</th>
@ -289,51 +286,12 @@
</thead> </thead>
<tbody> <tbody>
{% for erasure in erasures %} {% for erasure in erasures %}
{% if erasure.parent == server %}
<tr style="border-bottom: 1px dashed #000;"> <tr style="border-bottom: 1px dashed #000;">
<td> <td>
{{ erasure.device.serial_number.upper() }} {{ erasure.device.serial_number.upper() }}
</td> </td>
<td> <td>
{{ erasure.get_public_name() }} {{ erasure.parent.serial_number.upper() }}
</td>
<td>
{{ erasure.severity.get_public_name() }}
</td>
<td>
{{ erasure.date_str }}
</td>
</tr>
{% endif %}
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endfor %}
{% endif %}
{% if erasures_normal %}
<div class="row mt-3 page-break">
<div class="col">
<h1>Devices Summary</h1>
</div>
</div>
<div class="row mt-3">
<div class="col">
<table class="table" style="width: 100%; text-align: center;">
<thead style="border-bottom: 1px solid #000;">
<tr>
<th scope="col" style="text-align: center;">SN Storage</th>
<th scope="col" style="text-align: center;">Method</th>
<th scope="col" style="text-align: center;">Result</th>
<th scope="col" style="text-align: center;">Date</th>
</tr>
</thead>
<tbody>
{% for erasure in erasures_normal %}
<tr style="border-bottom: 1px dashed #000;">
<td>
{{ erasure.device.serial_number.upper() }}
</td> </td>
<td> <td>
{{ erasure.get_public_name() }} {{ erasure.get_public_name() }}
@ -350,7 +308,6 @@
</table> </table>
</div> </div>
</div> </div>
{% endif %}
</div> </div>
{% for erasure in erasures %} {% for erasure in erasures %}
<div class="container mb-5 page-break"> <div class="container mb-5 page-break">
@ -366,12 +323,14 @@
<dd>Hid: {{ erasure.parent.hid }}</dd> <dd>Hid: {{ erasure.parent.hid }}</dd>
<dd>Tags: {{ erasure.parent.tags }}</dd> <dd>Tags: {{ erasure.parent.tags }}</dd>
{% if erasure.device.parent %}
<dt>Computer where it resides:</dt> <dt>Computer where it resides:</dt>
<dd>Title: {{ erasure.device.parent.__format__('ts') }}</dd> <dd>Title: {{ erasure.device.parent.__format__('ts') }}</dd>
<dd>DevicehubID: {{ erasure.device.parent.dhid }}</dd> <dd>DevicehubID: {{ erasure.device.parent.dhid }}</dd>
<dd>Hid: {{ erasure.device.parent.hid }}</dd> <dd>Hid: {{ erasure.device.parent.hid }}</dd>
<dd>Tags: {{ erasure.device.parent.tags }}</dd> <dd>Tags: {{ erasure.device.parent.tags }}</dd>
{% endif %} {% endif %}
{% endif %}
<dt>Erasure:</dt> <dt>Erasure:</dt>
<dd>{{ erasure.__format__('ts') }}</dd> <dd>{{ erasure.__format__('ts') }}</dd>

View File

@ -187,9 +187,9 @@
{% endif %} {% endif %}
{{ ac.device.serial_number.upper() }} {{ ac.device.serial_number.upper() }}
{% endif %} {% endif %}
{% if ac.device.my_partner.lots | length > 0 %} {% if ac.device.get_lots_for_template() | length > 0 %}
<h6 class="d-inline"> <h6 class="d-inline">
{% for lot in ac.device.my_partner.get_lots_for_template() %} {% for lot in ac.device.get_lots_for_template() %}
<span class="badge rounded-pill bg-light text-dark">{{ lot }}</span> <span class="badge rounded-pill bg-light text-dark">{{ lot }}</span>
{% endfor %} {% endfor %}
</h6> </h6>

View File

@ -143,8 +143,11 @@ class SanitizationEntityView(View):
messages.success('Sanitization data updated successfully!') messages.success('Sanitization data updated successfully!')
else: else:
messages.error('Error modifying Sanitization data!') 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')) return flask.redirect(flask.url_for('core.user-profile'))