Django Contracts
This is a lightweight (and hopefully minimally opinionated) library that exists to make it easier to apply Django Forms to your views. If you need more complex capabilities than what Django Forms offers then you might want to consider something like Django REST Framework.
Basic Usage
from django_contracts.contracts import apply_contract
@apply_contract(request_contracts={'POST': MyRequestForm}, response_contracts={'POST': MyResponseForm})
def my_view(request):
# If you get here then the request matched your contract
data = request.validated_data
# ... do something with the data
You can also supply a function which returns a Django Form class to use as a contract. This is helpful if you need a form to be specific to a user.
from django import forms
from django_contracts.contracts import request_contract
def create_form_for_user(user, data):
class MyUserForm(forms.Form):
# ...
if user_can_do_thing:
my_field = ...
return MyUserForm(data)
@apply_contract(request_contracts={'POST': create_form_for_user}, pass_in_user=True)
def my_view(request):
# ...
Or if you prefer to override init on the form:
from django import forms
from django_contracts.contracts import apply
class MyUserForm(forms.Form):
def __init__(self, user, *args, **kwargs):
super(*args, **kwargs)
self.user = user
@apply_contract(request_contracts={'POST': create_form_for_user}, pass_in_user=True)
def my_view(request)
# ...
Using forms that take a User can be useful for filtering choice options.
Metadata
Release files for django-contracts 0.4.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django_contracts-0.4.5.tar.gz | 14.1 kB | Without provenance | Details for django_contracts-0.4.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_contracts-0.4.5-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for django_contracts-0.4.5-py2.py3-none-any.whl |
Total release size: 56.3 kB
Release files / django_contracts-0.4.5.tar.gz
| Download URL | django_contracts-0.4.5.tar.gz |
|---|---|
| Size | 14.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
20a1551c65cb2855f630276981f01d95d71ddd1663263582674df40c5dbdd40f
|
|
BLAKE2b-256 checksum How to use checksums |
0810cc7bf2655f2ab5b6d0c5e4bdc6899b8c1557a04cd6aaab9c99a3b83cc06e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3
|
Release files / django_contracts-0.4.5-py2.py3-none-any.whl
| Download URL | django_contracts-0.4.5-py2.py3-none-any.whl |
|---|---|
| Size | 42.2 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
c93031c2bcd1b934775e88057bb1862ebb6864ab5b55a2cd8fd93c06528052ea
|
|
BLAKE2b-256 checksum How to use checksums |
ed4838ba4a3a59a78c262b597a8f0077a9181c3a10f3c098bb070cf82daf043d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3
|
Security for django-contracts 0.4.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.