Python django.forms 模块,FileInput() 实例源码

我们从Python开源项目中,提取了以下16个代码示例,用于说明如何使用django.forms.FileInput()

项目:wagtailmedia    作者:torchbox    | 项目源码 | 文件源码
def get_media_form(model):
    fields = model.admin_form_fields
    if 'collection' not in fields:
        # force addition of the 'collection' field, because leaving it out can
        # cause dubious results when multiple collections exist (e.g adding the
        # media to the root collection where the user may not have permission) -
        # and when only one collection exists, it will get hidden anyway.
        fields = list(fields) + ['collection']

    return modelform_factory(
        model,
        form=BaseMediaForm,
        fields=fields,
        widgets={
            'tags': widgets.AdminTagWidget,
            'file': forms.FileInput(),
            'thumbnail': forms.ClearableFileInput(),
        })
项目:tumanov_castleoaks    作者:Roamdev    | 项目源码 | 文件源码
def render(self, name, value, attrs=None):
        context = dict(
            value=value,
            input=super(forms.FileInput, self).render(name, value, attrs),
            for_label=attrs.get('id', ''),
            filename=os.path.basename(value.name) if value else '',
        )

        if self.is_initial(value) and not self.is_required:
            checkbox_name = self.clear_checkbox_name(name)
            checkbox_id = self.clear_checkbox_id(checkbox_name)
            context['clear'] = forms.CheckboxInput().render(
                checkbox_name, False, attrs={
                    'id': checkbox_id
                }
            )

        return mark_safe(render_to_string('file_field/admin/widget.html', context))
项目:wagtailvideos    作者:takeflight    | 项目源码 | 文件源码
def get_video_form(model):
    fields = model.admin_form_fields
    if 'collection' not in fields:
        # force addition of the 'collection' field, because leaving it out can
        # cause dubious results when multiple collections exist (e.g adding the
        # document to the root collection where the user may not have permission) -
        # and when only one collection exists, it will get hidden anyway.
        print('collection not found')
        fields = list(fields) + ['collection']

    return modelform_factory(
        model,
        form=BaseVideoForm,
        fields=fields,
        formfield_callback=formfield_for_dbfield,
        # set the 'file' widget to a FileInput rather than the default ClearableFileInput
        # so that when editing, we don't get the 'currently: ...' banner which is
        # a bit pointless here
        widgets={
            'tags': widgets.AdminTagWidget,
            'file': forms.FileInput(),
            'thumbnail': forms.FileInput(),
        })
项目:Wagtail-Document-Folders    作者:anteatersa    | 项目源码 | 文件源码
def get_document_form(model):
    fields = model.admin_form_fields
    if 'collection' not in fields:
        # force addition of the 'collection' field, because leaving it out can
        # cause dubious results when multiple collections exist (e.g adding the
        # document to the root collection where the user may not have permission) -
        # and when only one collection exists, it will get hidden anyway.
        fields = list(fields) + ['collection']

    return modelform_factory(
        model,
        form=BaseDocumentForm,
        fields=fields,
        widgets={
            'folder': forms.HiddenInput(),
            'tags': widgets.AdminTagWidget,
            'file': forms.FileInput()
        })
项目:planet-b-saleor    作者:planet-b    | 项目源码 | 文件源码
def is_file(field):
    return isinstance(field.field.widget, forms.FileInput)
项目:mooder    作者:phith0n    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        super(ProfileForm, self).__init__(*args, **kwargs)
        self['mugshot'].field.widget = forms.FileInput()
        self['description'].field.widget = forms.Textarea(attrs={'rows': 3})
项目:multiuploader    作者:vinaypost    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        multiuploader_settings = getattr(settings, "MULTIUPLOADER_FORMS_SETTINGS",
                                         DEFAULTS.MULTIUPLOADER_FORMS_SETTINGS)
        media_type = kwargs.get('data', {}).get("media_type", "default")
        options = {
            'maxFileSize': multiuploader_settings[media_type]["MAX_FILE_SIZE"],
            'acceptFileTypes': format_file_extensions(multiuploader_settings[media_type]["FILE_TYPES"]),
            'maxNumberOfFiles': multiuploader_settings[media_type]["MAX_FILE_NUMBER"],
            'allowedContentTypes': list(map(str.lower, multiuploader_settings[media_type]["CONTENT_TYPES"])),
            'autoUpload': multiuploader_settings[media_type]["AUTO_UPLOAD"]
        }

        self.check_extension = True
        self.check_content_type = True

        if multiuploader_settings[media_type]["FILE_TYPES"] == '*':
            self.check_extension = False
            options.update({'acceptFileTypes': []})

        if multiuploader_settings[media_type]["CONTENT_TYPES"] == '*':
            self.check_content_type = False
            options.pop('allowedContentTypes')

        self._options = options
        self.options = json.dumps(options)

        super(MultiUploadForm, self).__init__(*args, **kwargs)

        self.fields["file"].widget = forms.FileInput(attrs={'multiple': True})
