3
0
Fork 0

fix: let view subclass more easily inject kwargs for make_batch()

This commit is contained in:
Lance Edgar 2024-12-15 02:28:22 -06:00
parent 180acc509f
commit 863a8814e1

View file

@ -203,12 +203,15 @@ class BatchMasterView(MasterView):
f.set_node('executed_by', UserRef(self.request))
f.set_readonly('executed_by')
def objectify(self, form):
def objectify(self, form, **kwargs):
"""
We override the default logic here, to invoke
:meth:`~wuttjamaican:wuttjamaican.batch.BatchHandler.make_batch()`
on the batch handler - when creating. Parent/default logic is
used when updating.
:param \**kwargs: Additional kwargs will be passed as-is to
the ``make_batch()`` call.
"""
if self.creating:
@ -219,15 +222,18 @@ class BatchMasterView(MasterView):
batch = schema.objectify(form.validated, context=form.model_instance)
# then we collect attributes from the new batch
kwargs = dict([(key, getattr(batch, key))
for key in form.validated
if hasattr(batch, key)])
kw = dict([(key, getattr(batch, key))
for key in form.validated
if hasattr(batch, key)])
# and set attribute for user creating the batch
kwargs['created_by'] = self.request.user
kw['created_by'] = self.request.user
# plus caller can override anything
kw.update(kwargs)
# finally let batch handler make the "real" batch
return self.batch_handler.make_batch(self.Session(), **kwargs)
return self.batch_handler.make_batch(self.Session(), **kw)
# when not creating, normal logic is fine
return super().objectify(form)