id internal when create a new placeholder, wbform

This commit is contained in:
Cayo Puigdefabregas 2022-10-05 09:18:42 +02:00
parent 02f394d81e
commit 120646289c
4 changed files with 32 additions and 54 deletions

View file

@ -322,7 +322,7 @@ class NewDeviceForm(FlaskForm):
default=1, default=1,
) )
id_device_supplier = StringField('Id Supplier', [validators.Optional()]) id_device_supplier = StringField('Id Supplier', [validators.Optional()])
phid = StringField('Placeholder Hardware identity (Phid)', [validators.Optional()]) id_device_internal = StringField('Id Internal', [validators.Optional()])
pallet = StringField('Identity of pallet', [validators.Optional()]) pallet = StringField('Identity of pallet', [validators.Optional()])
components = TextAreaField('Components', [validators.Optional()]) components = TextAreaField('Components', [validators.Optional()])
info = TextAreaField('Info', [validators.Optional()]) info = TextAreaField('Info', [validators.Optional()])
@ -382,7 +382,7 @@ class NewDeviceForm(FlaskForm):
self.type.data = self._obj.type self.type.data = self._obj.type
self.amount.render_kw = disabled self.amount.render_kw = disabled
self.id_device_supplier.data = self._obj.placeholder.id_device_supplier self.id_device_supplier.data = self._obj.placeholder.id_device_supplier
self.phid.data = self._obj.placeholder.phid self.id_device_internal.data = self._obj.placeholder.id_device_internal
self.pallet.data = self._obj.placeholder.pallet self.pallet.data = self._obj.placeholder.pallet
self.info.data = self._obj.placeholder.info self.info.data = self._obj.placeholder.info
self.components.data = self._obj.placeholder.components self.components.data = self._obj.placeholder.components
@ -411,7 +411,7 @@ class NewDeviceForm(FlaskForm):
if self._obj.placeholder.is_abstract: if self._obj.placeholder.is_abstract:
self.type.render_kw = disabled self.type.render_kw = disabled
self.amount.render_kw = disabled self.amount.render_kw = disabled
self.id_device_supplier.render_kw = disabled # self.id_device_supplier.render_kw = disabled
self.pallet.render_kw = disabled self.pallet.render_kw = disabled
self.info.render_kw = disabled self.info.render_kw = disabled
self.components.render_kw = disabled self.components.render_kw = disabled
@ -476,41 +476,11 @@ class NewDeviceForm(FlaskForm):
self.meid.errors = error self.meid.errors = error
is_valid = False is_valid = False
if self.phid.data and self.amount.data == 1 and not self._obj:
dev = Placeholder.query.filter(
Placeholder.phid == self.phid.data, Placeholder.owner == g.user
).first()
if dev:
msg = "Error, exist one Placeholder device with this PHID"
self.phid.errors = [msg]
is_valid = False
if (
self.phid.data
and self._obj
and self.phid.data != self._obj.placeholder.phid
):
dev = Placeholder.query.filter(
Placeholder.phid == self.phid.data, Device.owner == g.user
).first()
if dev:
msg = "Error, exist one Placeholder device with this PHID"
self.phid.errors = [msg]
is_valid = False
if not is_valid: if not is_valid:
return False return False
if self.image.data == '': if self.image.data == '':
self.image.data = None self.image.data = None
if self.manufacturer.data:
self.manufacturer.data = self.manufacturer.data.lower()
if self.model.data:
self.model.data = self.model.data.lower()
if self.serial_number.data:
self.serial_number.data = self.serial_number.data.lower()
if self.part_number.data:
self.part_number.data = self.part_number.data.lower()
return True return True
@ -579,8 +549,9 @@ class NewDeviceForm(FlaskForm):
def reset_ids(self): def reset_ids(self):
if self.amount.data > 1: if self.amount.data > 1:
self.phid.data = None # self.phid.data = None
self.id_device_supplier.data = None self.id_device_supplier.data = None
self.id_device_internal.data = None
self.serial_number.data = None self.serial_number.data = None
self.part_number.data = None self.part_number.data = None
self.sku.data = None self.sku.data = None
@ -590,8 +561,9 @@ class NewDeviceForm(FlaskForm):
def get_placeholder(self): def get_placeholder(self):
self.placeholder = Placeholder( self.placeholder = Placeholder(
**{ **{
'phid': self.phid.data or None, # 'phid': self.phid.data or None,
'id_device_supplier': self.id_device_supplier.data, 'id_device_supplier': self.id_device_supplier.data,
'id_device_internal': self.id_device_internal.data,
'info': self.info.data, 'info': self.info.data,
'components': self.components.data, 'components': self.components.data,
'pallet': self.pallet.data, 'pallet': self.pallet.data,
@ -601,11 +573,13 @@ class NewDeviceForm(FlaskForm):
return self.placeholder return self.placeholder
def edit_device(self): def edit_device(self):
self._obj.placeholder.phid = self.phid.data or self._obj.placeholder.phid
if not self._obj.placeholder.is_abstract: if not self._obj.placeholder.is_abstract:
self._obj.placeholder.id_device_supplier = ( self._obj.placeholder.id_device_supplier = (
self.id_device_supplier.data or None self.id_device_supplier.data or None
) )
self._obj.placeholder.id_device_internal = (
self.id_device_internal.data or None
)
self._obj.placeholder.info = self.info.data or None self._obj.placeholder.info = self.info.data or None
self._obj.placeholder.components = self.components.data or None self._obj.placeholder.components = self.components.data or None
self._obj.placeholder.pallet = self.pallet.data or None self._obj.placeholder.pallet = self.pallet.data or None
@ -1567,10 +1541,10 @@ class UploadPlaceholderForm(FlaskForm):
if placeholder: if placeholder:
self.dev_update += 1 self.dev_update += 1
device = placeholder.device device = placeholder.device
device.model = "{}".format(data['Model'][i]).lower() device.model = "{}".format(data['Model'][i])
device.manufacturer = "{}".format(data['Manufacturer'][i]).lower() device.manufacturer = "{}".format(data['Manufacturer'][i])
device.serial_number = "{}".format(data['Serial Number'][i]).lower() device.serial_number = "{}".format(data['Serial Number'][i])
device.part_number = "{}".format(data['Part Number'][i]).lower() device.part_number = "{}".format(data['Part Number'][i])
placeholder.id_device_supplier = "{}".format( placeholder.id_device_supplier = "{}".format(
data['Id device Supplier'][i] data['Id device Supplier'][i]
) )

View file

@ -545,7 +545,7 @@ class DeviceCreateView(GenericMixin):
tpy = form.type.data tpy = form.type.data
txt = f'{amount} placeholders Device "{tpy}" created successfully.' txt = f'{amount} placeholders Device "{tpy}" created successfully.'
placeholder = ( placeholder = (
Placeholder.query.filter_by(owner=g.user) Placeholder.query.filter(Placeholder.owner == g.user)
.order_by(Placeholder.id.desc()) .order_by(Placeholder.id.desc())
.first() .first()
) )

View file

@ -29,14 +29,18 @@ function amountInputs() {
if ($("#amount").val() > 1) { if ($("#amount").val() > 1) {
$("#Phid").hide(); $("#Phid").hide();
$("#Id_device_supplier").hide(); $("#Id_device_supplier").hide();
$("#Id_device_internal").hide();
$("#Serial_number").hide(); $("#Serial_number").hide();
$("#Part_number").hide();
$("#Sku").hide(); $("#Sku").hide();
$("#imei").hide(); $("#imei").hide();
$("#meid").hide(); $("#meid").hide();
} else { } else {
$("#Phid").show(); $("#Phid").show();
$("#Id_device_supplier").show(); $("#Id_device_supplier").show();
$("#Id_device_internal").show();
$("#Serial_number").show(); $("#Serial_number").show();
$("#Part_number").show();
$("#Sku").show(); $("#Sku").show();
deviceInputs(); deviceInputs();
}; };

View file

@ -90,19 +90,6 @@
{% endif %} {% endif %}
</div> </div>
<div class="form-group mb-2" id="Phid">
<label for="label" class="form-label">{{ form.phid.label }}</label>
{{ form.phid(class_="form-control") }}
<small class="text-muted form-text">Label that you want link to this device</small>
{% if form.phid.errors %}
<p class="text-danger">
{% for error in form.phid.errors %}
{{ error }}<br/>
{% endfor %}
</p>
{% endif %}
</div>
<div class="form-group mb-2" id="Id_device_supplier"> <div class="form-group mb-2" id="Id_device_supplier">
<label for="label" class="form-label">{{ form.id_device_supplier.label }}</label> <label for="label" class="form-label">{{ form.id_device_supplier.label }}</label>
{{ form.id_device_supplier(class_="form-control") }} {{ form.id_device_supplier(class_="form-control") }}
@ -116,6 +103,19 @@
{% endif %} {% endif %}
</div> </div>
<div class="form-group mb-2" id="Id_device_internal">
<label for="label" class="form-label">{{ form.id_device_internal.label }}</label>
{{ form.id_device_internal(class_="form-control") }}
<small class="text-muted form-text">Identity of device for the internal</small>
{% if form.id_device_internal.errors %}
<p class="text-danger">
{% for error in form.id_device_internal.errors %}
{{ error }}<br/>
{% endfor %}
</p>
{% endif %}
</div>
<div class="form-group mb-2"> <div class="form-group mb-2">
<label for="label" class="form-label">{{ form.pallet.label }}</label> <label for="label" class="form-label">{{ form.pallet.label }}</label>
{{ form.pallet(class_="form-control") }} {{ form.pallet(class_="form-control") }}