Compare commits

..

3 Commits

4 changed files with 31 additions and 51 deletions

View File

@ -35,11 +35,19 @@ class UploadForm(forms.Form):
).first() ).first()
if exist_annotation: if exist_annotation:
raise ValidationError("error: {} exist".format(file_name)) raise ValidationError(
_("The snapshot already exists"),
except Exception: code="duplicate_snapshot",
raise ValidationError("error in: {}".format(file_name)) params={"file_name": file_name},
)
#Caught any error and display it as Validation Error so the Form handles it
except Exception as e:
raise ValidationError(
_("Error on '%(file_name)s': %(error)s"),
code="error",
params={"file_name": file_name, "error": getattr(e, 'message', str(e))},
)
self.evidences.append((file_name, file_json)) self.evidences.append((file_name, file_json))
return True return True

View File

@ -56,14 +56,14 @@ class Command(BaseCommand):
except json.JSONDecodeError as e: except json.JSONDecodeError as e:
logger.error("JSON decode error in file %s: %s", filepath, e) logger.error("JSON decode error in file %s: %s", filepath, e)
raise ValueError(f"Invalid JSON format in file {filepath}") from e raise ValueError(f"Invalid JSON format in file. Check for file integrity.") from e
except FileNotFoundError as e: except FileNotFoundError as e:
logger.error("File not found: %s", filepath) logger.error("File not found: %s", filepath)
raise FileNotFoundError(f"File not found: {filepath}") from e raise FileNotFoundError(f"File not found") from e
#or we cath'em all #or we cath'em all
except Exception as e: except Exception as e:
logger.exception("Unexpected error when opening file %s: %s", filepath, e) logger.exception("Unexpected error when opening file %s: %s", filepath, e)
raise Exception(f"Unexpected error when opening file {filepath}") from e raise Exception(f"Unexpected error when opening file") from e
def parsing(self): def parsing(self):
for s, p in self.snapshots: for s, p in self.snapshots:

View File

@ -22,8 +22,10 @@ def get_mac(lshw):
except json.decoder.JSONDecodeError: except json.decoder.JSONDecodeError:
hw = json.loads(repair_json(lshw)) hw = json.loads(repair_json(lshw))
networks = [] nets = []
get_lshw_child(hw, networks, 'network') get_lshw_child(hw, nets, 'network')
nets_sorted = sorted(nets, key=lambda x: x['businfo'])
if nets_sorted: if nets_sorted:
mac = nets_sorted[0]['serial'] mac = nets_sorted[0]['serial']
@ -31,36 +33,6 @@ def get_mac(lshw):
return mac return mac
def get_network_cards(child, nets):
if child['id'] == 'network' and "PCI:" in child.get("businfo"):
nets.append(child)
if child.get('children'):
[get_network_cards(x, nets) for x in child['children']]
def get_mac(lshw):
nets = []
try:
if type(lshw) is dict:
hw = lshw
else:
hw = json.loads(lshw)
except json.decoder.JSONDecodeError:
hw = json.loads(repair_json(lshw))
try:
get_network_cards(hw, nets)
except Exception as ss:
logger.warning("%s", ss)
return
nets_sorted = sorted(nets, key=lambda x: x['businfo'])
# This funcion get the network card integrated in motherboard
# integrate = [x for x in nets if "pci@0000:00:" in x.get('businfo', '')]
if nets_sorted:
return nets_sorted[0]['serial']
class Build: class Build:
def __init__(self, evidence_json, user, check=False): def __init__(self, evidence_json, user, check=False):

View File

@ -13,18 +13,18 @@
{% csrf_token %} {% csrf_token %}
{% if form.errors %} {% if form.errors %}
<div class="alert alert-danger alert-icon alert-icon-border alert-dismissible" role="alert"> <div class="alert alert-danger alert-icon alert-icon-border alert-dismissible" role="alert">
<div class="icon"><span class="mdi mdi-close-circle-o"></span></div> <div class="icon"><span class="mdi mdi-close-circle-o"></span></div>
<div class="message"> <div class="message">
{% for field, error in form.errors.items %} {% for error in form.non_field_errors %}
{{ error }}<br /> {{ error }}<br />
{% endfor %} {% endfor %}
<button class="btn-close" type="button" data-dismiss="alert" aria-label="Close"></button> <button class="btn-close" type="button" data-dismiss="alert" aria-label="Close"></button>
</div>
</div> </div>
</div>
{% endif %} {% endif %}
{% bootstrap_form form %} {% bootstrap_form form alert_error_type="fields" %}
<div class="form-actions-no-box"> <div class="form-actions-no-box">
<a class="btn btn-grey" href="{% url 'dashboard:unassigned_devices' %}">{% translate "Cancel" %}</a> <a class="btn btn-grey" href="{% url 'dashboard:unassigned_devices' %}">{% translate "Cancel" %}</a>
<input class="btn btn-green-admin" type="submit" name="submit" value="{% translate 'Save' %}" /> <input class="btn btn-green-admin" type="submit" name="submit" value="{% translate 'Save' %}" />
</div> </div>