Skip to content

Fields

hypha.apply.stream_forms.fields

FileFieldWidgetMixin

media

media()
Source code in hypha/apply/stream_forms/fields.py
@cached_property
def media(self):
    return Media(
        css={
            "all": [
                static("file_form/file_form.css"),
            ]
        },
        js=[
            static("file_form/file_form.js"),
            static("js/apply/file-uploads.js"),
        ],
    )

MultiFileFieldWidget

Bases: FileFieldWidgetMixin, UploadMultipleWidget

MultiFileField

Bases: MultipleUploadedFileField

widget class-attribute instance-attribute

clean

clean(value, initial)
Source code in hypha/apply/stream_forms/fields.py
def clean(self, value, initial):
    if not value:
        return []
    old_files = [
        file
        for file in value
        if hasattr(file, "is_placeholder") and file.is_placeholder
    ]
    new_files = [
        file
        for file in value
        if hasattr(file, "is_placeholder") and not file.is_placeholder
    ]
    if not new_files and initial and len(old_files) == len(initial):
        return initial

    files = [
        FileField(
            validators=[
                FileExtensionValidator(
                    allowed_extensions=settings.FILE_ALLOWED_EXTENSIONS
                )
            ]
        ).clean(file, initial)
        for file in value
    ]

    return files

widget_attrs

widget_attrs(widget)
Source code in hypha/apply/stream_forms/fields.py
def widget_attrs(self, widget):
    attrs = super().widget_attrs(widget)
    if isinstance(widget, MultiFileFieldWidget) and "accept" not in widget.attrs:
        attrs.setdefault("accept", settings.FILE_ACCEPT_ATTR_VALUE)
    return attrs

SingleFileFieldWidget

Bases: FileFieldWidgetMixin, UploadWidget

SingleFileField

Bases: UploadedFileField

widget class-attribute instance-attribute

clean

clean(value, initial)
Source code in hypha/apply/stream_forms/fields.py
def clean(self, value, initial):
    if not value:
        return
    if hasattr(value, "is_placeholder") and value.is_placeholder and initial:
        return initial
    validator = FileExtensionValidator(
        allowed_extensions=settings.FILE_ALLOWED_EXTENSIONS
    )
    file = FileField(validators=[validator]).clean(value, initial)
    return file

widget_attrs

widget_attrs(widget)
Source code in hypha/apply/stream_forms/fields.py
def widget_attrs(self, widget):
    attrs = super().widget_attrs(widget)
    if isinstance(widget, SingleFileFieldWidget) and "accept" not in widget.attrs:
        attrs.setdefault("accept", settings.FILE_ACCEPT_ATTR_VALUE)
    return attrs