Fixed #28795 -- Removed 'not in' checks and used dict.setdefault().
This commit is contained in:
parent
a2ec1e6b2d
commit
23bf4ad87f
|
@ -8,5 +8,4 @@ class GISConfig(AppConfig):
|
||||||
verbose_name = _("GIS")
|
verbose_name = _("GIS")
|
||||||
|
|
||||||
def ready(self):
|
def ready(self):
|
||||||
if 'geojson' not in serializers.BUILTIN_SERIALIZERS:
|
serializers.BUILTIN_SERIALIZERS.setdefault('geojson', 'django.contrib.gis.serializers.geojson')
|
||||||
serializers.BUILTIN_SERIALIZERS['geojson'] = "django.contrib.gis.serializers.geojson"
|
|
||||||
|
|
|
@ -255,9 +255,8 @@ class GeometryField(BaseSpatialField):
|
||||||
'srid': self.srid,
|
'srid': self.srid,
|
||||||
}
|
}
|
||||||
defaults.update(kwargs)
|
defaults.update(kwargs)
|
||||||
if (self.dim > 2 and 'widget' not in kwargs and
|
if self.dim > 2 and not getattr(defaults['form_class'].widget, 'supports_3d', False):
|
||||||
not getattr(defaults['form_class'].widget, 'supports_3d', False)):
|
defaults.setdefault('widget', forms.Textarea)
|
||||||
defaults['widget'] = forms.Textarea
|
|
||||||
return super().formfield(**defaults)
|
return super().formfield(**defaults)
|
||||||
|
|
||||||
def select_format(self, compiler, sql, params):
|
def select_format(self, compiler, sql, params):
|
||||||
|
|
|
@ -381,27 +381,14 @@ class GDALRaster(GDALRasterBase):
|
||||||
consult the GDAL_RESAMPLE_ALGORITHMS constant.
|
consult the GDAL_RESAMPLE_ALGORITHMS constant.
|
||||||
"""
|
"""
|
||||||
# Get the parameters defining the geotransform, srid, and size of the raster
|
# Get the parameters defining the geotransform, srid, and size of the raster
|
||||||
if 'width' not in ds_input:
|
ds_input.setdefault('width', self.width)
|
||||||
ds_input['width'] = self.width
|
ds_input.setdefault('height', self.height)
|
||||||
|
ds_input.setdefault('srid', self.srs.srid)
|
||||||
if 'height' not in ds_input:
|
ds_input.setdefault('origin', self.origin)
|
||||||
ds_input['height'] = self.height
|
ds_input.setdefault('scale', self.scale)
|
||||||
|
ds_input.setdefault('skew', self.skew)
|
||||||
if 'srid' not in ds_input:
|
|
||||||
ds_input['srid'] = self.srs.srid
|
|
||||||
|
|
||||||
if 'origin' not in ds_input:
|
|
||||||
ds_input['origin'] = self.origin
|
|
||||||
|
|
||||||
if 'scale' not in ds_input:
|
|
||||||
ds_input['scale'] = self.scale
|
|
||||||
|
|
||||||
if 'skew' not in ds_input:
|
|
||||||
ds_input['skew'] = self.skew
|
|
||||||
|
|
||||||
# Get the driver, name, and datatype of the target raster
|
# Get the driver, name, and datatype of the target raster
|
||||||
if 'driver' not in ds_input:
|
ds_input.setdefault('driver', self.driver.name)
|
||||||
ds_input['driver'] = self.driver.name
|
|
||||||
|
|
||||||
if 'name' not in ds_input:
|
if 'name' not in ds_input:
|
||||||
ds_input['name'] = self.name + '_copy.' + self.driver.name
|
ds_input['name'] = self.name + '_copy.' + self.driver.name
|
||||||
|
|
|
@ -693,8 +693,8 @@ class AlterModelOptions(ModelOptionOperation):
|
||||||
model_state.options = dict(model_state.options)
|
model_state.options = dict(model_state.options)
|
||||||
model_state.options.update(self.options)
|
model_state.options.update(self.options)
|
||||||
for key in self.ALTER_OPTION_KEYS:
|
for key in self.ALTER_OPTION_KEYS:
|
||||||
if key not in self.options and key in model_state.options:
|
if key not in self.options:
|
||||||
del model_state.options[key]
|
model_state.options.pop(key, False)
|
||||||
state.reload_model(app_label, self.name_lower, delay=True)
|
state.reload_model(app_label, self.name_lower, delay=True)
|
||||||
|
|
||||||
def database_forwards(self, app_label, schema_editor, from_state, to_state):
|
def database_forwards(self, app_label, schema_editor, from_state, to_state):
|
||||||
|
|
|
@ -692,8 +692,7 @@ class Query:
|
||||||
# in the parent list. Again, it must be mentioned to ensure that
|
# in the parent list. Again, it must be mentioned to ensure that
|
||||||
# only "must include" fields are pulled in.
|
# only "must include" fields are pulled in.
|
||||||
for model in orig_opts.get_parent_list():
|
for model in orig_opts.get_parent_list():
|
||||||
if model not in seen:
|
seen.setdefault(model, set())
|
||||||
seen[model] = set()
|
|
||||||
for model, values in seen.items():
|
for model, values in seen.items():
|
||||||
callback(target, model, values)
|
callback(target, model, values)
|
||||||
|
|
||||||
|
|
|
@ -87,20 +87,10 @@ class BoundField:
|
||||||
|
|
||||||
attrs = attrs or {}
|
attrs = attrs or {}
|
||||||
attrs = self.build_widget_attrs(attrs, widget)
|
attrs = self.build_widget_attrs(attrs, widget)
|
||||||
auto_id = self.auto_id
|
if self.auto_id and 'id' not in widget.attrs:
|
||||||
if auto_id and 'id' not in attrs and 'id' not in widget.attrs:
|
attrs.setdefault('id', self.html_initial_id if only_initial else self.auto_id)
|
||||||
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
|
|
||||||
|
|
||||||
return widget.render(
|
return widget.render(
|
||||||
name=name,
|
name=self.html_initial_name if only_initial else self.html_name,
|
||||||
value=self.value(),
|
value=self.value(),
|
||||||
attrs=attrs,
|
attrs=attrs,
|
||||||
renderer=self.form.renderer,
|
renderer=self.form.renderer,
|
||||||
|
|
|
@ -136,10 +136,7 @@ class HttpResponseBase:
|
||||||
self._headers[header.lower()] = (header, value)
|
self._headers[header.lower()] = (header, value)
|
||||||
|
|
||||||
def __delitem__(self, header):
|
def __delitem__(self, header):
|
||||||
try:
|
self._headers.pop(header.lower(), False)
|
||||||
del self._headers[header.lower()]
|
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def __getitem__(self, header):
|
def __getitem__(self, header):
|
||||||
return self._headers[header.lower()][1]
|
return self._headers[header.lower()][1]
|
||||||
|
|
|
@ -57,6 +57,5 @@ class LocaleMiddleware(MiddlewareMixin):
|
||||||
|
|
||||||
if not (i18n_patterns_used and language_from_path):
|
if not (i18n_patterns_used and language_from_path):
|
||||||
patch_vary_headers(response, ('Accept-Language',))
|
patch_vary_headers(response, ('Accept-Language',))
|
||||||
if 'Content-Language' not in response:
|
response.setdefault('Content-Language', language)
|
||||||
response['Content-Language'] = language
|
|
||||||
return response
|
return response
|
||||||
|
|
|
@ -37,10 +37,10 @@ class SecurityMiddleware(MiddlewareMixin):
|
||||||
sts_header = sts_header + "; preload"
|
sts_header = sts_header + "; preload"
|
||||||
response["strict-transport-security"] = sts_header
|
response["strict-transport-security"] = sts_header
|
||||||
|
|
||||||
if self.content_type_nosniff and 'x-content-type-options' not in response:
|
if self.content_type_nosniff:
|
||||||
response["x-content-type-options"] = "nosniff"
|
response.setdefault('x-content-type-options', 'nosniff')
|
||||||
|
|
||||||
if self.xss_filter and 'x-xss-protection' not in response:
|
if self.xss_filter:
|
||||||
response["x-xss-protection"] = "1; mode=block"
|
response.setdefault('x-xss-protection', '1; mode=block')
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
|
@ -225,8 +225,7 @@ class IfChangedNode(Node):
|
||||||
def render(self, context):
|
def render(self, context):
|
||||||
# Init state storage
|
# Init state storage
|
||||||
state_frame = self._get_context_stack_frame(context)
|
state_frame = self._get_context_stack_frame(context)
|
||||||
if self not in state_frame:
|
state_frame.setdefault(self)
|
||||||
state_frame[self] = None
|
|
||||||
|
|
||||||
nodelist_true_output = None
|
nodelist_true_output = None
|
||||||
if self._varlist:
|
if self._varlist:
|
||||||
|
|
|
@ -103,8 +103,8 @@ def condition(etag_func=None, last_modified_func=None):
|
||||||
if request.method in ('GET', 'HEAD'):
|
if request.method in ('GET', 'HEAD'):
|
||||||
if res_last_modified and not response.has_header('Last-Modified'):
|
if res_last_modified and not response.has_header('Last-Modified'):
|
||||||
response['Last-Modified'] = http_date(res_last_modified)
|
response['Last-Modified'] = http_date(res_last_modified)
|
||||||
if res_etag and not response.has_header('ETag'):
|
if res_etag:
|
||||||
response['ETag'] = res_etag
|
response.setdefault('ETag', res_etag)
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
|
@ -21,8 +21,7 @@ class ContextMixin:
|
||||||
extra_context = None
|
extra_context = None
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
if 'view' not in kwargs:
|
kwargs.setdefault('view', self)
|
||||||
kwargs['view'] = self
|
|
||||||
if self.extra_context is not None:
|
if self.extra_context is not None:
|
||||||
kwargs.update(self.extra_context)
|
kwargs.update(self.extra_context)
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
|
@ -455,8 +455,7 @@ if __name__ == "__main__":
|
||||||
if options.settings:
|
if options.settings:
|
||||||
os.environ['DJANGO_SETTINGS_MODULE'] = options.settings
|
os.environ['DJANGO_SETTINGS_MODULE'] = options.settings
|
||||||
else:
|
else:
|
||||||
if "DJANGO_SETTINGS_MODULE" not in os.environ:
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'test_sqlite')
|
||||||
os.environ['DJANGO_SETTINGS_MODULE'] = 'test_sqlite'
|
|
||||||
options.settings = os.environ['DJANGO_SETTINGS_MODULE']
|
options.settings = os.environ['DJANGO_SETTINGS_MODULE']
|
||||||
|
|
||||||
if options.selenium:
|
if options.selenium:
|
||||||
|
|
Loading…
Reference in New Issue