fix: let view subclass more easily inject kwargs for make_batch()
This commit is contained in:
parent
180acc509f
commit
863a8814e1
|
@ -203,12 +203,15 @@ class BatchMasterView(MasterView):
|
||||||
f.set_node('executed_by', UserRef(self.request))
|
f.set_node('executed_by', UserRef(self.request))
|
||||||
f.set_readonly('executed_by')
|
f.set_readonly('executed_by')
|
||||||
|
|
||||||
def objectify(self, form):
|
def objectify(self, form, **kwargs):
|
||||||
"""
|
"""
|
||||||
We override the default logic here, to invoke
|
We override the default logic here, to invoke
|
||||||
:meth:`~wuttjamaican:wuttjamaican.batch.BatchHandler.make_batch()`
|
:meth:`~wuttjamaican:wuttjamaican.batch.BatchHandler.make_batch()`
|
||||||
on the batch handler - when creating. Parent/default logic is
|
on the batch handler - when creating. Parent/default logic is
|
||||||
used when updating.
|
used when updating.
|
||||||
|
|
||||||
|
:param \**kwargs: Additional kwargs will be passed as-is to
|
||||||
|
the ``make_batch()`` call.
|
||||||
"""
|
"""
|
||||||
if self.creating:
|
if self.creating:
|
||||||
|
|
||||||
|
@ -219,15 +222,18 @@ class BatchMasterView(MasterView):
|
||||||
batch = schema.objectify(form.validated, context=form.model_instance)
|
batch = schema.objectify(form.validated, context=form.model_instance)
|
||||||
|
|
||||||
# then we collect attributes from the new batch
|
# then we collect attributes from the new batch
|
||||||
kwargs = dict([(key, getattr(batch, key))
|
kw = dict([(key, getattr(batch, key))
|
||||||
for key in form.validated
|
for key in form.validated
|
||||||
if hasattr(batch, key)])
|
if hasattr(batch, key)])
|
||||||
|
|
||||||
# and set attribute for user creating the batch
|
# 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
|
# 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
|
# when not creating, normal logic is fine
|
||||||
return super().objectify(form)
|
return super().objectify(form)
|
||||||
|
|
Loading…
Reference in a new issue