From 57882ca2c5e60e4d59bb63e366ba4fbec4f408c2 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 12 Jun 2023 18:47:55 +0200 Subject: [PATCH] add placeholder datastorage --- ereuse_devicehub/inventory/forms.py | 17 +++++++++++++---- .../templates/inventory/erasure.html | 4 ++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index 0d644565..22666a3a 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -402,7 +402,7 @@ class NewDeviceForm(FlaskForm): sku = StringField('SKU', [validators.Optional()]) image = URLField('Image', [validators.Optional(), validators.URL()]) imei = IntegerField('IMEI', [validators.Optional()]) - data_storage_size = IntegerField('Storage Size', [validators.Optional()]) + data_storage_size = FloatField('Storage Size', [validators.Optional()]) meid = StringField('MEID', [validators.Optional()]) resolution = IntegerField('Resolution width', [validators.Optional()]) screen = FloatField('Screen size', [validators.Optional()]) @@ -435,7 +435,7 @@ class NewDeviceForm(FlaskForm): "Other": Other, } - def reset_from_obj(self): + def reset_from_obj(self): # noqa: C901 if not self._obj: return disabled = {'disabled': "disabled"} @@ -476,6 +476,9 @@ class NewDeviceForm(FlaskForm): if self._obj.type == 'ComputerMonitor': self.resolution.data = self._obj.resolution_width self.screen.data = self._obj.size + if self._obj.type in ['HardDrive', 'SolidStateDrive']: + if self._obj.size: + self.data_storage_size.data = self._obj.size / 1000 if self._obj.placeholder.is_abstract: self.type.render_kw = disabled @@ -501,6 +504,8 @@ class NewDeviceForm(FlaskForm): self.imei.render_kw = disabled self.meid.render_kw = disabled self.data_storage_size.render_kw = disabled + if self._obj.type in ['HardDrive', 'SolidStateDrive']: + self.data_storage_size.render_kw = disabled if self._obj.type == 'ComputerMonitor': self.resolution.render_kw = disabled self.screen.render_kw = disabled @@ -570,7 +575,6 @@ class NewDeviceForm(FlaskForm): if commit: db.session.commit() - # import pdb; pdb.set_trace() def create_device(self): schema = SnapshotSchema() @@ -617,7 +621,8 @@ class NewDeviceForm(FlaskForm): device.data_storage_size = self.data_storage_size.data if self.type.data in ['HardDrive', 'SolidStateDrive']: - device.data_storage_size = self.data_storage_size.data + if self.data_storage_size.data: + self._obj.size = self.data_storage_size.data * 1000 device.image = URL(self.image.data) @@ -688,6 +693,10 @@ class NewDeviceForm(FlaskForm): self._obj.meid = self.meid.data self._obj.data_storage_size = self.data_storage_size.data + if self.type.data in ['HardDrive', 'SolidStateDrive']: + if self.data_storage_size.data: + self._obj.size = self.data_storage_size.data * 1000 + if ( self.appearance.data and self.appearance.data != self._obj.appearance().name diff --git a/ereuse_devicehub/templates/inventory/erasure.html b/ereuse_devicehub/templates/inventory/erasure.html index 15ed5db6..73d201a9 100644 --- a/ereuse_devicehub/templates/inventory/erasure.html +++ b/ereuse_devicehub/templates/inventory/erasure.html @@ -334,7 +334,7 @@ {% if erasure.device.is_mobile() %} - {{ (erasure.device.imei or '') }} + IMEI:{{ (erasure.device.imei or '') }} @@ -376,7 +376,7 @@
Model: {{ erasure.device.model }}
IMEI: {{ (erasure.device.imei or '') }}
DHID: {{ erasure.device.dhid }}
-
Size: {{ erasure.device.get_size() or '' }}
+
Size: {{ erasure.device.get_size() or '?' }} GB
{% else %}

{{ (erasure.device.serial_number or '').upper() }}