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 @@