本文整理汇总了Python中django.contrib.admin.widgets.AdminFileWidget方法的典型用法代码示例。如果您正苦于以下问题:Python widgets.AdminFileWidget方法的具体用法?Python widgets.AdminFileWidget怎么用?Python widgets.AdminFileWidget使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.admin.widgets
的用法示例。
在下文中一共展示了widgets.AdminFileWidget方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_render
# 需要导入模块: from django.contrib.admin import widgets [as 别名]
# 或者: from django.contrib.admin.widgets import AdminFileWidget [as 别名]
def test_render(self):
w = widgets.AdminFileWidget()
self.assertHTMLEqual(
w.render('test', self.album.cover_art),
'<p class="file-upload">Currently: <a href="%(STORAGE_URL)salbums/'
r'hybrid_theory.jpg">albums\hybrid_theory.jpg</a> '
'<span class="clearable-file-input">'
'<input type="checkbox" name="test-clear" id="test-clear_id"> '
'<label for="test-clear_id">Clear</label></span><br>'
'Change: <input type="file" name="test"></p>' % {
'STORAGE_URL': default_storage.url(''),
},
)
self.assertHTMLEqual(
w.render('test', SimpleUploadedFile('test', b'content')),
'<input type="file" name="test">',
)
示例2: _construct_form
# 需要导入模块: from django.contrib.admin import widgets [as 别名]
# 或者: from django.contrib.admin.widgets import AdminFileWidget [as 别名]
def _construct_form(self, i, **kwargs):
form = super(SponsorBenefitsInlineFormSet, self)._construct_form(
i, **kwargs
)
# only include the relevant data fields for this benefit type
fields = form.instance.data_fields()
form.fields = dict(
(k, v) for (k, v) in form.fields.items() if k in fields + ["id"]
)
for field in fields:
# don't need a label, the form template will label it
# with the benefit name
form.fields[field].label = ""
# provide word limit as help_text
if (
form.instance.benefit.type == "text"
and form.instance.max_words
):
form.fields[field].help_text = (
_("maximum %s words") % form.instance.max_words
)
# use admin file widget that shows currently uploaded file
if field == "upload":
form.fields[field].widget = AdminFileWidget()
return form
示例3: formfield
# 需要导入模块: from django.contrib.admin import widgets [as 别名]
# 或者: from django.contrib.admin.widgets import AdminFileWidget [as 别名]
def formfield(self, **kwargs):
"""Return a formfield."""
# This is a fairly standard way to set up some defaults
# while letting the caller override them.
defaults = {}
if self.ppoi_field:
defaults['form_class'] = SizedImageCenterpointClickDjangoAdminField
if kwargs.get('widget') is AdminFileWidget:
# Ensuring default admin widget is skipped (in favor of using
# SizedImageCenterpointClickDjangoAdminField's default widget as
# the default widget choice for use in the admin).
# This is for two reasons:
# 1. To prevent 'typical' admin users (those who want to use
# the PPOI 'click' widget by default) from having to
# specify a formfield_overrides for each ModelAdmin class
# used by each model that has a VersatileImageField.
# 2. If a VersatileImageField does not have a ppoi_field specified
# it will 'fall back' to a ClearableFileInput anyways.
# If admin users do, in fact, want to force use of the
# AdminFileWidget they can simply subclass AdminFileWidget and
# specify it in their ModelAdmin.formfield_overrides (though,
# if that's the case, why are they using VersatileImageField in
# the first place?)
del kwargs['widget']
defaults.update(kwargs)
return super(VersatileImageField, self).formfield(**defaults)
示例4: test_FileField
# 需要导入模块: from django.contrib.admin import widgets [as 别名]
# 或者: from django.contrib.admin.widgets import AdminFileWidget [as 别名]
def test_FileField(self):
self.assertFormfield(Album, 'cover_art', widgets.AdminFileWidget)
示例5: test_inheritance
# 需要导入模块: from django.contrib.admin import widgets [as 别名]
# 或者: from django.contrib.admin.widgets import AdminFileWidget [as 别名]
def test_inheritance(self):
self.assertFormfield(Album, 'backside_art', widgets.AdminFileWidget)
示例6: test_render_required
# 需要导入模块: from django.contrib.admin import widgets [as 别名]
# 或者: from django.contrib.admin.widgets import AdminFileWidget [as 别名]
def test_render_required(self):
widget = widgets.AdminFileWidget()
widget.is_required = True
self.assertHTMLEqual(
widget.render('test', self.album.cover_art),
'<p class="file-upload">Currently: <a href="%(STORAGE_URL)salbums/'
r'hybrid_theory.jpg">albums\hybrid_theory.jpg</a><br>'
'Change: <input type="file" name="test"></p>' % {
'STORAGE_URL': default_storage.url(''),
},
)