Refs #28909 -- Simplifed code using unpacking generalizations.
This commit is contained in:
parent
5b589a47b9
commit
074a2f7f58
|
@ -589,13 +589,11 @@ class BaseDatabaseWrapper:
|
||||||
potential child threads while (or after) the test database is destroyed.
|
potential child threads while (or after) the test database is destroyed.
|
||||||
Refs #10868, #17786, #16969.
|
Refs #10868, #17786, #16969.
|
||||||
"""
|
"""
|
||||||
settings_dict = self.settings_dict.copy()
|
return self.__class__(
|
||||||
settings_dict['NAME'] = None
|
{**self.settings_dict, 'NAME': None},
|
||||||
nodb_connection = self.__class__(
|
|
||||||
settings_dict,
|
|
||||||
alias=NO_DB_ALIAS,
|
alias=NO_DB_ALIAS,
|
||||||
allow_thread_sharing=False)
|
allow_thread_sharing=False,
|
||||||
return nodb_connection
|
)
|
||||||
|
|
||||||
def _start_transaction_under_autocommit(self):
|
def _start_transaction_under_autocommit(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -221,9 +221,7 @@ class BaseDatabaseCreation:
|
||||||
# already and its name has been copied to settings_dict['NAME'] so
|
# already and its name has been copied to settings_dict['NAME'] so
|
||||||
# we don't need to call _get_test_db_name.
|
# we don't need to call _get_test_db_name.
|
||||||
orig_settings_dict = self.connection.settings_dict
|
orig_settings_dict = self.connection.settings_dict
|
||||||
new_settings_dict = orig_settings_dict.copy()
|
return {**orig_settings_dict, 'NAME': '{}_{}'.format(orig_settings_dict['NAME'], suffix)}
|
||||||
new_settings_dict['NAME'] = '{}_{}'.format(orig_settings_dict['NAME'], suffix)
|
|
||||||
return new_settings_dict
|
|
||||||
|
|
||||||
def _clone_test_db(self, suffix, verbosity, keepdb=False):
|
def _clone_test_db(self, suffix, verbosity, keepdb=False):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -51,10 +51,8 @@ class DatabaseCreation(BaseDatabaseCreation):
|
||||||
if self.is_in_memory_db(source_database_name):
|
if self.is_in_memory_db(source_database_name):
|
||||||
return orig_settings_dict
|
return orig_settings_dict
|
||||||
else:
|
else:
|
||||||
new_settings_dict = orig_settings_dict.copy()
|
|
||||||
root, ext = os.path.splitext(orig_settings_dict['NAME'])
|
root, ext = os.path.splitext(orig_settings_dict['NAME'])
|
||||||
new_settings_dict['NAME'] = '{}_{}.{}'.format(root, suffix, ext)
|
return {**orig_settings_dict, 'NAME': '{}_{}.{}'.format(root, suffix, ext)}
|
||||||
return new_settings_dict
|
|
||||||
|
|
||||||
def _clone_test_db(self, suffix, verbosity, keepdb=False):
|
def _clone_test_db(self, suffix, verbosity, keepdb=False):
|
||||||
source_database_name = self.connection.settings_dict['NAME']
|
source_database_name = self.connection.settings_dict['NAME']
|
||||||
|
|
|
@ -219,9 +219,7 @@ class QuerySet:
|
||||||
def __getstate__(self):
|
def __getstate__(self):
|
||||||
# Force the cache to be fully populated.
|
# Force the cache to be fully populated.
|
||||||
self._fetch_all()
|
self._fetch_all()
|
||||||
obj_dict = self.__dict__.copy()
|
return {**self.__dict__, DJANGO_VERSION_PICKLE_KEY: get_version()}
|
||||||
obj_dict[DJANGO_VERSION_PICKLE_KEY] = get_version()
|
|
||||||
return obj_dict
|
|
||||||
|
|
||||||
def __setstate__(self, state):
|
def __setstate__(self, state):
|
||||||
msg = None
|
msg = None
|
||||||
|
|
|
@ -958,35 +958,29 @@ class SelectDateWidget(Widget):
|
||||||
year_choices = [(i, str(i)) for i in self.years]
|
year_choices = [(i, str(i)) for i in self.years]
|
||||||
if not self.is_required:
|
if not self.is_required:
|
||||||
year_choices.insert(0, self.year_none_value)
|
year_choices.insert(0, self.year_none_value)
|
||||||
year_attrs = context['widget']['attrs'].copy()
|
|
||||||
year_name = self.year_field % name
|
year_name = self.year_field % name
|
||||||
year_attrs['id'] = 'id_%s' % year_name
|
|
||||||
date_context['year'] = self.select_widget(attrs, choices=year_choices).get_context(
|
date_context['year'] = self.select_widget(attrs, choices=year_choices).get_context(
|
||||||
name=year_name,
|
name=year_name,
|
||||||
value=context['widget']['value']['year'],
|
value=context['widget']['value']['year'],
|
||||||
attrs=year_attrs,
|
attrs={**context['widget']['attrs'], 'id': 'id_%s' % year_name},
|
||||||
)
|
)
|
||||||
month_choices = list(self.months.items())
|
month_choices = list(self.months.items())
|
||||||
if not self.is_required:
|
if not self.is_required:
|
||||||
month_choices.insert(0, self.month_none_value)
|
month_choices.insert(0, self.month_none_value)
|
||||||
month_attrs = context['widget']['attrs'].copy()
|
|
||||||
month_name = self.month_field % name
|
month_name = self.month_field % name
|
||||||
month_attrs['id'] = 'id_%s' % month_name
|
|
||||||
date_context['month'] = self.select_widget(attrs, choices=month_choices).get_context(
|
date_context['month'] = self.select_widget(attrs, choices=month_choices).get_context(
|
||||||
name=month_name,
|
name=month_name,
|
||||||
value=context['widget']['value']['month'],
|
value=context['widget']['value']['month'],
|
||||||
attrs=month_attrs,
|
attrs={**context['widget']['attrs'], 'id': 'id_%s' % month_name},
|
||||||
)
|
)
|
||||||
day_choices = [(i, i) for i in range(1, 32)]
|
day_choices = [(i, i) for i in range(1, 32)]
|
||||||
if not self.is_required:
|
if not self.is_required:
|
||||||
day_choices.insert(0, self.day_none_value)
|
day_choices.insert(0, self.day_none_value)
|
||||||
day_attrs = context['widget']['attrs'].copy()
|
|
||||||
day_name = self.day_field % name
|
day_name = self.day_field % name
|
||||||
day_attrs['id'] = 'id_%s' % day_name
|
|
||||||
date_context['day'] = self.select_widget(attrs, choices=day_choices,).get_context(
|
date_context['day'] = self.select_widget(attrs, choices=day_choices,).get_context(
|
||||||
name=day_name,
|
name=day_name,
|
||||||
value=context['widget']['value']['day'],
|
value=context['widget']['value']['day'],
|
||||||
attrs=day_attrs,
|
attrs={**context['widget']['attrs'], 'id': 'id_%s' % day_name},
|
||||||
)
|
)
|
||||||
subwidgets = []
|
subwidgets = []
|
||||||
for field in self._parse_date_fmt():
|
for field in self._parse_date_fmt():
|
||||||
|
|
|
@ -30,7 +30,6 @@ class EngineHandler:
|
||||||
templates = OrderedDict()
|
templates = OrderedDict()
|
||||||
backend_names = []
|
backend_names = []
|
||||||
for tpl in self._templates:
|
for tpl in self._templates:
|
||||||
tpl = tpl.copy()
|
|
||||||
try:
|
try:
|
||||||
# This will raise an exception if 'BACKEND' doesn't exist or
|
# This will raise an exception if 'BACKEND' doesn't exist or
|
||||||
# isn't a string containing at least one dot.
|
# isn't a string containing at least one dot.
|
||||||
|
@ -41,10 +40,13 @@ class EngineHandler:
|
||||||
"Invalid BACKEND for a template engine: {}. Check "
|
"Invalid BACKEND for a template engine: {}. Check "
|
||||||
"your TEMPLATES setting.".format(invalid_backend))
|
"your TEMPLATES setting.".format(invalid_backend))
|
||||||
|
|
||||||
tpl.setdefault('NAME', default_name)
|
tpl = {
|
||||||
tpl.setdefault('DIRS', [])
|
'NAME': default_name,
|
||||||
tpl.setdefault('APP_DIRS', False)
|
'DIRS': [],
|
||||||
tpl.setdefault('OPTIONS', {})
|
'APP_DIRS': False,
|
||||||
|
'OPTIONS': {},
|
||||||
|
**tpl,
|
||||||
|
}
|
||||||
|
|
||||||
templates[tpl['NAME']] = tpl
|
templates[tpl['NAME']] = tpl
|
||||||
backend_names.append(tpl['NAME'])
|
backend_names.append(tpl['NAME'])
|
||||||
|
|
|
@ -289,8 +289,7 @@ def restart_with_reloader():
|
||||||
args += sys.argv[1:]
|
args += sys.argv[1:]
|
||||||
else:
|
else:
|
||||||
args += sys.argv
|
args += sys.argv
|
||||||
new_environ = os.environ.copy()
|
new_environ = {**os.environ, 'RUN_MAIN': 'true'}
|
||||||
new_environ["RUN_MAIN"] = 'true'
|
|
||||||
exit_code = subprocess.call(args, env=new_environ)
|
exit_code = subprocess.call(args, env=new_environ)
|
||||||
if exit_code != 3:
|
if exit_code != 3:
|
||||||
return exit_code
|
return exit_code
|
||||||
|
|
|
@ -100,9 +100,7 @@ class MultiValueDict(dict):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def __getstate__(self):
|
def __getstate__(self):
|
||||||
obj_dict = self.__dict__.copy()
|
return {**self.__dict__, '_data': {k: self._getlist(k) for k in self}}
|
||||||
obj_dict['_data'] = {k: self._getlist(k) for k in self}
|
|
||||||
return obj_dict
|
|
||||||
|
|
||||||
def __setstate__(self, obj_dict):
|
def __setstate__(self, obj_dict):
|
||||||
data = obj_dict.pop('_data', {})
|
data = obj_dict.pop('_data', {})
|
||||||
|
|
Loading…
Reference in New Issue