當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。