Package: django-normalized-filefield
File field that behaves as close to other fields as possible.0.1.1Whaat?This!Screenshots(animated gif)Whaaaaat?! I don get it!Basic idea: I want to handle file inputsno differentlyfrom 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 extendingdjango.forms.fields.FileFieldand altering its behaviour to be as
close to other input types as possible.It is meant to be a drop-in replacement fordjango.forms.fields.FileFieldthough some considerations are needed.VersionsTestes in all combinations of:DjangoPython1.7.112.7.101.8.83.4.31.9.13.5.1Differences from FileFieldTODO expand this section with detailsNot much… The “Clear” checkbox is present in some situations where theClearableFileInputdoes not render it.Also, there is a new state for the field. In addition to “empty” and
“initial” that traditionalClearableFileInputrenders 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).UsageIn ModelsA model field is provided to make use with models simpler. The only
difference from the normalmodels.field.FileFieldis that it
specifies a different form field class, namelyNormalizedFileField.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.FileFieldvsmodels.fields.FileField),
this package also names form and model field the same,NormalizedFileField.In Formsfrom normalized_filefield.form_field import NormalizedFileField

class MyModelForm(forms.ModelForm):
    a_file = NormalizedFileField()Widgetnormalized_filefield.widget.NormalizedFileInputis only meant
to be used together with this form field class.Changing the markupThe widget markup can be changed. Nothing different here then what
regularClearableFileInputprovides. One difference is that template
strings are made with the “format” syntax instead of the old “percent”
syntax.Seenormalized_filefield.widget.VerboseHTMLMixinfor a very verbose
markup option.TODO expand this sectionTODO[ ] 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)