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


Python widgets.AdminFileWidget方法代码示例

本文整理汇总了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">',
        ) 
开发者ID:nesdis,项目名称:djongo,代码行数:19,代码来源:tests.py

示例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 
开发者ID:pydata,项目名称:conf_site,代码行数:32,代码来源:forms.py

示例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) 
开发者ID:respondcreate,项目名称:django-versatileimagefield,代码行数:28,代码来源:fields.py

示例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) 
开发者ID:nesdis,项目名称:djongo,代码行数:4,代码来源:tests.py

示例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) 
开发者ID:nesdis,项目名称:djongo,代码行数:4,代码来源:tests.py

示例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(''),
            },
        ) 
开发者ID:nesdis,项目名称:djongo,代码行数:13,代码来源:tests.py


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