signoffs.core.signoffs#
A Signoff defines the business and presentation logic for collecting a single âsignatureâ
Signoff Types are registered subclasses of AbstractSignoff - they define the behaviour for a Signoff. Persistence layer for Signoff state is provided by a Signet model - one concrete Signet model can back any number of Signoff Types - can think of a Signoff instance as the strategy for managing a Signet instance.
Module Contents#
Classes#
Defines the abstract semantics for a Signoff and serves as base class for all concrete Signoff Types. |
|
A base Signoff Type to be used as abstract base class to register concrete Signoff Types Concrete Types will require a concrete Signet Model to back the signoff. |
|
Defines the default business logic for signing and revoking a |
|
Public API: Alias for `DefaultSignoffBusinessLogic |
Functions#
Force signature onto given signoff for given user and save its signet, regardless of permissions or signoff state |
|
Force revoke the given signoff for user regardless of permissions or signoff state. |
API#
- signoffs.core.signoffs.sign_signoff(signoff, user, commit=True, **kwargs)[source]#
Force signature onto given signoff for given user and save its signet, regardless of permissions or signoff state
kwargs are passed directly to save - use commit=False to sign without saving.
- signoffs.core.signoffs.revoke_signoff(signoff, user, reason='', revokeModel=None, **kwargs)[source]#
Force revoke the given signoff for user regardless of permissions or signoff state.
@param revokeModel: if supplied, create record of revocation, otherwise just delete the signet.
- class signoffs.core.signoffs.AbstractSignoff(signet=None, subject=None, **kwargs)[source]#
Defines the abstract semantics for a Signoff and serves as base class for all concrete Signoff Types.
A
Signoff Type(i.e. subclass ofAbstractSignoff) defines the behaviours for a specific type of signoff.A
Signoffinstance represents a timestamped agreement by aUser, persisted by aSignetmodel instance. Signoffs are pure code objects, not stored in the DB - they define application logic, not application data. A Signoff Type defines:how the
Signetis labelled and rendered,what permission is required to sign or revoke it,
what forms are used to sign and revoke them, etc. The default meta-data and services can be overridden in a subclass or passed to .register() factory. Signoff Types are registered in the
signoffs.registry.signoffsregistry where they can be retrieved by id
Caution
Signetrecords are stored in DB with a reference toSignoff.idBe cautions not to change or delete idâs that are in-use.Initialization
Construct a Signoff instance backed by the given signet or an instance of
cls.signetModel(**kwargs)subjectis optional: the object this signoff is signing off on - set bySignoffFieldbut otherwise unused.- signetModel: signoffs.core.signoffs.signet_type#
None
- logic: signoffs.core.signoffs.SignoffLogic#
None
- revokeModel: signoffs.core.signoffs.revoke_type#
None
- render: signoffs.core.renderers.SignoffRenderer#
None
- forms: signoffs.core.forms.SignoffFormsManager#
None
- urls: signoffs.core.urls.SignoffUrlsManager#
None
- classmethod register(id, **kwargs)[source]#
Create, register, and return a new subclass of cls with overrides for given kwargs attributes
Standard mechanism to define new Signoff types, typically in
my_app/models.pyormy_app/signoffs.pyUsage:MySignoff = AbstractSignoff.register('my_signoff_type', label='Sign it!', ...)
- classmethod validate()[source]#
Run any class validation that must pass before class can be registered. Invoked by registry.
- classmethod get_signetModel()[source]#
Always use this accessor as the signetModel attribute may be an âapp.Modelâ label
- classmethod get_signet_queryset()[source]#
Return a base (unfiltered) queryset of ALL signets for this Signoff Type
- classmethod get_revoked_signets_queryset()[source]#
Return a base (unfiltered) queryset of ALL revoked signets for this Signoff Type
- classmethod get_revokeModel()[source]#
Always use this accessor as the revokeModel attributed may be an âapp.Modelâ label
- classmethod get(queryset=None, **filters)[source]#
Return the saved signoff that matches filters or a new signoff with these initial values if none exists
Raises
MultipleObjectsReturnedif more than one signoff matches filter criteria.
- property subject#
The object being signed off on, if provided.
Subclass with signet FK relations may want to override this to access the signet related object.
subjectis set by model Fields for convenient access to owner obj, but value is not used by core logic.
- property slug#
A slugified version of the signoff id, for places where a unique identifier slug is required
- property signet_model#
Return the signoff model for this type
- property revoke_model#
Return the revoke model for this type
- get_new_signet(**initial_values)[source]#
Get a new, unsaved signet instance for this signoff type, with given optional initial values
- matches(other)[source]#
Return True iff this signoff is of same type as other, which may be a signoff instance or a str
- get_signet_defaults(user)[source]#
Return a dictionary of default values for fields this signoffâs signet -
Called during signoff.sign - provides default values that will NOT override values already set on the signet. See signets.get_signet_defaults for further docs.
- classmethod is_permitted_signer(user)[source]#
return True iff user has permission to sign a signoff of this Type
- sign_if_permitted(user, commit=True, **kwargs)[source]#
Sign for given user and save signet, if self.can_sign(user), raise
PermissionDeniedotherwisekwargsare passed directly to sign_method - usecommit=Falseto sign without saving.
- sign(user, commit=True, **kwargs)[source]#
Sign for given user and save signet, regardless of permissions or signoff state
kwargsare passed directly to sign_method - usecommit=Falseto sign without saving.
- classmethod is_permitted_revoker(user)[source]#
Return True iff user has permission to revoke signoffs of this Type
- revoke_if_permitted(user, reason='', **kwargs)[source]#
Revoke this signoff for user if they have permission, otherwise raise PermissionDenied
- revoke(user, reason='', **kwargs)[source]#
Revoke this signoff regardless of permissions or signoff state - careful!
Prefer to use
revoke_if_permittedto enforce business rules.
- property signatory#
Return the user who signed, or AnonymousUser if signed but no signatory, None if not yet signed
- property sigil#
Return the âsigilâ on this signoff if it is signed, None otherwise
- property sigil_label#
Return a label for the âsigilâ on this signoff, if it is signed, None otherwise
- property timestamp#
Return the timestamp on this signoff if it is signed, None otherwise
- validate_save()[source]#
Raise PermissionDenied if this Signoff cannot be saved, otherwise just pass.
- class signoffs.core.signoffs.BaseSignoff(signet=None, subject=None, **kwargs)[source]#
Bases:
signoffs.core.signoffs.AbstractSignoffA base Signoff Type to be used as abstract base class to register concrete Signoff Types Concrete Types will require a concrete Signet Model to back the signoff.
Tip
Register new Signoff Types with::
BaseSignoff.register(...)Initialization
Construct a Signoff instance backed by the given signet or an instance of
cls.signetModel(**kwargs)subjectis optional: the object this signoff is signing off on - set bySignoffFieldbut otherwise unused.- id#
âsignoffs.base-signoffâ
- signetModel#
None
- revokeModel#
None
- label#
âI consentâ
- class signoffs.core.signoffs.DefaultSignoffBusinessLogic(perm=None, sign_method=None, revoke_perm=None, revoke_method=None)[source]#
Defines the default business logic for signing and revoking a
SignoffinstanceNote
SignoffBusinessLogicshould not encode contextual (e.g., approval or approval process) business logic.Initialization
Override default actions / permissions, or None to use class default
- perm: signoffs.core.signoffs.opt_str = <Multiline-String>#
- revoke_perm: signoffs.core.signoffs.opt_str = <Multiline-String>#
- classmethod mixin(*mixins)[source]#
Return a subclass of this class with the given mixin classes mixed in
- is_permitted_signer(signoff_type, user)[source]#
Return True iff user has permission to sign a signoff of given type
- sign_if_permitted(signoff, user, commit=True, **kwargs)[source]#
Sign signoff for given user and save signet, if self.can_sign(user) raises PermissionDenied otherwise kwargs are passed directly to save - use commit=False to sign without saving.
- sign(signoff, user, commit=True, **kwargs)[source]#
Sign signoff for given user and save signet, regardless of permissions or signoff state - careful!
kwargs are passed directly to save - use commit=False to sign without saving. Prefer to use
sign_if_permittedto enforce business rules.
- is_permitted_revoker(signoff_type, user)[source]#
return True iff user has permission to revoke signoffs of given type
- class signoffs.core.signoffs.SignoffLogic(perm=None, sign_method=None, revoke_perm=None, revoke_method=None)[source]#
Bases:
signoffs.core.signoffs.DefaultSignoffBusinessLogicPublic API: Alias for `DefaultSignoffBusinessLogic
Initialization
Override default actions / permissions, or None to use class default
signoffs.contrib.signets.signoffs#
Some basic Signoff Types backed by the Signet models defined in this package
Add "signoffs.contrib.signets" to settings.INSTALLED_APPS
Module Contents#
Classes#
A basic Signoff Type that can be used out-of-the-box for simple use-cases where any user can sign off |
|
A SimpleSignoff that stores a âreceiptâ when a signoff is revoked |
|
A SimpleSignoff that can never be revoked |
API#
- class signoffs.contrib.signets.signoffs.SimpleSignoff(signet=None, subject=None, **kwargs)#
Bases:
signoffs.core.signoffs.BaseSignoffA basic Signoff Type that can be used out-of-the-box for simple use-cases where any user can sign off
Uses
DefaultSignoffBusinessLogic- unrestricted: anyone can sign or revoke. Backed bysignoffs.contrib.signets.models.Signetmodel.Initialization
Construct a Signoff instance backed by the given signet or an instance of
cls.signetModel(**kwargs)subjectis optional: the object this signoff is signing off on - set bySignoffFieldbut otherwise unused.- signetModel#
None
- revokeModel#
None
- label#
âI consentâ
- class signoffs.contrib.signets.signoffs.RevokableSignoff(signet=None, subject=None, **kwargs)#
Bases:
signoffs.contrib.signets.signoffs.SimpleSignoffA SimpleSignoff that stores a âreceiptâ when a signoff is revoked
Initialization
Construct a Signoff instance backed by the given signet or an instance of
cls.signetModel(**kwargs)subjectis optional: the object this signoff is signing off on - set bySignoffFieldbut otherwise unused.- revokeModel#
None
- class signoffs.contrib.signets.signoffs.IrrevokableSignoff(signet=None, subject=None, **kwargs)#
Bases:
signoffs.contrib.signets.signoffs.SimpleSignoffA SimpleSignoff that can never be revoked
Initialization
Construct a Signoff instance backed by the given signet or an instance of
cls.signetModel(**kwargs)subjectis optional: the object this signoff is signing off on - set bySignoffFieldbut otherwise unused.- revoke_perm#
False
- logic#
None