Models¶
django-anysign presumes digital signature involves models in the Django project: one to store the signatures, another to store signers, and one to store backend specific options.
That said, django-anysign does not embed concrete models: it provides base models you have to extend in your applications. This design allows you to customize models the way you like, i.e. depending on your use case.
Minimal integration¶
Here is the minimal integration you need in some models.py:
import django_anysign
class SignatureType(django_anysign.SignatureType):
pass
class Signature(django_anysign.SignatureFactory(SignatureType)):
pass
class Signer(django_anysign.SignerFactory(Signature)):
pass
The example above is taken from django-anysign‘s Demo project.
SignatureType¶
-
class
django_anysign.models.SignatureType(*args, **kwargs)¶ Bases:
django.db.models.base.ModelAbstract base model for signature type.
A signature type encapsulates backend setup. Typically:
- a “configured backend” is a backend class (such as
DummySignBackend) and related configuration (URL, credentials...). - a
Signatureinstance will be related to a configured backend, via aSignatureType.
-
signature_backend_code= None¶ Machine-readable code for the backend. Typically related to settings, by default keys in
settings.ANYSIGN['BACKENDS']dictionary.
-
SignatureType.signature_backend_options¶ Dictionary for backend’s specific configuration.
Default implementation returns empty dictionary.
There are 2 main ways for you to setup backends with the right arguments:
- in the model subclassing this one, override this property. This is
the good option if you can have several
SignatureTypeinstances for one backend, i.e. ifsignature_backend_codeis not unique. - in the backend’s subclass, make
__init__()read the Django settings or environment. This can be a good option if you have an uniqueSignatureBackendinstance matching a backend (signature_backend_codeis unique).
- in the model subclassing this one, override this property. This is
the good option if you can have several
-
SignatureType.get_signature_backend()¶ Instanciate and return signature backend instance.
Default implementation uses
get_backend_instance()withsignature_backend_codeas positional arguement and withsignature_backend_options()as keyword arguments.
-
SignatureType.signature_backend¶ Return backend from internal cache or new instance.
If
signature_backend_codechanged since the last access, then the internal (instance level) cache is invalidated and a new instance is returned.
- a “configured backend” is a backend class (such as
Signature¶
-
django_anysign.models.SignatureFactory(SignatureType)¶ Return base class for signature model, using
SignatureTypemodel.This pattern is the best one we found at the moment to have an abstract base model
SignatureBasewith appropriate foreign key toSignatureTypemodel. Feel free to propose a better option if you know one ;)
Here is what you get in the Demo project:
Signer¶
-
django_anysign.models.SignerFactory(Signature)¶ Return base class for signer model, using
Signaturemodel.This pattern is the best one we found at the moment to have an abstract base model
Signerwith appropriate foreign key toSignaturemodel. Feel free to propose a better option if you know one ;)
Here is what you get in the Demo project: