Django Warning Forms
Add warnings to your Django Forms easily
Documentation
The full documentation is at https://dj-warning-forms.readthedocs.io.
Quickstart
Install Django Warning Forms:
pip install dj-warning-forms
Use the form mixin in any form
from django import forms
from dj_warning_forms.forms import WarningFormMixin, FormFieldWarning
from .models import Poll
class PollForm(WarningFormMixin, forms.ModelForm):
question = forms.CharField(
max_length=200, widget=forms.TextInput(attrs={"autocomplete": "off"})
)
class Meta:
model = Poll
fields = "__all__"
def warning_question(self) -> List[FormFieldWarning]:
if not self.cleaned_data["question"].endswith("?"):
return [
FormFieldWarning(
message="Weird question",
description="This question does not end with a question mark. Are you sure you want to publish this question?", # noqa
)
]
return []
Adding a warning is as simple as adding a method with the warning_ prefix. This method must return a list of FormFieldWarning objects.
Showing warnings in the template
You can find the list of warnings in form.warnings.
{% block content %}
<form action="." method="post">
{% csrf_token %}
{{ form }}
<input type="submit" value="Submit">
<!-- Customize your form warnings as you wish -->
{% if form.warnings %}
<div class="rounded p-2 mt-2 bg-warning">
<ul>
{% for warning in form.warnings %}
<li><b>{{ warning.message }}:</b> {{ warning.description }}</li>
{% endfor %}
</ul>
</div>
{% endif %}
<!-- End of form warnings -->
</form>
{% endblock %}
Features
No external dependencies
Minimal changes needed in your forms
Easy to customize
Running Tests
Does the code actually work?
source <YOURVIRTUALENV>/bin/activate (myenv) $ pip install tox (myenv) $ tox
Development commands
pip install -r requirements_dev.txt invoke -l
Credits
Tools used in rendering this package:
Metadata
Release files for dj-warning-forms 0.1.0
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 |
|---|---|---|---|---|
| dj-warning-forms-0.1.0.tar.gz | 7.4 kB | Without provenance | Details for dj-warning-forms-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dj_warning_forms-0.1.0-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for dj_warning_forms-0.1.0-py2.py3-none-any.whl |
Total release size: 13.5 kB
Release files / dj-warning-forms-0.1.0.tar.gz
| Download URL | dj-warning-forms-0.1.0.tar.gz |
|---|---|
| Size | 7.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
543fa51ac63d87b42715419bd46561833f00aa67540413b2409478e4dfbe9702
|
|
BLAKE2b-256 checksum How to use checksums |
1b0fdf9c1fca091ba49914bf4857542da810c10cb88f5fda273b70bfbe9abf2f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2
|
Release files / dj_warning_forms-0.1.0-py2.py3-none-any.whl
| Download URL | dj_warning_forms-0.1.0-py2.py3-none-any.whl |
|---|---|
| Size | 6.1 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
c11cbd8205c7185603fd0fe2741a13ddb278416b0bf05708ca4222715cddbafc
|
|
BLAKE2b-256 checksum How to use checksums |
4933daa453f629bc52ceb6286a47f8c222fe209b62dc49795cc4d0b622c7c81a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2
|
Security for dj-warning-forms 0.1.0
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.