drop phid from UploadPlaceholderForm and drop update placeholder form this form

This commit is contained in:
Cayo Puigdefabregas 2022-10-05 09:49:15 +02:00
parent 926f65e291
commit 77d10661b3
1 changed files with 4 additions and 34 deletions

View File

@ -549,7 +549,6 @@ 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.id_device_supplier.data = None self.id_device_supplier.data = None
self.id_device_internal.data = None self.id_device_internal.data = None
self.serial_number.data = None self.serial_number.data = None
@ -561,7 +560,6 @@ class NewDeviceForm(FlaskForm):
def get_placeholder(self): def get_placeholder(self):
self.placeholder = Placeholder( self.placeholder = Placeholder(
**{ **{
# '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, 'id_device_internal': self.id_device_internal.data,
'info': self.info.data, 'info': self.info.data,
@ -1488,9 +1486,7 @@ class UploadPlaceholderForm(FlaskForm):
else: else:
self.source = "Excel File: {}".format(_file.filename) self.source = "Excel File: {}".format(_file.filename)
try: try:
data = ( data = pd.read_excel(_file).fillna('').to_dict()
pd.read_excel(_file, converters={'Phid': str}).fillna('').to_dict()
)
except ValueError: except ValueError:
txt = ["File don't have a correct format"] txt = ["File don't have a correct format"]
self.placeholder_file.errors = txt self.placeholder_file.errors = txt
@ -1512,12 +1508,12 @@ class UploadPlaceholderForm(FlaskForm):
return False return False
header = [ header = [
'Phid',
'Model', 'Model',
'Manufacturer', 'Manufacturer',
'Serial Number', 'Serial Number',
'Part Number', 'Part Number',
'Id device Supplier', 'Id device Supplier',
'Id device Internal',
'Pallet', 'Pallet',
'Info', 'Info',
] ]
@ -1531,32 +1527,7 @@ class UploadPlaceholderForm(FlaskForm):
self.placeholders = [] self.placeholders = []
schema = SnapshotSchema() schema = SnapshotSchema()
self.path_snapshots = {} self.path_snapshots = {}
for i in data['Phid'].keys(): for i in data['Model'].keys():
placeholder = None
data['Phid'][i] = str(data['Phid'][i])
if data['Phid'][i]:
placeholder = Placeholder.query.filter_by(phid=data['Phid'][i]).first()
# update one
if placeholder:
self.dev_update += 1
device = placeholder.device
device.model = "{}".format(data['Model'][i])
device.manufacturer = "{}".format(data['Manufacturer'][i])
device.serial_number = "{}".format(data['Serial Number'][i])
device.part_number = "{}".format(data['Part Number'][i])
placeholder.id_device_supplier = "{}".format(
data['Id device Supplier'][i]
)
placeholder.pallet = "{}".format(data['Pallet'][i])
placeholder.info = "{}".format(data['Info'][i])
placeholder_log = PlaceholdersLog(
type="Update", source=self.source, placeholder=device.placeholder
)
self.placeholders.append((device, placeholder_log))
continue
# create a new one # create a new one
json_snapshot = { json_snapshot = {
'type': 'Snapshot', 'type': 'Snapshot',
@ -1571,8 +1542,8 @@ class UploadPlaceholderForm(FlaskForm):
}, },
} }
json_placeholder = { json_placeholder = {
'phid': data['Phid'][i] or None,
'id_device_supplier': data['Id device Supplier'][i], 'id_device_supplier': data['Id device Supplier'][i],
'id_device_internal': data['Id device Internal'][i],
'pallet': data['Pallet'][i], 'pallet': data['Pallet'][i],
'info': data['Info'][i], 'info': data['Info'][i],
'is_abstract': False, 'is_abstract': False,
@ -1609,7 +1580,6 @@ class EditPlaceholderForm(FlaskForm):
serial_number = StringField('Serial Number', [validators.Optional()]) serial_number = StringField('Serial Number', [validators.Optional()])
part_number = StringField('Part Number', [validators.Optional()]) part_number = StringField('Part Number', [validators.Optional()])
id_device_supplier = StringField('Id Supplier', [validators.Optional()]) id_device_supplier = StringField('Id Supplier', [validators.Optional()])
phid = StringField('Phid', [validators.DataRequired()])
pallet = StringField('Pallet', [validators.Optional()]) pallet = StringField('Pallet', [validators.Optional()])
info = StringField('Info', [validators.Optional()]) info = StringField('Info', [validators.Optional()])