From 23bf4ad87f86f44a5ecf9aea722ced76fe7b7fdf Mon Sep 17 00:00:00 2001 From: Дилян Палаузов Date: Mon, 13 Nov 2017 16:15:49 -0500 Subject: Fixed #28795 -- Removed 'not in' checks and used dict.setdefault(). --- django/forms/boundfield.py | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) (limited to 'django/forms') diff --git a/django/forms/boundfield.py b/django/forms/boundfield.py index 6acae1c59b..dba54e588a 100644 --- a/django/forms/boundfield.py +++ b/django/forms/boundfield.py @@ -87,20 +87,10 @@ class BoundField: attrs = attrs or {} attrs = self.build_widget_attrs(attrs, widget) - auto_id = self.auto_id - if auto_id and 'id' not in attrs and 'id' not in widget.attrs: - if not only_initial: - attrs['id'] = auto_id - else: - attrs['id'] = self.html_initial_id - - if not only_initial: - name = self.html_name - else: - name = self.html_initial_name - + if self.auto_id and 'id' not in widget.attrs: + attrs.setdefault('id', self.html_initial_id if only_initial else self.auto_id) return widget.render( - name=name, + name=self.html_initial_name if only_initial else self.html_name, value=self.value(), attrs=attrs, renderer=self.form.renderer, -- cgit v1.3