Python django.contrib.admin.widgets.AdminFileWidget() Examples
The following are 6
code examples of django.contrib.admin.widgets.AdminFileWidget().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.contrib.admin.widgets
, or try the search function
.
Example #1
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 6 votes |
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">', )
Example #2
Source File: forms.py From conf_site with MIT License | 5 votes |
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
Example #3
Source File: fields.py From django-versatileimagefield with MIT License | 5 votes |
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)
Example #4
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_FileField(self): self.assertFormfield(Album, 'cover_art', widgets.AdminFileWidget)
Example #5
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_inheritance(self): self.assertFormfield(Album, 'backside_art', widgets.AdminFileWidget)
Example #6
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
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(''), }, )