项目:jiango    作者:yefei    | 项目源码 | 文件源码
def is_file(field):
    return isinstance(field.field.widget, forms.FileInput)
项目:jiango    作者:yefei    | 项目源码 | 文件源码
def is_file(field):
    return isinstance(field.field.widget, forms.FileInput)
项目:Wagtail-Image-Folders    作者:anteatersa    | 项目源码 | 文件源码
def test_file_field(self):
        form = get_image_form(WagtailImage)

        self.assertIsInstance(form.base_fields['file'], WagtailImageField)
        self.assertIsInstance(form.base_fields['file'].widget, forms.FileInput)
项目:Wagtail-Image-Folders    作者:anteatersa    | 项目源码 | 文件源码
def get_image_form(model):
    fields = model.admin_form_fields
    if 'collection' not in fields:
        # force addition of the 'collection' field, because leaving it out can
        # cause dubious results when multiple collections exist (e.g adding the
        # document to the root collection where the user may not have permission) -
        # and when only one collection exists, it will get hidden anyway.
        fields = list(fields) + ['collection']

    return modelform_factory(
        model,
        form=BaseImageForm,
        fields=fields,
        formfield_callback=formfield_for_dbfield,
        # set the 'file' widget to a FileInput rather than the default ClearableFileInput
        # so that when editing, we don't get the 'currently: ...' banner which is
        # a bit pointless here
        widgets={
            'tags': widgets.AdminTagWidget,
            'file': forms.FileInput(),
            'folder': forms.HiddenInput(),
            'focal_point_x': forms.HiddenInput(attrs={'class': 'focal_point_x'}),
            'focal_point_y': forms.HiddenInput(attrs={'class': 'focal_point_y'}),
            'focal_point_width': forms.HiddenInput(attrs={'class': 'focal_point_width'}),
            'focal_point_height': forms.HiddenInput(attrs={'class': 'focal_point_height'}),
        })
项目:Wagtail-Image-Folders    作者:anteatersa    | 项目源码 | 文件源码
def get_folder_form(model):
    fields = model.admin_form_fields

    return modelform_factory(
        model,
        form=ImageFolderForm,
        fields=fields,
        formfield_callback=formfield_for_dbfield,
        # set the 'file' widget to a FileInput rather than the default ClearableFileInput
        # so that when editing, we don't get the 'currently: ...' banner which is
        # a bit pointless here
        widgets={
            'title': forms.TextInput(),
        })
项目:Wagtail-Document-Folders    作者:anteatersa    | 项目源码 | 文件源码
def get_document_multi_form(model):
    return modelform_factory(
        model,
        form=BaseDocumentForm,
        fields=['title', 'collection', 'tags'],
        widgets={
            'folder': forms.HiddenInput(),
            'tags': widgets.AdminTagWidget,
            'file': forms.FileInput()
        })
项目:Wagtail-Document-Folders    作者:anteatersa    | 项目源码 | 文件源码
def get_folder_form(model):
    fields = model.admin_form_fields

    return modelform_factory(
        model,
        form=DocumentFolderForm,
        fields=fields,
        #formfield_callback=formfield_for_dbfield,
        # set the 'file' widget to a FileInput rather than the default ClearableFileInput
        # so that when editing, we don't get the 'currently: ...' banner which is
        # a bit pointless here
        widgets={
            'title': forms.TextInput(),
        })
项目:django_postgres_extensions    作者:primal100    | 项目源码 | 文件源码
def test_needs_multipart_true(self):
        """
        needs_multipart_form should be True if any widgets need it.
        """
        widget = forms.NestedFormWidget(
            ('text', 'file'),
            (TextInput(), FileInput())
        )
        self.assertTrue(widget.needs_multipart_form)
项目:netbox    作者:digitalocean    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        super(BootstrapMixin, self).__init__(*args, **kwargs)

        exempt_widgets = [forms.CheckboxInput, forms.ClearableFileInput, forms.FileInput, forms.RadioSelect]

        for field_name, field in self.fields.items():
            if field.widget.__class__ not in exempt_widgets:
                css = field.widget.attrs.get('class', '')
                field.widget.attrs['class'] = ' '.join([css, 'form-control']).strip()
            if field.required and not isinstance(field.widget, forms.FileInput):
                field.widget.attrs['required'] = 'required'
            if 'placeholder' not in field.widget.attrs:
                field.widget.attrs['placeholder'] = field.label