From d1fc5d5c382ac6351ca38d9c88a736d7ac204906 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 21 Feb 2023 17:35:47 -0600 Subject: [PATCH] Validate vendor for catalog batch upload --- tailbone/views/batch/vendorcatalog.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tailbone/views/batch/vendorcatalog.py b/tailbone/views/batch/vendorcatalog.py index 01fa85ea..1bd5eed7 100644 --- a/tailbone/views/batch/vendorcatalog.py +++ b/tailbone/views/batch/vendorcatalog.py @@ -202,6 +202,8 @@ class VendorCatalogView(FileBatchMasterView): if self.creating and 'vendor' in f: f.replace('vendor', 'vendor_uuid') 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 # autocomplete is to be used, we also must make sure we @@ -258,6 +260,13 @@ class VendorCatalogView(FileBatchMasterView): else: 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): key = getattr(batch, field) if not key: