Validate vendor for catalog batch upload

This commit is contained in:
Lance Edgar 2023-02-21 17:35:47 -06:00
parent 2fa62acbbd
commit d1fc5d5c38

View file

@ -202,6 +202,8 @@ class VendorCatalogView(FileBatchMasterView):
if self.creating and 'vendor' in f: if self.creating and 'vendor' in f:
f.replace('vendor', 'vendor_uuid') f.replace('vendor', 'vendor_uuid')
f.set_label('vendor_uuid', "Vendor") f.set_label('vendor_uuid', "Vendor")
f.set_required('vendor_uuid')
f.set_validator('vendor_uuid', self.valid_vendor_uuid)
# should we use dropdown or autocomplete? note that if # should we use dropdown or autocomplete? note that if
# autocomplete is to be used, we also must make sure we # autocomplete is to be used, we also must make sure we
@ -258,6 +260,13 @@ class VendorCatalogView(FileBatchMasterView):
else: else:
f.remove('cache_products') f.remove('cache_products')
def valid_vendor_uuid(self, node, value):
model = self.model
if value:
vendor = self.Session.get(model.Vendor, value)
if not vendor:
raise colander.Invalid(node, "Vendor not found")
def render_parser_key(self, batch, field): def render_parser_key(self, batch, field):
key = getattr(batch, field) key = getattr(batch, field)
if not key: if not key: