allow edit only phid on abstrac devices

This commit is contained in:
Cayo Puigdefabregas 2022-08-05 16:17:19 +02:00
parent 5d81db5b8c
commit ded8a23075
1 changed files with 64 additions and 30 deletions

View File

@ -414,6 +414,34 @@ class NewDeviceForm(FlaskForm):
self.resolution.data = self._obj.resolution_width
self.screen.data = self._obj.size
if self._obj.placeholder.is_abstract:
self.type.render_kw = disabled
self.amount.render_kw = disabled
self.id_device_supplier.render_kw = disabled
self.pallet.render_kw = disabled
self.info.render_kw = disabled
self.serial_number.render_kw = disabled
self.model.render_kw = disabled
self.manufacturer.render_kw = disabled
self.appearance.render_kw = disabled
self.functionality.render_kw = disabled
self.brand.render_kw = disabled
self.generation.render_kw = disabled
self.version.render_kw = disabled
self.weight.render_kw = disabled
self.width.render_kw = disabled
self.height.render_kw = disabled
self.depth.render_kw = disabled
self.variant.render_kw = disabled
self.sku.render_kw = disabled
self.image.render_kw = disabled
if self._obj.type in ['Smartphone', 'Tablet', 'Cellphone']:
self.imei.render_kw = disabled
self.meid.render_kw = disabled
if self._obj.type == 'ComputerMonitor':
self.resolution.render_kw = disabled
self.screen.render_kw = disabled
def validate(self, extra_validators=None): # noqa: C901
error = ["Not a correct value"]
is_valid = super().validate(extra_validators)
@ -575,40 +603,46 @@ class NewDeviceForm(FlaskForm):
def edit_device(self):
self._obj.placeholder.phid = self.phid.data or self._obj.placeholder.phid
self._obj.placeholder.id_device_supplier = self.id_device_supplier.data or None
self._obj.placeholder.info = self.info.data or None
self._obj.placeholder.pallet = self.pallet.data or None
self._obj.placeholder.is_abstract = False
self._obj.model = self.model.data
self._obj.manufacturer = self.manufacturer.data
self._obj.serial_number = self.serial_number.data
self._obj.brand = self.brand.data
self._obj.version = self.version.data
self._obj.generation = self.generation.data
self._obj.sku = self.sku.data
self._obj.weight = self.weight.data
self._obj.width = self.width.data
self._obj.height = self.height.data
self._obj.depth = self.depth.data
self._obj.variant = self.variant.data
self._obj.image = self.image.data
if not self._obj.placeholder.is_abstract:
self._obj.placeholder.id_device_supplier = (
self.id_device_supplier.data or None
)
self._obj.placeholder.info = self.info.data or None
self._obj.placeholder.pallet = self.pallet.data or None
self._obj.model = self.model.data
self._obj.manufacturer = self.manufacturer.data
self._obj.serial_number = self.serial_number.data
self._obj.brand = self.brand.data
self._obj.version = self.version.data
self._obj.generation = self.generation.data
self._obj.sku = self.sku.data
self._obj.weight = self.weight.data
self._obj.width = self.width.data
self._obj.height = self.height.data
self._obj.depth = self.depth.data
self._obj.variant = self.variant.data
self._obj.image = self.image.data
if self._obj.type == 'ComputerMonitor':
self._obj.resolution_width = self.resolution.data
self._obj.size = self.screen.data
if self._obj.type == 'ComputerMonitor':
self._obj.resolution_width = self.resolution.data
self._obj.size = self.screen.data
if self._obj.type in ['Smartphone', 'Tablet', 'Cellphone']:
self._obj.imei = self.imei.data
self._obj.meid = self.meid.data
if self._obj.type in ['Smartphone', 'Tablet', 'Cellphone']:
self._obj.imei = self.imei.data
self._obj.meid = self.meid.data
if self.appearance.data and self.appearance.data != self._obj.appearance().name:
self._obj.set_appearance(self.appearance.data)
if (
self.appearance.data
and self.appearance.data != self._obj.appearance().name
):
self._obj.set_appearance(self.appearance.data)
if (
self.functionality.data
and self.functionality.data != self._obj.functionality().name
):
self._obj.set_functionality(self.functionality.data)
if (
self.functionality.data
and self.functionality.data != self._obj.functionality().name
):
self._obj.set_functionality(self.functionality.data)
placeholder_log = PlaceholdersLog(
type="Update", source='Web form', placeholder=self._obj.placeholder
)