diff --git a/django/contrib/admin/widgets.py b/django/contrib/admin/widgets.py index bf597384ad..669c715123 100644 --- a/django/contrib/admin/widgets.py +++ b/django/contrib/admin/widgets.py @@ -34,7 +34,7 @@ class FilteredSelectMultiple(forms.SelectMultiple): self.is_stacked = is_stacked super(FilteredSelectMultiple, self).__init__(attrs, choices) - def get_context(self, name, value, attrs=None): + def get_context(self, name, value, attrs): context = super(FilteredSelectMultiple, self).get_context(name, value, attrs) context['widget']['attrs']['class'] = 'selectfilter' if self.is_stacked: @@ -132,7 +132,7 @@ class ForeignKeyRawIdWidget(forms.TextInput): self.db = using super(ForeignKeyRawIdWidget, self).__init__(attrs) - def get_context(self, name, value, attrs=None): + def get_context(self, name, value, attrs): context = super(ForeignKeyRawIdWidget, self).get_context(name, value, attrs) rel_to = self.rel.model if rel_to in self.admin_site._registry: @@ -199,7 +199,7 @@ class ManyToManyRawIdWidget(ForeignKeyRawIdWidget): """ template_name = 'admin/widgets/many_to_many_raw_id.html' - def get_context(self, name, value, attrs=None): + def get_context(self, name, value, attrs): context = super(ManyToManyRawIdWidget, self).get_context(name, value, attrs) if self.rel.model in self.admin_site._registry: # The related object is registered with the same AdminSite @@ -268,7 +268,7 @@ class RelatedFieldWidgetWrapper(forms.Widget): return reverse("admin:%s_%s_%s" % (info + (action,)), current_app=self.admin_site.name, args=args) - def get_context(self, name, value, attrs=None): + def get_context(self, name, value, attrs): from django.contrib.admin.views.main import IS_POPUP_VAR, TO_FIELD_VAR rel_opts = self.rel.model._meta info = (rel_opts.app_label, rel_opts.model_name) diff --git a/django/contrib/gis/admin/widgets.py b/django/contrib/gis/admin/widgets.py index 014b3ad818..2d20ea2132 100644 --- a/django/contrib/gis/admin/widgets.py +++ b/django/contrib/gis/admin/widgets.py @@ -15,7 +15,7 @@ class OpenLayersWidget(Textarea): """ Renders an OpenLayers map using the WKT of the geometry. """ - def get_context(self, name, value, attrs=None): + def get_context(self, name, value, attrs): # Update the template parameters with any attributes passed in. if attrs: self.params.update(attrs) diff --git a/django/contrib/gis/forms/widgets.py b/django/contrib/gis/forms/widgets.py index 1a03747beb..e9518f4e7e 100644 --- a/django/contrib/gis/forms/widgets.py +++ b/django/contrib/gis/forms/widgets.py @@ -42,7 +42,7 @@ class BaseGeometryWidget(Widget): logger.error("Error creating geometry from value '%s' (%s)", value, err) return None - def get_context(self, name, value, attrs=None): + def get_context(self, name, value, attrs): # If a string reaches here (via a validation error on another # field) then just reconstruct the Geometry. if value and isinstance(value, six.string_types): diff --git a/django/forms/widgets.py b/django/forms/widgets.py index 90ff7bff55..686c092795 100644 --- a/django/forms/widgets.py +++ b/django/forms/widgets.py @@ -201,7 +201,7 @@ class Widget(six.with_metaclass(RenameWidgetMethods)): return formats.localize_input(value) return force_text(value) - def get_context(self, name, value, attrs=None): + def get_context(self, name, value, attrs): context = {} context['widget'] = { 'name': name, @@ -271,7 +271,7 @@ class Input(Widget): self.input_type = attrs.pop('type', self.input_type) super(Input, self).__init__(attrs) - def get_context(self, name, value, attrs=None): + def get_context(self, name, value, attrs): context = super(Input, self).get_context(name, value, attrs) context['widget']['type'] = self.input_type return context @@ -323,7 +323,7 @@ class MultipleHiddenInput(HiddenInput): """ template_name = 'django/forms/widgets/multiple_hidden.html' - def get_context(self, name, value, attrs=None): + def get_context(self, name, value, attrs): context = super(MultipleHiddenInput, self).get_context(name, value, attrs) final_attrs = context['widget']['attrs'] id_ = context['widget']['attrs'].get('id') @@ -405,7 +405,7 @@ class ClearableFileInput(FileInput): if self.is_initial(value): return value - def get_context(self, name, value, attrs=None): + def get_context(self, name, value, attrs): context = super(ClearableFileInput, self).get_context(name, value, attrs) checkbox_name = self.clear_checkbox_name(name) checkbox_id = self.clear_checkbox_id(checkbox_name) @@ -502,7 +502,7 @@ class CheckboxInput(Input): return return force_text(value) - def get_context(self, name, value, attrs=None): + def get_context(self, name, value, attrs): if self.check_test(value): if attrs is None: attrs = {} @@ -622,7 +622,7 @@ class ChoiceWidget(Widget): 'template_name': self.option_template_name, } - def get_context(self, name, value, attrs=None): + def get_context(self, name, value, attrs): context = super(ChoiceWidget, self).get_context(name, value, attrs) context['widget']['optgroups'] = self.optgroups(name, context['widget']['value'], attrs) context['wrap_label'] = True @@ -667,7 +667,7 @@ class Select(ChoiceWidget): checked_attribute = {'selected': True} option_inherits_attrs = False - def get_context(self, name, value, attrs=None): + def get_context(self, name, value, attrs): context = super(Select, self).get_context(name, value, attrs) if self.allow_multiple_selected: context['widget']['attrs']['multiple'] = 'multiple' @@ -789,7 +789,7 @@ class MultiWidget(Widget): def is_hidden(self): return all(w.is_hidden for w in self.widgets) - def get_context(self, name, value, attrs=None): + def get_context(self, name, value, attrs): context = super(MultiWidget, self).get_context(name, value, attrs) if self.is_localized: for widget in self.widgets: @@ -941,7 +941,7 @@ class SelectDateWidget(Widget): self.month_none_value = self.none_value self.day_none_value = self.none_value - def get_context(self, name, value, attrs=None): + def get_context(self, name, value, attrs): context = super(SelectDateWidget, self).get_context(name, value, attrs) date_context = {} year_choices = [(i, i) for i in self.years] diff --git a/docs/ref/forms/widgets.txt b/docs/ref/forms/widgets.txt index c17877545b..077d4617ad 100644 --- a/docs/ref/forms/widgets.txt +++ b/docs/ref/forms/widgets.txt @@ -241,7 +241,7 @@ foundation for custom widgets. In older versions, this method is a private API named ``_format_value()``. The old name will work until Django 2.0. - .. method:: get_context(name, value, attrs=None) + .. method:: get_context(name, value, attrs) .. versionadded:: 1.11 @@ -386,7 +386,7 @@ foundation for custom widgets. It provides some custom context: - .. method:: get_context(name, value, attrs=None) + .. method:: get_context(name, value, attrs) In addition to the ``'widget'`` key described in :meth:`Widget.get_context`, ``MultiValueWidget`` adds a