signoffs.core.forms#
Forms for collecting and revoking signoffs.
Challenges:
the
Signetform itself is just a labelled checkbox - it doesnât display any model fields. Yet, it should behave like a model form, defining a signoff instance once validated.the form is only displayed when there is no instance - you canât edit a saved signoff, only revoke it. So these forms donât have an instance - they are only used to âaddâ a signoff.
the form itself likely needs an association to the Signoff Type so it can be rendered correctly.
so, the signoff type itself might be obtained from the request data (e.g., in a generic view) So if the request is bad, it may not be possible to construct a Form class to validate rest of data.
Signets with relations: The form is being used to sign off on something specific, so it likely needs a relation to some concrete object. So the view will need some way to know which object is being signed off on.
To solve this for concrete Signets with relational fields, try ONE of these approaches:
pre-create the signoff instance, with relations in place, and pass it to the form. The
Signetinstance, with its relations, will be saved if form validates and is signed.specialize
AbstractSignoffFormto add hidden fields with the extra relation data; Use initial data to populate these fields and be sure to overrideclean()to validate the extra data.
Module Contents#
Classes#
Abstract Base class for the signoff_form_factory |
|
Form used to validate requests to revoke a signoff - not really intended to be user-facing. Not intended to collect signoffs, but rather simply to house the validation logic for revoke requests, which may be delete rather than post requests. It is not a ModelForm so it remains as generic as possible, though in many ways a Signet ModelForm might be useful. |
|
Manage the forms used by a particular signoff type - usually injected using a FormsManager service |
|
A descriptor class that âinjectsâ a |
Functions#
Returns a Form class suited to collecting a signoff. Not unlike modelform_factory, except the model is provided by the signoff_type. baseForm can be overridden to add additional fields and/or fully customize validation and save logic. Validation ensures the type of signoff in POST matches the type provided. Signing this form with a User performs a permissions check and saves the signoff, if required. |
|
Returns a Form class suited to validation a signoff revoke request. Not unlike modelform_factory, except the model is provided by the signoff_type. baseForm can be overridden to add additional fields and/or fully customize validation and save logic. Validation ensures the type of signoff in POST matches the type provided. Revoking this form with a User performs a permissions check and deletes the signoffâs signet, if required. |
API#
- class signoffs.core.forms.AbstractSignoffForm(*args, instance=None, **kwargs)[source]#
Bases:
django.forms.ModelFormAbstract Base class for the signoff_form_factory
Initialization
Form accepts an optional signoff, used like the instance parameter for ModelForms to pass initial values. Form also accepts âuserâ as optional kwarg: the user who is signing off
- signed_off#
None
- signoff_id#
None
- class Meta[source]#
- model#
None
- exclude#
[âuserâ, âsigilâ, âsigil_labelâ, âtimestampâ]
- clean()[source]#
Validate signoff for consistency with the instance form was intialized with.
Note
Donât be tempted to check permissions here! The form is clean even if user doesnât have permission!
- sign(user, commit=True)[source]#
Sign and save this form for the given user, without checking permissions (no business logic invoked!)
- Returns:
the saved Signet instance, or None if the signoff was not actually signed.
Note
If signoff has m2m relations and commit==False, caller is responsible to call self.save_m2m()
- signoffs.core.forms.signoff_form_factory(signoff_type, baseForm=AbstractSignoffForm, form_prefix=None, signoff_field_kwargs=None)[source]#
Returns a Form class suited to collecting a signoff. Not unlike modelform_factory, except the model is provided by the signoff_type. baseForm can be overridden to add additional fields and/or fully customize validation and save logic. Validation ensures the type of signoff in POST matches the type provided. Signing this form with a User performs a permissions check and saves the signoff, if required.
- class signoffs.core.forms.AbstractSignoffRevokeForm(*args, **kwargs)[source]#
Bases:
django.forms.FormForm used to validate requests to revoke a signoff - not really intended to be user-facing. Not intended to collect signoffs, but rather simply to house the validation logic for revoke requests, which may be delete rather than post requests. It is not a ModelForm so it remains as generic as possible, though in many ways a Signet ModelForm might be useful.
Initialization
Form requires the signetModel class of the signet to be revoked
- signoff_id#
None
- signet_pk#
None
- clean()[source]#
Validate the signoff type for the formâs signet matches the formâs signoff type
Note
Donât be tempted to check permissions here! The form is clean even if user doesnât have permission!
- signoffs.core.forms.revoke_form_factory(signoff_type, baseForm=AbstractSignoffRevokeForm, form_prefix=None, signoff_field_kwargs=None)[source]#
Returns a Form class suited to validation a signoff revoke request. Not unlike modelform_factory, except the model is provided by the signoff_type. baseForm can be overridden to add additional fields and/or fully customize validation and save logic. Validation ensures the type of signoff in POST matches the type provided. Revoking this form with a User performs a permissions check and deletes the signoffâs signet, if required.
- class signoffs.core.forms.SignoffTypeForms(signoff_type, signoff_form=None, revoke_form=None)[source]#
Manage the forms used by a particular signoff type - usually injected using a FormsManager service
Initialization
- signoff_form: signoffs.core.forms.opt_callable#
None
baseForm type passed to signoff_form_factory or a callable that returns a Form subclass
- revoke_form: signoffs.core.forms.opt_callable#
None
baseForm type passed to revoke_form_factory or a callable that returns a Form subclass
- static _get_form_class(candidate)[source]#
candidate may be a Form subclass or a callable that returns one - return the Form subclass either way
- get_signoff_form_class(**kwargs)[source]#
Return a form class suitable for collecting a signoff of this Type. kwargs passed through to factory.
- get_revoke_form_class(**kwargs)[source]#
Return a form class suitable for validating revoke request for a signoff of this Type.
- class signoffs.core.forms.SignoffFormsManager[source]#
Bases:
class_service(service_class=SignoffTypeForms)A descriptor class that âinjectsâ a
SignoffTypeFormsinstance into a Signoff instance.To inject custom form services:
provide a custom service_class:
forms=SignoffFormsManager(service_class=MyInstanceForms)OR specialize class attributes:
MySignoffFormsManager = utils.service(SignoffTypeForms, signoff_form=mySignoffForm)OR bothâŚ
MySignoffFormsManager = utils.service(MyInstanceForms)
signoffs.contrib.approvals.forms#
A form for collecting approval signoffs
Module Contents#
Classes#
Form for collecting approval signoffs |
API#
- class signoffs.contrib.approvals.forms.ApprovalSignoffForm(*args, instance=None, **kwargs)[source]#
Bases:
signoffs.core.forms.AbstractSignoffFormForm for collecting approval signoffs
Initialization
Form accepts an optional signoff, used like the instance parameter for ModelForms to pass initial values. Form also accepts âuserâ as optional kwarg: the user who is signing off
- class Meta[source]#
Bases:
signoffs.core.forms.AbstractSignoffForm.Meta- model#
None
- widgets#
None