当前位置: 首页>>代码示例>>Python>>正文


Python forms.FileInput方法代码示例

本文整理汇总了Python中django.forms.FileInput方法的典型用法代码示例。如果您正苦于以下问题:Python forms.FileInput方法的具体用法?Python forms.FileInput怎么用?Python forms.FileInput使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.forms的用法示例。


在下文中一共展示了forms.FileInput方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import FileInput [as 别名]
def __init__(self, *args, **kwargs):
        key_type = kwargs.pop('key_type', None)
        value = kwargs.pop('value', None)
        super(EditKey, self).__init__(*args, **kwargs)

        if key_type == 'rich-text':
            self.fields['value'].widget = SummernoteWidget()
        elif key_type == 'boolean':
            self.fields['value'].widget = forms.CheckboxInput()
        elif key_type == 'integer':
            self.fields['value'].widget = forms.TextInput(attrs={'type': 'number'})
        elif key_type == 'file' or key_type == 'journalthumb':
            self.fields['value'].widget = forms.FileInput()
        elif key_type == 'text':
            self.fields['value'].widget = forms.Textarea()
        else:
            self.fields['value'].widget.attrs['size'] = '100%'

        self.fields['value'].initial = value
        self.fields['value'].required = False 
开发者ID:BirkbeckCTP,项目名称:janeway,代码行数:22,代码来源:forms.py

示例2: get_image_form

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import FileInput [as 别名]
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(),
            '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'}),
        }) 
开发者ID:wagtail,项目名称:wagtail,代码行数:27,代码来源:forms.py

示例3: get_document_form

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import FileInput [as 别名]
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={
            'tags': widgets.AdminTagWidget,
            'file': forms.FileInput()
        }) 
开发者ID:wagtail,项目名称:wagtail,代码行数:19,代码来源:forms.py

示例4: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import FileInput [as 别名]
def __init__(self, allowed_extensions, *args, **kwargs):
        super().__init__(*args, **kwargs)

        accept = ",".join(
            [".{}".format(x) for x in allowed_extensions]
        )
        self.fields["import_file"].widget = forms.FileInput(
            attrs={"accept": accept}
        )

        uppercased_extensions = [x.upper() for x in allowed_extensions]
        allowed_extensions_text = ", ".join(uppercased_extensions)
        help_text = _(
            "Supported formats: %(supported_formats)s."
        ) % {
            'supported_formats': allowed_extensions_text,
        }
        self.fields["import_file"].help_text = help_text 
开发者ID:wagtail,项目名称:wagtail,代码行数:20,代码来源:forms.py

示例5: get_video_form

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import FileInput [as 别名]
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(),
        }) 
开发者ID:neon-jungle,项目名称:wagtailvideos,代码行数:25,代码来源:forms.py

示例6: is_file

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import FileInput [as 别名]
def is_file(field):
    return isinstance(field.field.widget, forms.FileInput) 
开发者ID:OpenMDM,项目名称:OpenMDM,代码行数:4,代码来源:bootstrap.py

示例7: test_file_field

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import FileInput [as 别名]
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) 
开发者ID:wagtail,项目名称:wagtail,代码行数:7,代码来源:tests.py

示例8: get_document_multi_form

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import FileInput [as 别名]
def get_document_multi_form(model):
    fields = [field for field in model.admin_form_fields if field != 'file']
    if 'collection' not in fields:
        fields.append('collection')

    return modelform_factory(
        model,
        form=BaseDocumentForm,
        fields=fields,
        widgets={
            'tags': widgets.AdminTagWidget,
            'file': forms.FileInput()
        }) 
开发者ID:wagtail,项目名称:wagtail,代码行数:15,代码来源:forms.py

示例9: is_fileinput

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import FileInput [as 别名]
def is_fileinput(boundfield):
    """Return True if this field's widget is a FileField."""
    return isinstance(boundfield.field.widget, forms.FileInput) 
开发者ID:eventoL,项目名称:eventoL,代码行数:5,代码来源:filters.py

