Python django.forms.widgets.ClearableFileInput() Examples
The following are 5
code examples of django.forms.widgets.ClearableFileInput().
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.forms.widgets
, or try the search function
.
Example #1
Source File: widgets.py From freedomvote with GNU General Public License v3.0 | 6 votes |
def render(self, name, value, attrs=None,): substitutions = { 'clear_checkbox_label': self.clear_checkbox_label, 'initial' : '<img class="img-responsive img-thumbnail" width="%s" src="%s">' % ( force_text('100%'), force_text(get_thumbnailer(value)['medium'].url if value and hasattr(value, 'url') else static('images/placeholder.svg')) ) } template = '%(initial)s%(input)s' substitutions['input'] = super(ClearableFileInput, self).render(name, value, attrs) if not self.is_required: template = '%(initial)s%(clear_template)s%(input)s' checkbox_name = self.clear_checkbox_name(name) checkbox_id = self.clear_checkbox_id(checkbox_name) substitutions['clear_checkbox_name'] = conditional_escape(checkbox_name) substitutions['clear_checkbox_id'] = conditional_escape(checkbox_id) substitutions['clear'] = CheckboxInput().render(checkbox_name, False, attrs={'id': checkbox_id}) substitutions['clear_template'] = self.clear_checkbox_name(checkbox_name) return mark_safe(template % substitutions)
Example #2
Source File: widgets.py From django-versatileimagefield with MIT License | 5 votes |
def get_context(self, name, value, attrs): """Get the context to render this widget with.""" if self.has_template_widget_rendering: context = super(ClearableFileInputWithImagePreview, self).get_context(name, value, attrs) else: # Build the context manually. context = {} context['widget'] = { 'name': name, 'is_hidden': self.is_hidden, 'required': self.is_required, 'value': self._format_value(value), 'attrs': self.build_attrs(self.attrs, attrs), 'template_name': self.template_name, 'type': self.input_type, } # It seems Django 1.11's ClearableFileInput doesn't add everything to the 'widget' key, so we can't use it # in MultiWidget. Add it manually here. checkbox_name = self.clear_checkbox_name(name) checkbox_id = self.clear_checkbox_id(checkbox_name) context['widget'].update({ 'checkbox_name': checkbox_name, 'checkbox_id': checkbox_id, 'is_initial': self.is_initial(value), 'input_text': self.input_text, 'initial_text': self.initial_text, 'clear_checkbox_label': self.clear_checkbox_label, }) if value and hasattr(value, "url"): context['widget'].update({ 'hidden_field_id': self.get_hidden_field_id(name), 'point_stage_id': self.get_point_stage_id(name), 'ppoi_id': self.get_ppoi_id(name), 'sized_url': self.get_sized_url(value), 'image_preview_id': self.image_preview_id(name), }) return context
Example #3
Source File: widgets.py From django-versatileimagefield with MIT License | 5 votes |
def __init__(self, widgets=None, attrs=None): widgets = [ ClearableFileInput(attrs=None), Select(attrs=attrs, choices=CENTERPOINT_CHOICES) ] super(VersatileImagePPOISelectWidget, self).__init__(widgets, attrs)
Example #4
Source File: widgets.py From adhocracy4 with GNU Affero General Public License v3.0 | 5 votes |
def value_from_datadict(self, data, files, name): """ Modify value_from_datadict, so that delete takes precedence over upload. """ file_value = super(widgets.ClearableFileInput, self)\ .value_from_datadict(data, files, name) checkbox_value = widgets.CheckboxInput()\ .value_from_datadict(data, files, self.clear_checkbox_name(name)) if not self.is_required and checkbox_value: return False return file_value
Example #5
Source File: widgets.py From freedomvote with GNU General Public License v3.0 | 5 votes |
def __init__(self, *args, **kwargs): super(ClearableFileInput, self).__init__(*args, **kwargs) self.template_name = "core/custom_file_input.html"