signoffs.core.models.managers#

Custom object and query managers.

Module Contents#

Classes#

QuerySetApiMixin

Delegates common methods to a query manager or queryset to emulate a queryset-like API, without making extra queries where possible. Assumes a small number of instances on the queryset

SignetSetApiMixin

Delegates common methods to a signet_set manager or queryset

SignoffSetManager

Manage a set of Signoff objects backed by a signet manager or queryset. May be used, for example, on the reverse side of a many-to-one relation formed by a Signet with a FK.

SignoffSingleManager

A SignoffSetManager that attempts to limit the number of related signets to one and provide simplified API for dealing with the single signoff. Why? b/c it is convenient to manage all signoffs, e.g., on an Approval, backed by one Signet model. If every Signoff is a single, then a set of SignoffFields is well-suited to the task. But if any Signoff may be a series, then it is convenient to model all as SignoffSets. This class helps clarify that a specific reverse Many2One relation is being modeled as a OneToOne. Caveats Can’t really prevent multiple signoffs being added via non-API access. That’s up to the application programmer.

StampSignoffsManager

Manage the entire set of signoffs related to a Stamp of Approval via reverse signet_set manager. Note that a single Stamp manages one set of Signets that may be of various Signoff Types - recommend using a SignoffSetManager instead, unless access to entire set of signoffs is needed. Provides a unified API for accessing a single Stamp instance’s related signoffs and signets.

ApprovalStampSetApiMixin

Delegates common methods to a stamp_set manager or queryset

ApprovalSetManager

Manage a set of Approval objects backed by a Stamp manager or queryset. May be used, for example, on the reverse side of a many-to-one relation formed by a Stamp with a FK. Provides a unified API for accessing Approval instances, and related SigningOrder, Stamp, signoffs, and signets.

API#

class signoffs.core.models.managers.QuerySetApiMixin[source]#

Delegates common methods to a query manager or queryset to emulate a queryset-like API, without making extra queries where possible. Assumes a small number of instances on the queryset

qs#

None

all()[source]#

Return list of objects in this set, ordered chronologically

count()[source]#

Return the number of objects in the qs

exists()[source]#

Rerturn True iff at least one Object exists in this set

earliest()[source]#

Return the first object from this set, or None if not self.exists()

latest()[source]#

Return most recent object from this set, or None if not self.exists()

class signoffs.core.models.managers.SignetSetApiMixin[source]#

Bases: signoffs.core.models.managers.QuerySetApiMixin

Delegates common methods to a signet_set manager or queryset

signet_set#

None

property qs#
class signoffs.core.models.managers.SignoffSetManager(signoff_type, signet_set, signet_set_owner=None)[source]#

Bases: signoffs.core.models.managers.SignetSetApiMixin

Manage a set of Signoff objects backed by a signet manager or queryset. May be used, for example, on the reverse side of a many-to-one relation formed by a Signet with a FK.

For example::

signets = Signets.objects.filter(user=bob)
bobs_report_signoffs = SignoffSetManager('myapp.signoffs.report', signets)

For ā€œreverseā€ access from a signet-related object, use a SignoffSet field to define the reverse manager.

The API is modelled on django’s related object managers, with familiar operations that work roughly equivalently.

Initialization

Manage the signet_set (query manager or queryset), filtered for the given Signoff Type If an approval instance is supplied, signets in this set are created with a reference to the approval’s stamp.

all()[source]#

Return list of signoffs in this set, ordered chronologically

_pre_save_owner()[source]#

Bit of a hack - if signet_set_owner is an unsaved model, save it before saving related signets

create(user, **kwargs)[source]#

Create and return a new Signoff in this set

can_sign(user)[source]#

Return True iff given user would be allowed to sign (create) a new signoff in this set

has_signed(user)[source]#

Return True iff given user is a signatory in this set of signoffs

property forms#

Return the forms manager for adding a new signoff to this set or revoking a signoff in this set.

revoked()[source]#

Returns a queryset of revoked signets related to the manager’s instance. related ā€˜revoked’ and ā€˜revoked.user’ objects are selected, assuming why else get the revoked signoffs

class signoffs.core.models.managers.SignoffSingleManager(signoff_type, signet_set, signet_set_owner=None)[source]#

Bases: signoffs.core.models.managers.SignoffSetManager

A SignoffSetManager that attempts to limit the number of related signets to one and provide simplified API for dealing with the single signoff. Why? b/c it is convenient to manage all signoffs, e.g., on an Approval, backed by one Signet model. If every Signoff is a single, then a set of SignoffFields is well-suited to the task. But if any Signoff may be a series, then it is convenient to model all as SignoffSets. This class helps clarify that a specific reverse Many2One relation is being modeled as a OneToOne. Caveats Can’t really prevent multiple signoffs being added via non-API access. That’s up to the application programmer.

Initialization

Manage the signet_set (query manager or queryset), filtered for the given Signoff Type If an approval instance is supplied, signets in this set are created with a reference to the approval’s stamp.

get()[source]#

Get this signoff

create(user, **kwargs)[source]#

Create and return the new Signoff. Raise ??? if self.exists()

can_sign(user)[source]#

Return True iff given user would be allowed to sign (create) a new signoff in this set

class signoffs.core.models.managers.StampSignoffsManager(stamp, subject=None)[source]#

Bases: signoffs.core.models.managers.SignetSetApiMixin

Manage the entire set of signoffs related to a Stamp of Approval via reverse signet_set manager. Note that a single Stamp manages one set of Signets that may be of various Signoff Types - recommend using a SignoffSetManager instead, unless access to entire set of signoffs is needed. Provides a unified API for accessing a single Stamp instance’s related signoffs and signets.

For example::

stamp = ProjectStamp.objects.filter(project_id='bob').first()
bobs_project_signoffs = StampSignoffsManager(stamp)

The API is modelled on django’s related object managers, with familiar operations that work roughly equivalently.

Initialization

Manage the given Approval instance and all of its related data

property signet_set#

required for SignetSetApiMixin

all()[source]#

Return list of signoffs in this approval, ordered chronologically

class signoffs.core.models.managers.ApprovalStampSetApiMixin[source]#

Bases: signoffs.core.models.managers.QuerySetApiMixin

Delegates common methods to a stamp_set manager or queryset

stamp_set#

None

property qs#
class signoffs.core.models.managers.ApprovalSetManager(approval_type, stamp_set, subject=None)[source]#

Bases: signoffs.core.models.managers.ApprovalStampSetApiMixin

Manage a set of Approval objects backed by a Stamp manager or queryset. May be used, for example, on the reverse side of a many-to-one relation formed by a Stamp with a FK. Provides a unified API for accessing Approval instances, and related SigningOrder, Stamp, signoffs, and signets.

For example::

stamps = Stamp.objects.filter(user=bob)
bobs_report_approvals = ApprovalSetManager('myapp.approvals.report', stamps)

For ā€œreverseā€ access from a stamp-related object, use an ApprovalSet field to define the reverse manager.

The API is modelled on django’s related object managers, with familiar operations that work roughly equivalently.

Initialization

Manage the stamp_set (query manager or queryset), filtered for the given Signoff Type

all()[source]#

Return list of approvals in this set, ordered chronologically

create(**kwargs)[source]#

Create and return a new Approval in this set