Compare commits
3 Commits
main
...
96-add-ser
Author | SHA1 | Date |
---|---|---|
sergio_gimenez | 915d95379c | |
sergio_gimenez | 8cb66104ca | |
sergio_gimenez | 7db879e189 |
|
@ -1,6 +1,5 @@
|
|||
DOMAIN=localhost
|
||||
# note that with DEBUG=true, logs are more verbose (include tracebacks)
|
||||
DEBUG=true
|
||||
# note that DEBUG=true make snapshot parsing more verbose
|
||||
DEMO=true
|
||||
|
||||
STATIC_ROOT=/tmp/static/
|
||||
|
|
|
@ -129,7 +129,8 @@ class Device:
|
|||
return self.uuids[0]
|
||||
|
||||
def get_lots(self):
|
||||
self.lots = [x.lot for x in DeviceLot.objects.filter(device_id=self.id)]
|
||||
self.lots = [
|
||||
x.lot for x in DeviceLot.objects.filter(device_id=self.id)]
|
||||
|
||||
@classmethod
|
||||
def get_unassigned(cls, institution, offset=0, limit=None):
|
||||
|
@ -179,7 +180,6 @@ class Device:
|
|||
count = cls.get_unassigned_count(institution)
|
||||
return devices, count
|
||||
|
||||
|
||||
@classmethod
|
||||
def get_unassigned_count(cls, institution):
|
||||
|
||||
|
@ -279,6 +279,12 @@ class Device:
|
|||
self.get_last_evidence()
|
||||
return self.last_evidence.get_manufacturer()
|
||||
|
||||
@property
|
||||
def serial_number(self):
|
||||
if not self.last_evidence:
|
||||
self.get_last_evidence()
|
||||
return self.last_evidence.get_serial_number()
|
||||
|
||||
@property
|
||||
def type(self):
|
||||
if self.last_evidence.doc['type'] == "WebSnapshot":
|
||||
|
|
|
@ -84,7 +84,7 @@
|
|||
<div class="col-lg-3 col-md-4 label">
|
||||
{% trans 'Serial Number' %}
|
||||
</div>
|
||||
<div class="col-lg-9 col-md-8">{{ object.last_evidence.doc.device.serialNumber|default:'' }}</div>
|
||||
<div class="col-lg-9 col-md-8">{{ object.serial_number|default:'' }}</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
|
|
|
@ -34,6 +34,8 @@ DEBUG = config('DEBUG', default=False, cast=bool)
|
|||
|
||||
DOMAIN = config("DOMAIN")
|
||||
assert DOMAIN not in [None, ''], "DOMAIN var is MANDATORY"
|
||||
# this var is very important, we print it
|
||||
print("DOMAIN: " + DOMAIN)
|
||||
|
||||
ALLOWED_HOSTS = config('ALLOWED_HOSTS', default=DOMAIN, cast=Csv())
|
||||
assert DOMAIN in ALLOWED_HOSTS, f"DOMAIN {DOMAIN} is not in ALLOWED_HOSTS {ALLOWED_HOSTS}"
|
||||
|
|
|
@ -18,8 +18,6 @@ deploy() {
|
|||
|
||||
if [ "${DEBUG:-}" = 'true' ]; then
|
||||
./manage.py print_settings
|
||||
else
|
||||
echo "DOMAIN: ${DOMAIN}"
|
||||
fi
|
||||
|
||||
# detect if existing deployment (TODO only works with sqlite)
|
||||
|
|
|
@ -58,6 +58,8 @@ class Command(BaseCommand):
|
|||
self.devices.append(Build(s, self.user))
|
||||
move_json(p, self.user.institution.name)
|
||||
except Exception as err:
|
||||
if settings.DEBUG:
|
||||
logger.exception("%s", err)
|
||||
snapshot_id = s.get("uuid", "")
|
||||
txt = "Could not parse snapshot: %s"
|
||||
txt = "It is not possible to parse snapshot: %s"
|
||||
logger.error(txt, snapshot_id)
|
||||
|
|
|
@ -19,14 +19,16 @@ class Annotation(models.Model):
|
|||
created = models.DateTimeField(auto_now_add=True)
|
||||
uuid = models.UUIDField()
|
||||
owner = models.ForeignKey(Institution, on_delete=models.CASCADE)
|
||||
user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True)
|
||||
user = models.ForeignKey(
|
||||
User, on_delete=models.SET_NULL, null=True, blank=True)
|
||||
type = models.SmallIntegerField(choices=Type)
|
||||
key = models.CharField(max_length=STR_EXTEND_SIZE)
|
||||
value = models.CharField(max_length=STR_EXTEND_SIZE)
|
||||
|
||||
class Meta:
|
||||
constraints = [
|
||||
models.UniqueConstraint(fields=["type", "key", "uuid"], name="unique_type_key_uuid")
|
||||
models.UniqueConstraint(
|
||||
fields=["type", "key", "uuid"], name="unique_type_key_uuid")
|
||||
]
|
||||
|
||||
|
||||
|
@ -87,7 +89,7 @@ class Evidence:
|
|||
return self.components
|
||||
|
||||
def get_manufacturer(self):
|
||||
if self.doc.get("type") == "WebSnapshot":
|
||||
if self.is_new_snapshot():
|
||||
kv = self.doc.get('kv', {})
|
||||
if len(kv) < 1:
|
||||
return ""
|
||||
|
@ -99,7 +101,7 @@ class Evidence:
|
|||
return self.dmi.manufacturer().strip()
|
||||
|
||||
def get_model(self):
|
||||
if self.doc.get("type") == "WebSnapshot":
|
||||
if self.is_new_snapshot():
|
||||
kv = self.doc.get('kv', {})
|
||||
if len(kv) < 2:
|
||||
return ""
|
||||
|
@ -122,6 +124,11 @@ class Evidence:
|
|||
return k
|
||||
return ""
|
||||
|
||||
def get_serial_number(self):
|
||||
if self.is_legacy():
|
||||
return self.doc['device']['serialNumber']
|
||||
return self.dmi.serial_number().strip()
|
||||
|
||||
@classmethod
|
||||
def get_all(cls, user):
|
||||
return Annotation.objects.filter(
|
||||
|
@ -136,3 +143,6 @@ class Evidence:
|
|||
|
||||
def is_legacy(self):
|
||||
return self.doc.get("software") != "workbench-script"
|
||||
|
||||
def is_new_snapshot(self):
|
||||
return self.doc.get("type") == "WebSnapshot"
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import logging
|
||||
from django.conf import settings
|
||||
|
||||
# Colors
|
||||
RED = "\033[91m"
|
||||
|
@ -25,11 +24,6 @@ class CustomFormatter(logging.Formatter):
|
|||
record.msg = self.highlight_args(record.msg, record.args, color)
|
||||
record.args = ()
|
||||
|
||||
# provide trace when DEBUG config
|
||||
if settings.DEBUG:
|
||||
import traceback
|
||||
print(traceback.format_exc())
|
||||
|
||||
return super().format(record)
|
||||
|
||||
def highlight_args(self, message, args, color):
|
||||
|
|
Loading…
Reference in New Issue