示例10: test_is_fileinput_with_FileInput_should_return_true

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import FileInput [as 别名]
def test_is_fileinput_with_FileInput_should_return_true(mocker):
    boundfield = mocker.Mock()
    boundfield.field = mocker.Mock()
    boundfield.field.widget = forms.FileInput()
    assert filters.is_fileinput(boundfield) 
开发者ID:eventoL,项目名称:eventoL,代码行数:7,代码来源:test_templatetag_filters.py

示例11: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import FileInput [as 别名]
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}) 
开发者ID:phith0n,项目名称:mooder,代码行数:6,代码来源:forms.py

示例12: test_render

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import FileInput [as 别名]
def test_render(self):
        """
        FileInput widgets never render the value attribute. The old value
        isn't useful if a form is updated or an error occurred.
        """
        self.check_html(self.widget, 'email', 'test@example.com', html='<input type="file" name="email">')
        self.check_html(self.widget, 'email', '', html='<input type="file" name="email">')
        self.check_html(self.widget, 'email', None, html='<input type="file" name="email">') 
开发者ID:nesdis,项目名称:djongo,代码行数:10,代码来源:test_fileinput.py

示例13: registerImportHandler

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import FileInput [as 别名]
def registerImportHandler(cls, handler):
        class Panel(ConcealedPanel):
            def _show(self):
                page = getattr(self, 'instance', None)
                if not page:
                    return False
                hasReq = hasattr(page, '__joyous_edit_request')
                if not hasReq:
                    return False
                # only a user with edit and publishing rights should be able
                # to import iCalendar files
                perms = page.permissions_for_user(self.request.user)
                return perms.can_publish() and perms.can_edit()

        cls.importHandler = handler
        uploadWidget = forms.FileInput(attrs={'accept': "text/calendar,"
                                                        "application/zip,"
                                                        ".ics,.zip"})
        cls.declared_fields['upload'] = forms.FileField(
                                            label=_("Upload"),
                                            required=False,
                                            widget=uploadWidget)
        cls.declared_fields['utc2local'] = forms.BooleanField(
                                            label=_("Convert UTC to localtime?"),
                                            required=False,
                                            initial=True)
        CalendarPage.settings_panels.append(Panel([
              FieldPanel('upload'),
              FieldPanel('utc2local'),
            ], heading=_("Import"))) 
开发者ID:linuxsoftware,项目名称:ls.joyous,代码行数:32,代码来源:calendar.py

示例14: _get_css_classes

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import FileInput [as 别名]
def _get_css_classes(field):
    """
    Helper function which returns the appropriate (Bootstrap) CSS classes for rendering an input field and
    its `<div>` container.

    Returns:
        A tuple of the form `(div_classes, field_classes, iterate_subfields, wrap_in_label)`.
        `iterate_subfields` is a bool indicating that the field should be rendered by iterating over its
        sub-fields (i.e. over itself) and wrapping them in containers with `field_classes`. This is required
        for multiple radios and checkboxes belonging together.
        `wrap_in_label` is a bool that specifies whether the input field should be placed inside the
        associated `<label>`, as required by Bootstrap for checkboxes.
    """

    div_classes = []
    field_classes = []
    iterate_subfields = False
    wrap_in_label = False

    if field.errors:
        div_classes.append('has-error')

    widget = field.field.widget

    if isinstance(widget, CheckboxInput):
        div_classes.append('checkbox')
        wrap_in_label = True
    elif isinstance(widget, CheckboxSelectMultiple):
        div_classes.append('form-group')
        field_classes.append('checkbox')
        iterate_subfields = True
    elif isinstance(widget, RadioSelect):
        div_classes.append('form-group')
        field_classes.append('radio')
        iterate_subfields = True
    elif isinstance(widget, FileInput):
        pass
    elif isinstance(widget, MultiWidget):
        div_classes.append('form-group')
        div_classes.append('form-inline')
        field_classes.append('form-control')
    else:
        div_classes.append('form-group')
        field_classes.append('form-control')

    return (div_classes, field_classes, iterate_subfields, wrap_in_label) 
开发者ID:fausecteam,项目名称:ctf-gameserver,代码行数:48,代码来源:form_as_div.py


注:本文中的django.forms.FileInput方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。