本文整理汇总了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
示例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'}),
})
示例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()
})
示例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
示例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(),
})
示例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)
示例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)
示例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()
})
示例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)
示例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)
示例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})
示例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">')
示例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")))
示例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)