diff --git a/tailbone/views/batch/delproduct.py b/tailbone/views/batch/delproduct.py index ebe30df3..e181ec49 100644 --- a/tailbone/views/batch/delproduct.py +++ b/tailbone/views/batch/delproduct.py @@ -45,6 +45,19 @@ class DeleteProductBatchView(BatchMasterView): bulk_deletable = True rows_bulk_deletable = True + form_fields = [ + 'id', + 'description', + 'notes', + 'inactivity_months', + 'created', + 'created_by', + 'rowcount', + 'status_code', + 'executed', + 'executed_by', + ] + row_grid_columns = [ 'sequence', 'upc', diff --git a/tailbone/views/products.py b/tailbone/views/products.py index e7afa49a..d929a589 100644 --- a/tailbone/views/products.py +++ b/tailbone/views/products.py @@ -1608,6 +1608,7 @@ class ProductView(MasterView): if self.request.method == 'POST': if form.validate(newstyle=True): data = form.validated + fully_validated = True # collect general params batch_key = data['batch_type'] @@ -1617,27 +1618,32 @@ class ProductView(MasterView): # collect batch-type-specific params pform = params_forms.get(batch_key) - if pform and pform.validate(newstyle=True): - pdata = pform.validated - for field in pform.schema: - param_name = pform.schema[field.name].param_name - params[param_name] = pdata[field.name] + if pform: + if pform.validate(newstyle=True): + pdata = pform.validated + for field in pform.schema: + param_name = pform.schema[field.name].param_name + params[param_name] = pdata[field.name] + else: + fully_validated = False - # TODO: should this be done elsewhere? - for name in params: - if params[name] is colander.null: - params[name] = None + if fully_validated: - handler = supported[batch_key] - products = self.get_products_for_batch(batch_key) - progress = self.make_progress('products.batch') - thread = Thread(target=self.make_batch_thread, - args=(handler, self.request.user.uuid, products, params, progress)) - thread.start() - return self.render_progress(progress, { - 'cancel_url': self.get_index_url(), - 'cancel_msg': "Batch creation was canceled.", - }) + # TODO: should this be done elsewhere? + for name in params: + if params[name] is colander.null: + params[name] = None + + handler = supported[batch_key] + products = self.get_products_for_batch(batch_key) + progress = self.make_progress('products.batch') + thread = Thread(target=self.make_batch_thread, + args=(handler, self.request.user.uuid, products, params, progress)) + thread.start() + return self.render_progress(progress, { + 'cancel_url': self.get_index_url(), + 'cancel_msg': "Batch creation was canceled.", + }) return self.render_to_response('batch', { 'form': form, @@ -1668,6 +1674,17 @@ class ProductView(MasterView): colander.SchemaNode(colander.Boolean(), name='calculate_for_manual'), ) + def make_batch_params_schema_delproduct(self): + """ + Return params schema for making a "delete products" batch. + """ + return colander.SchemaNode( + colander.Mapping(), + colander.SchemaNode(colander.Integer(), name='inactivity_months', + # TODO: probably should be configurable + default=18), + ) + def make_batch_thread(self, handler, user_uuid, products, params, progress): """ Threat target for making a batch from current products query.