commit
25794f2fb4
|
@ -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):
|
||||
|
|
|
@ -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",
|
||||
)
|
||||
|
||||
|
@ -1558,8 +1561,18 @@ class CustomerDetailsForm(FlaskForm):
|
|||
|
||||
def validate(self, extra_validators=None):
|
||||
is_valid = super().validate(extra_validators)
|
||||
|
||||
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)
|
||||
self._obj.logo = URL(self._obj.logo)
|
||||
|
|
|
@ -1058,20 +1058,48 @@ 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
|
||||
|
||||
customer_details = self.get_customer_details_from_request()
|
||||
|
||||
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 not len(init):
|
||||
return my_data, customer_details
|
||||
|
||||
lots = sorted(list(init), key=lambda x: x.created)
|
||||
lots.reverse()
|
||||
for lot in lots:
|
||||
try:
|
||||
if len(request.referrer.split('/lot/')) > 1:
|
||||
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()
|
||||
customer_details = lot.transfer.customer_details
|
||||
return lot.transfer.customer_details
|
||||
except Exception:
|
||||
pass
|
||||
return my_data, customer_details
|
||||
|
||||
def get_server_erasure_hosts(self, erasures):
|
||||
erasures_host = []
|
||||
|
@ -1093,10 +1121,11 @@ 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
|
||||
erasures_host = set(erasures_host)
|
||||
|
||||
result = 'Success'
|
||||
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_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)
|
||||
n_computers = len({x.parent for x in erasures} - erasures_host)
|
||||
|
||||
params = {
|
||||
'title': 'Erasure Certificate',
|
||||
|
@ -1116,7 +1145,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,
|
||||
|
|
|
@ -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:
|
||||
|
@ -1015,6 +1021,19 @@ class Device(Thing):
|
|||
|
||||
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):
|
||||
return self.id < other.id
|
||||
|
||||
|
|
|
@ -159,19 +159,20 @@
|
|||
<table class="body_content">
|
||||
<tbody>
|
||||
{% if erasure_hosts %}
|
||||
{% for e in erasure_hosts %}
|
||||
<tr style="padding-top:5px;">
|
||||
<td style="width:20%;">
|
||||
<span>N° of sanitization server ({{ loop.index }}/{{ erasure_hosts|length }}):</span>
|
||||
<span>SNs; of sanitization server {{ erasure_hosts|length }}:</span>
|
||||
</td>
|
||||
<td style="width:80%;">
|
||||
{% for e in erasure_hosts %}
|
||||
{% if e.serial_number %}
|
||||
<span>{{ e.serial_number.upper() }}</span>
|
||||
<span>{{ e.serial_number.upper() }}</span>{% if not loop.last %},{% endif %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
{% endif %}
|
||||
{% if n_computers %}
|
||||
<tr style="padding-top:5px;">
|
||||
<td style="width:20%;">
|
||||
<span>N° of computers:</span>
|
||||
|
@ -245,7 +246,7 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row" style="margin-top:225px;">
|
||||
<div class="row" style="margin-top:200px;">
|
||||
<div class="col-12">
|
||||
<table class="body_content" style="border-top: 1px solid #000;">
|
||||
<tbody>
|
||||
|
@ -266,14 +267,9 @@
|
|||
</div>
|
||||
|
||||
{% if erasures %}
|
||||
{% if erasure_hosts %}
|
||||
{% for server in erasure_hosts %}
|
||||
<div class="row mt-3 page-break">
|
||||
<div class="col">
|
||||
<h1>Server Summary</h1>
|
||||
</div>
|
||||
<div class="col">
|
||||
<h4>SN Server {{ server.serial_number and server.serial_number.upper() }}</h4>
|
||||
<h1>Summary</h1>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mt-3">
|
||||
|
@ -282,6 +278,7 @@
|
|||
<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;">SN Host</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>
|
||||
|
@ -289,51 +286,12 @@
|
|||
</thead>
|
||||
<tbody>
|
||||
{% for erasure in erasures %}
|
||||
{% if erasure.parent == server %}
|
||||
<tr style="border-bottom: 1px dashed #000;">
|
||||
<td>
|
||||
{{ erasure.device.serial_number.upper() }}
|
||||
</td>
|
||||
<td>
|
||||
{{ erasure.get_public_name() }}
|
||||
</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() }}
|
||||
{{ erasure.parent.serial_number.upper() }}
|
||||
</td>
|
||||
<td>
|
||||
{{ erasure.get_public_name() }}
|
||||
|
@ -350,7 +308,6 @@
|
|||
</table>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% for erasure in erasures %}
|
||||
<div class="container mb-5 page-break">
|
||||
|
@ -366,12 +323,14 @@
|
|||
<dd>Hid: {{ erasure.parent.hid }}</dd>
|
||||
<dd>Tags: {{ erasure.parent.tags }}</dd>
|
||||
|
||||
{% if erasure.device.parent %}
|
||||
<dt>Computer where it resides:</dt>
|
||||
<dd>Title: {{ erasure.device.parent.__format__('ts') }}</dd>
|
||||
<dd>DevicehubID: {{ erasure.device.parent.dhid }}</dd>
|
||||
<dd>Hid: {{ erasure.device.parent.hid }}</dd>
|
||||
<dd>Tags: {{ erasure.device.parent.tags }}</dd>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
<dt>Erasure:</dt>
|
||||
<dd>{{ erasure.__format__('ts') }}</dd>
|
||||
|
|
|
@ -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 %}
|
||||
<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>
|
||||
{% endfor %}
|
||||
</h6>
|
||||
|
|
|
@ -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'))
|
||||
|
||||
|
||||
|
|
Reference in New Issue