本文整理匯總了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(''),
},
)