Compare commits

..

3 Commits

4 changed files with 31 additions and 51 deletions

View File

@ -33,13 +33,21 @@ class UploadForm(forms.Form):
exist_annotation = Annotation.objects.filter(
uuid=file_json['uuid']
).first()
if exist_annotation:
raise ValidationError("error: {} exist".format(file_name))
except Exception:
raise ValidationError("error in: {}".format(file_name))
raise ValidationError(
_("The snapshot already exists"),
code="duplicate_snapshot",
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))
return True

View File

@ -56,14 +56,14 @@ class Command(BaseCommand):
except json.JSONDecodeError as 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:
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
except Exception as 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):
for s, p in self.snapshots:

View File

@ -22,8 +22,10 @@ def get_mac(lshw):
except json.decoder.JSONDecodeError:
hw = json.loads(repair_json(lshw))
networks = []
get_lshw_child(hw, networks, 'network')
nets = []
get_lshw_child(hw, nets, 'network')
nets_sorted = sorted(nets, key=lambda x: x['businfo'])
if nets_sorted:
mac = nets_sorted[0]['serial']
@ -31,36 +33,6 @@ def get_mac(lshw):
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:
def __init__(self, evidence_json, user, check=False):

View File

@ -13,18 +13,18 @@
{% csrf_token %}
{% if form.errors %}
<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="message">
{% for field, error in form.errors.items %}
{{ error }}<br />
{% endfor %}
<button class="btn-close" type="button" data-dismiss="alert" aria-label="Close"></button>
<div class="icon"><span class="mdi mdi-close-circle-o"></span></div>
<div class="message">
{% for error in form.non_field_errors %}
{{ error }}<br />
{% endfor %}
<button class="btn-close" type="button" data-dismiss="alert" aria-label="Close"></button>
</div>
</div>
</div>
{% endif %}
{% bootstrap_form form %}
<div class="form-actions-no-box">
<a class="btn btn-grey" href="{% url 'dashboard:unassigned_devices' %}">{% translate "Cancel" %}</a>
{% bootstrap_form form alert_error_type="fields" %}
<div class="form-actions-no-box">
<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' %}" />
</div>