Made small readability improvements.
This commit is contained in:
parent
4eb756793b
commit
302caa40e4
|
@ -428,8 +428,7 @@ class AdminPasswordChangeForm(forms.Form):
|
||||||
def clean_password2(self):
|
def clean_password2(self):
|
||||||
password1 = self.cleaned_data.get('password1')
|
password1 = self.cleaned_data.get('password1')
|
||||||
password2 = self.cleaned_data.get('password2')
|
password2 = self.cleaned_data.get('password2')
|
||||||
if password1 and password2:
|
if password1 and password2 and password1 != password2:
|
||||||
if password1 != password2:
|
|
||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
self.error_messages['password_mismatch'],
|
self.error_messages['password_mismatch'],
|
||||||
code='password_mismatch',
|
code='password_mismatch',
|
||||||
|
|
|
@ -71,7 +71,7 @@ class GeometryField(forms.Field):
|
||||||
|
|
||||||
# Ensuring that the geometry is of the correct type (indicated
|
# Ensuring that the geometry is of the correct type (indicated
|
||||||
# using the OGC string label).
|
# using the OGC string label).
|
||||||
if str(geom.geom_type).upper() != self.geom_type and not self.geom_type == 'GEOMETRY':
|
if str(geom.geom_type).upper() != self.geom_type and self.geom_type != 'GEOMETRY':
|
||||||
raise ValidationError(self.error_messages['invalid_geom_type'], code='invalid_geom_type')
|
raise ValidationError(self.error_messages['invalid_geom_type'], code='invalid_geom_type')
|
||||||
|
|
||||||
# Transforming the geometry if the SRID was set.
|
# Transforming the geometry if the SRID was set.
|
||||||
|
|
|
@ -187,9 +187,8 @@ class AppDirectoriesFinder(BaseFinder):
|
||||||
Find a requested static file in an app's static locations.
|
Find a requested static file in an app's static locations.
|
||||||
"""
|
"""
|
||||||
storage = self.storages.get(app)
|
storage = self.storages.get(app)
|
||||||
if storage:
|
# Only try to find a file if the source dir actually exists.
|
||||||
# only try to find a file if the source dir actually exists
|
if storage and storage.exists(path):
|
||||||
if storage.exists(path):
|
|
||||||
matched_path = storage.path(path)
|
matched_path = storage.path(path)
|
||||||
if matched_path:
|
if matched_path:
|
||||||
return matched_path
|
return matched_path
|
||||||
|
|
|
@ -113,8 +113,7 @@ class Command(BaseCommand):
|
||||||
# We may have previously seen an "all-models" request for
|
# We may have previously seen an "all-models" request for
|
||||||
# this app (no model qualifier was given). In this case
|
# this app (no model qualifier was given). In this case
|
||||||
# there is no need adding specific models to the list.
|
# there is no need adding specific models to the list.
|
||||||
if app_list_value is not None:
|
if app_list_value is not None and model not in app_list_value:
|
||||||
if model not in app_list_value:
|
|
||||||
app_list_value.append(model)
|
app_list_value.append(model)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
if primary_keys:
|
if primary_keys:
|
||||||
|
|
|
@ -696,7 +696,7 @@ class QuerySet:
|
||||||
field_name != 'pk' and
|
field_name != 'pk' and
|
||||||
not opts.get_field(field_name).unique and
|
not opts.get_field(field_name).unique and
|
||||||
field_name not in unique_fields and
|
field_name not in unique_fields and
|
||||||
not self.query.distinct_fields == (field_name,)
|
self.query.distinct_fields != (field_name,)
|
||||||
):
|
):
|
||||||
raise ValueError("in_bulk()'s field_name must be a unique field but %r isn't." % field_name)
|
raise ValueError("in_bulk()'s field_name must be a unique field but %r isn't." % field_name)
|
||||||
if id_list is not None:
|
if id_list is not None:
|
||||||
|
|
|
@ -104,8 +104,7 @@ class CommonMiddleware(MiddlewareMixin):
|
||||||
"""
|
"""
|
||||||
# If the given URL is "Not Found", then check if we should redirect to
|
# If the given URL is "Not Found", then check if we should redirect to
|
||||||
# a path with a slash appended.
|
# a path with a slash appended.
|
||||||
if response.status_code == 404:
|
if response.status_code == 404 and self.should_redirect_with_slash(request):
|
||||||
if self.should_redirect_with_slash(request):
|
|
||||||
return self.response_redirect_class(self.get_full_path_with_slash(request))
|
return self.response_redirect_class(self.get_full_path_with_slash(request))
|
||||||
|
|
||||||
# Add the Content-Length header to non-streaming responses if not
|
# Add the Content-Length header to non-streaming responses if not
|
||||||
|
|
|
@ -121,9 +121,8 @@ def resolve_url(to, *args, **kwargs):
|
||||||
# further to some Python functions like urlparse.
|
# further to some Python functions like urlparse.
|
||||||
to = str(to)
|
to = str(to)
|
||||||
|
|
||||||
if isinstance(to, str):
|
|
||||||
# Handle relative URLs
|
# Handle relative URLs
|
||||||
if to.startswith(('./', '../')):
|
if isinstance(to, str) and to.startswith(('./', '../')):
|
||||||
return to
|
return to
|
||||||
|
|
||||||
# Next try a reverse URL resolution.
|
# Next try a reverse URL resolution.
|
||||||
|
|
|
@ -23,8 +23,7 @@ class Element:
|
||||||
def append(self, element):
|
def append(self, element):
|
||||||
if isinstance(element, str):
|
if isinstance(element, str):
|
||||||
element = normalize_whitespace(element)
|
element = normalize_whitespace(element)
|
||||||
if self.children:
|
if self.children and isinstance(self.children[-1], str):
|
||||||
if isinstance(self.children[-1], str):
|
|
||||||
self.children[-1] += element
|
self.children[-1] += element
|
||||||
self.children[-1] = normalize_whitespace(self.children[-1])
|
self.children[-1] = normalize_whitespace(self.children[-1])
|
||||||
return
|
return
|
||||||
|
@ -32,16 +31,14 @@ class Element:
|
||||||
# removing last children if it is only whitespace
|
# removing last children if it is only whitespace
|
||||||
# this can result in incorrect dom representations since
|
# this can result in incorrect dom representations since
|
||||||
# whitespace between inline tags like <span> is significant
|
# whitespace between inline tags like <span> is significant
|
||||||
if isinstance(self.children[-1], str):
|
if isinstance(self.children[-1], str) and self.children[-1].isspace():
|
||||||
if self.children[-1].isspace():
|
|
||||||
self.children.pop()
|
self.children.pop()
|
||||||
if element:
|
if element:
|
||||||
self.children.append(element)
|
self.children.append(element)
|
||||||
|
|
||||||
def finalize(self):
|
def finalize(self):
|
||||||
def rstrip_last_element(children):
|
def rstrip_last_element(children):
|
||||||
if children:
|
if children and isinstance(children[-1], str):
|
||||||
if isinstance(children[-1], str):
|
|
||||||
children[-1] = children[-1].rstrip()
|
children[-1] = children[-1].rstrip()
|
||||||
if not children[-1]:
|
if not children[-1]:
|
||||||
children.pop()
|
children.pop()
|
||||||
|
@ -79,11 +76,9 @@ class Element:
|
||||||
return hash((self.name, *self.attributes))
|
return hash((self.name, *self.attributes))
|
||||||
|
|
||||||
def _count(self, element, count=True):
|
def _count(self, element, count=True):
|
||||||
if not isinstance(element, str):
|
if not isinstance(element, str) and self == element:
|
||||||
if self == element:
|
|
||||||
return 1
|
return 1
|
||||||
if isinstance(element, RootElement):
|
if isinstance(element, RootElement) and self.children == element.children:
|
||||||
if self.children == element.children:
|
|
||||||
return 1
|
return 1
|
||||||
i = 0
|
i = 0
|
||||||
elem_child_idx = 0
|
elem_child_idx = 0
|
||||||
|
@ -241,7 +236,6 @@ def parse_html(html):
|
||||||
document = parser.root
|
document = parser.root
|
||||||
document.finalize()
|
document.finalize()
|
||||||
# Removing ROOT element if it's not necessary
|
# Removing ROOT element if it's not necessary
|
||||||
if len(document.children) == 1:
|
if len(document.children) == 1 and not isinstance(document.children[0], str):
|
||||||
if not isinstance(document.children[0], str):
|
|
||||||
document = document.children[0]
|
document = document.children[0]
|
||||||
return document
|
return document
|
||||||
|
|
|
@ -180,9 +180,12 @@ def get_conditional_response(request, etag=None, last_modified=None, response=No
|
||||||
return _precondition_failed(request)
|
return _precondition_failed(request)
|
||||||
|
|
||||||
# Step 4: Test the If-Modified-Since precondition.
|
# Step 4: Test the If-Modified-Since precondition.
|
||||||
if (not if_none_match_etags and if_modified_since and
|
if (
|
||||||
not _if_modified_since_passes(last_modified, if_modified_since)):
|
not if_none_match_etags and
|
||||||
if request.method in ('GET', 'HEAD'):
|
if_modified_since and
|
||||||
|
not _if_modified_since_passes(last_modified, if_modified_since) and
|
||||||
|
request.method in ('GET', 'HEAD')
|
||||||
|
):
|
||||||
return _not_modified(request, response)
|
return _not_modified(request, response)
|
||||||
|
|
||||||
# Step 5: Test the If-Range precondition (not supported).
|
# Step 5: Test the If-Range precondition (not supported).
|
||||||
|
|
|
@ -665,8 +665,7 @@ class ThreadTests(TransactionTestCase):
|
||||||
# (the connection opened in the main thread will automatically be
|
# (the connection opened in the main thread will automatically be
|
||||||
# closed on teardown).
|
# closed on teardown).
|
||||||
for conn in connections_dict.values():
|
for conn in connections_dict.values():
|
||||||
if conn is not connection:
|
if conn is not connection and conn.allow_thread_sharing:
|
||||||
if conn.allow_thread_sharing:
|
|
||||||
conn.close()
|
conn.close()
|
||||||
conn.dec_thread_sharing()
|
conn.dec_thread_sharing()
|
||||||
|
|
||||||
|
@ -702,8 +701,7 @@ class ThreadTests(TransactionTestCase):
|
||||||
# (the connection opened in the main thread will automatically be
|
# (the connection opened in the main thread will automatically be
|
||||||
# closed on teardown).
|
# closed on teardown).
|
||||||
for conn in connections_dict.values():
|
for conn in connections_dict.values():
|
||||||
if conn is not connection:
|
if conn is not connection and conn.allow_thread_sharing:
|
||||||
if conn.allow_thread_sharing:
|
|
||||||
conn.close()
|
conn.close()
|
||||||
conn.dec_thread_sharing()
|
conn.dec_thread_sharing()
|
||||||
|
|
||||||
|
|
|
@ -1714,7 +1714,7 @@ class CacheUtils(SimpleTestCase):
|
||||||
def _get_request_cache(self, method='GET', query_string=None, update_cache=None):
|
def _get_request_cache(self, method='GET', query_string=None, update_cache=None):
|
||||||
request = self._get_request(self.host, self.path,
|
request = self._get_request(self.host, self.path,
|
||||||
method, query_string=query_string)
|
method, query_string=query_string)
|
||||||
request._cache_update_cache = True if not update_cache else update_cache
|
request._cache_update_cache = update_cache if update_cache else True
|
||||||
return request
|
return request
|
||||||
|
|
||||||
def test_patch_vary_headers(self):
|
def test_patch_vary_headers(self):
|
||||||
|
|
|
@ -161,7 +161,7 @@ class SchemaTests(TransactionTestCase):
|
||||||
schema_editor.add_field(model, field)
|
schema_editor.add_field(model, field)
|
||||||
cursor.execute("SELECT {} FROM {};".format(field_name, model._meta.db_table))
|
cursor.execute("SELECT {} FROM {};".format(field_name, model._meta.db_table))
|
||||||
database_default = cursor.fetchall()[0][0]
|
database_default = cursor.fetchall()[0][0]
|
||||||
if cast_function and not type(database_default) == type(expected_default):
|
if cast_function and type(database_default) != type(expected_default):
|
||||||
database_default = cast_function(database_default)
|
database_default = cast_function(database_default)
|
||||||
self.assertEqual(database_default, expected_default)
|
self.assertEqual(database_default, expected_default)
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ class SetLanguageTests(TestCase):
|
||||||
def _get_inactive_language_code(self):
|
def _get_inactive_language_code(self):
|
||||||
"""Return language code for a language which is not activated."""
|
"""Return language code for a language which is not activated."""
|
||||||
current_language = get_language()
|
current_language = get_language()
|
||||||
return [code for code, name in settings.LANGUAGES if not code == current_language][0]
|
return [code for code, name in settings.LANGUAGES if code != current_language][0]
|
||||||
|
|
||||||
def test_setlang(self):
|
def test_setlang(self):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue