Normalized FileField
File field that behaves as close to other fields as possible.
0.1.1
Whaat?
This!
Screenshots
(animated gif)
Whaaaaat?! I don get it!
Basic idea: I want to handle file inputs no differently from other inputs!
If a text input can have its value “sent back” when form validation fails, so must the file input!
Even when a file field is required, user should still be able to clear it (just as they can delete text in a required text field) no matter that the field validation will fail!
File inputs in HTML are a bit different that other inputs (“text”, “checkbox”, etc). Amount of data involved in a typical “file” field is much larger then what is in fields on any other type. It is one thing to send and return (in the case of form validation error) a few characters in a text input, another thing completely to send and return megabytes of data in files - it’s not practical.
On the server side this means that files have to be handled differently as well. Usually they are saved in a temporary place and it is up to the developer to copy them where needed.
Django hides some of this boilerplate away, making working with file fields a bit simpler. But still it is different from other fields. As this package demonstrates, there is no real need for this, as file fields can be made to behave like other fields.
This package normalizes the behaviour of file fields by extending django.forms.fields.FileField and altering its behaviour to be as close to other input types as possible.
It is meant to be a drop-in replacement for django.forms.fields.FileField though some considerations are needed.
Versions
Testes in all combinations of:
Django |
Python |
|---|---|
1.7.11 |
2.7.10 |
1.8.8 |
3.4.3 |
1.9.1 |
3.5.1 |
Differences from FileField
TODO expand this section with details
Not much… The “Clear” checkbox is present in some situations where the ClearableFileInput does not render it.
Also, there is a new state for the field. In addition to “empty” and “initial” that traditional ClearableFileInput renders as a single HTML input element or as a double input with the link and label “Currently”, this widget also has a “Selected” state. This is similar to state with the “Currently” link, but it renders just the name of the file without the link. It is used in situations when form validation has failed, but the file field is ok and the file has been saved to temporary storage (cache).
Usage
In Models
A model field is provided to make use with models simpler. The only difference from the normal models.field.FileField is that it specifies a different form field class, namely NormalizedFileField.
from normalized_filefield.model_field import NormalizedFileField
class MyModel(models.Model):
a_file = NormalizedFileField(upload_to='media/place')
...
Note: In keeping with (dubious) tradition of how field classes are named in Django (forms.field.FileField vs models.fields.FileField), this package also names form and model field the same, NormalizedFileField.
In Forms
from normalized_filefield.form_field import NormalizedFileField
class MyModelForm(forms.ModelForm):
a_file = NormalizedFileField()
Widget normalized_filefield.widget.NormalizedFileInput is only meant to be used together with this form field class.
Changing the markup
The widget markup can be changed. Nothing different here then what regular ClearableFileInput provides. One difference is that template strings are made with the “format” syntax instead of the old “percent” syntax.
See normalized_filefield.widget.VerboseHTMLMixin for a very verbose markup option.
TODO expand this section
TODO
[ ] File cache storage seems not to clear automatically,
[ ] Styleable version, JS
[ ] Image Field
[ ] Clean up the widget and form classes (make more mixin-friendly structure)
Metadata
Release files for django-normalized-filefield 0.1.1
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-normalized-filefield-0.1.1.tar.gz | 9.0 kB | Without provenance | Details for django-normalized-filefield-0.1.1.tar.gz |
Release files / django-normalized-filefield-0.1.1.tar.gz
| Download URL | django-normalized-filefield-0.1.1.tar.gz |
|---|---|
| Size | 9.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3ee320a89f20b6975f566d02249f8fce1e45535305aa4f3f0ddbb8547739c40b
|
|
BLAKE2b-256 checksum How to use checksums |
47de64cd9a479d0dd84ec74ff88cdd59f6dccfafa9cf569c4e01a73b002a2cc0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for django-normalized-filefield 0.1.1
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.