mirror of
https://github.com/django/django.git
synced 2025-10-30 17:16:10 +00:00
Fixed #21288 -- Fixed E126 pep8 warnings
This commit is contained in:
committed by
Tim Graham
parent
a3690168cb
commit
b289fcf1bf
@@ -217,8 +217,8 @@ class RelatedFieldListFilter(FieldListFilter):
|
||||
}
|
||||
|
||||
FieldListFilter.register(lambda f: (
|
||||
bool(f.rel) if hasattr(f, 'rel') else
|
||||
isinstance(f, models.related.RelatedObject)), RelatedFieldListFilter)
|
||||
bool(f.rel) if hasattr(f, 'rel') else
|
||||
isinstance(f, models.related.RelatedObject)), RelatedFieldListFilter)
|
||||
|
||||
|
||||
class BooleanFieldListFilter(FieldListFilter):
|
||||
@@ -241,7 +241,7 @@ class BooleanFieldListFilter(FieldListFilter):
|
||||
yield {
|
||||
'selected': self.lookup_val == lookup and not self.lookup_val2,
|
||||
'query_string': cl.get_query_string({
|
||||
self.lookup_kwarg: lookup,
|
||||
self.lookup_kwarg: lookup,
|
||||
}, [self.lookup_kwarg2]),
|
||||
'display': title,
|
||||
}
|
||||
@@ -249,7 +249,7 @@ class BooleanFieldListFilter(FieldListFilter):
|
||||
yield {
|
||||
'selected': self.lookup_val2 == 'True',
|
||||
'query_string': cl.get_query_string({
|
||||
self.lookup_kwarg2: 'True',
|
||||
self.lookup_kwarg2: 'True',
|
||||
}, [self.lookup_kwarg]),
|
||||
'display': _('Unknown'),
|
||||
}
|
||||
@@ -278,7 +278,7 @@ class ChoicesFieldListFilter(FieldListFilter):
|
||||
yield {
|
||||
'selected': smart_text(lookup) == self.lookup_val,
|
||||
'query_string': cl.get_query_string({
|
||||
self.lookup_kwarg: lookup}),
|
||||
self.lookup_kwarg: lookup}),
|
||||
'display': title,
|
||||
}
|
||||
|
||||
@@ -340,7 +340,7 @@ class DateFieldListFilter(FieldListFilter):
|
||||
yield {
|
||||
'selected': self.date_params == param_dict,
|
||||
'query_string': cl.get_query_string(
|
||||
param_dict, [self.field_generic]),
|
||||
param_dict, [self.field_generic]),
|
||||
'display': title,
|
||||
}
|
||||
|
||||
|
||||
@@ -150,13 +150,12 @@ class BaseModelAdmin(six.with_metaclass(RenameBaseModelAdminMethods)):
|
||||
# rendered output. formfield can be None if it came from a
|
||||
# OneToOneField with parent_link=True or a M2M intermediary.
|
||||
if formfield and db_field.name not in self.raw_id_fields:
|
||||
related_modeladmin = self.admin_site._registry.get(
|
||||
db_field.rel.to)
|
||||
related_modeladmin = self.admin_site._registry.get(db_field.rel.to)
|
||||
can_add_related = bool(related_modeladmin and
|
||||
related_modeladmin.has_add_permission(request))
|
||||
related_modeladmin.has_add_permission(request))
|
||||
formfield.widget = widgets.RelatedFieldWidgetWrapper(
|
||||
formfield.widget, db_field.rel, self.admin_site,
|
||||
can_add_related=can_add_related)
|
||||
formfield.widget, db_field.rel, self.admin_site,
|
||||
can_add_related=can_add_related)
|
||||
|
||||
return formfield
|
||||
|
||||
@@ -1196,11 +1195,11 @@ class ModelAdmin(BaseModelAdmin):
|
||||
|
||||
opts = self.model._meta
|
||||
|
||||
self.message_user(request, _(
|
||||
'The %(name)s "%(obj)s" was deleted successfully.') % {
|
||||
self.message_user(request,
|
||||
_('The %(name)s "%(obj)s" was deleted successfully.') % {
|
||||
'name': force_text(opts.verbose_name),
|
||||
'obj': force_text(obj_display)
|
||||
}, messages.SUCCESS)
|
||||
}, messages.SUCCESS)
|
||||
|
||||
if self.has_change_permission(request, None):
|
||||
post_url = reverse('admin:%s_%s_changelist' %
|
||||
@@ -1313,9 +1312,9 @@ class ModelAdmin(BaseModelAdmin):
|
||||
raise Http404(_('%(name)s object with primary key %(key)r does not exist.') % {'name': force_text(opts.verbose_name), 'key': escape(object_id)})
|
||||
|
||||
if request.method == 'POST' and "_saveasnew" in request.POST:
|
||||
return self.add_view(request, form_url=reverse('admin:%s_%s_add' %
|
||||
(opts.app_label, opts.model_name),
|
||||
current_app=self.admin_site.name))
|
||||
return self.add_view(request, form_url=reverse('admin:%s_%s_add' % (
|
||||
opts.app_label, opts.model_name),
|
||||
current_app=self.admin_site.name))
|
||||
|
||||
ModelForm = self.get_form(request, obj)
|
||||
if request.method == 'POST':
|
||||
@@ -1544,7 +1543,7 @@ class ModelAdmin(BaseModelAdmin):
|
||||
if obj is None:
|
||||
raise Http404(
|
||||
_('%(name)s object with primary key %(key)r does not exist.') %
|
||||
{'name': force_text(opts.verbose_name), 'key': escape(object_id)}
|
||||
{'name': force_text(opts.verbose_name), 'key': escape(object_id)}
|
||||
)
|
||||
|
||||
using = router.db_for_write(self.model)
|
||||
|
||||
@@ -164,8 +164,7 @@ def result_headers(cl):
|
||||
"url_primary": cl.get_query_string({ORDER_VAR: '.'.join(o_list_primary)}),
|
||||
"url_remove": cl.get_query_string({ORDER_VAR: '.'.join(o_list_remove)}),
|
||||
"url_toggle": cl.get_query_string({ORDER_VAR: '.'.join(o_list_toggle)}),
|
||||
"class_attrib": format_html(' class="{0}"', ' '.join(th_classes))
|
||||
if th_classes else '',
|
||||
"class_attrib": format_html(' class="{0}"', ' '.join(th_classes)) if th_classes else '',
|
||||
}
|
||||
|
||||
def _boolean_icon(field_val):
|
||||
@@ -246,8 +245,7 @@ def items_for_result(cl, result, form):
|
||||
link_or_text = format_html(
|
||||
'<a href="{0}"{1}>{2}</a>',
|
||||
url,
|
||||
format_html(' onclick="opener.dismissRelatedLookupPopup(window, '{0}'); return false;"', result_id)
|
||||
if cl.is_popup else '',
|
||||
format_html(' onclick="opener.dismissRelatedLookupPopup(window, '{0}'); return false;"', result_id) if cl.is_popup else '',
|
||||
result_repr)
|
||||
|
||||
yield format_html('<{0}{1}>{2}</{3}>',
|
||||
@@ -261,7 +259,7 @@ def items_for_result(cl, result, form):
|
||||
# can provide fields on a per request basis
|
||||
if (form and field_name in form.fields and not (
|
||||
field_name == cl.model._meta.pk.name and
|
||||
form[cl.model._meta.pk.name].is_hidden)):
|
||||
form[cl.model._meta.pk.name].is_hidden)):
|
||||
bf = form[field_name]
|
||||
result_repr = mark_safe(force_text(bf.errors) + force_text(bf))
|
||||
yield format_html('<td{0}>{1}</td>', row_class, result_repr)
|
||||
|
||||
@@ -33,8 +33,7 @@ def submit_row(context):
|
||||
'show_delete_link': (not is_popup and context['has_delete_permission']
|
||||
and change and context.get('show_delete', True)),
|
||||
'show_save_as_new': not is_popup and change and save_as,
|
||||
'show_save_and_add_another': context['has_add_permission'] and
|
||||
not is_popup and (not save_as or context['add']),
|
||||
'show_save_and_add_another': context['has_add_permission'] and not is_popup and (not save_as or context['add']),
|
||||
'show_save_and_continue': not is_popup and context['has_change_permission'],
|
||||
'is_popup': is_popup,
|
||||
'show_save': True,
|
||||
|
||||
@@ -34,7 +34,7 @@ class Command(BaseCommand):
|
||||
|
||||
try:
|
||||
u = UserModel._default_manager.using(options.get('database')).get(**{
|
||||
UserModel.USERNAME_FIELD: username
|
||||
UserModel.USERNAME_FIELD: username
|
||||
})
|
||||
except UserModel.DoesNotExist:
|
||||
raise CommandError("user '%s' does not exist" % username)
|
||||
|
||||
@@ -427,7 +427,7 @@ class PermissionDeniedBackendTest(TestCase):
|
||||
self.assertEqual(authenticate(username='test', password='test'), None)
|
||||
|
||||
@override_settings(AUTHENTICATION_BACKENDS=tuple(
|
||||
settings.AUTHENTICATION_BACKENDS) + (backend, ))
|
||||
settings.AUTHENTICATION_BACKENDS) + (backend, ))
|
||||
def test_authenticates(self):
|
||||
self.assertEqual(authenticate(username='test', password='test'), self.user1)
|
||||
|
||||
|
||||
@@ -177,9 +177,10 @@ class PasswordResetTest(AuthViewsTestCase):
|
||||
# HTTP_HOST header isn't poisoned. This is done as a check when get_host()
|
||||
# is invoked, but we check here as a practical consequence.
|
||||
with patch_logger('django.security.DisallowedHost', 'error') as logger_calls:
|
||||
response = self.client.post('/password_reset/',
|
||||
{'email': 'staffmember@example.com'},
|
||||
HTTP_HOST='www.example:dr.frankenstein@evil.tld'
|
||||
response = self.client.post(
|
||||
'/password_reset/',
|
||||
{'email': 'staffmember@example.com'},
|
||||
HTTP_HOST='www.example:dr.frankenstein@evil.tld'
|
||||
)
|
||||
self.assertEqual(response.status_code, 400)
|
||||
self.assertEqual(len(mail.outbox), 0)
|
||||
@@ -190,9 +191,10 @@ class PasswordResetTest(AuthViewsTestCase):
|
||||
def test_poisoned_http_host_admin_site(self):
|
||||
"Poisoned HTTP_HOST headers can't be used for reset emails on admin views"
|
||||
with patch_logger('django.security.DisallowedHost', 'error') as logger_calls:
|
||||
response = self.client.post('/admin_password_reset/',
|
||||
{'email': 'staffmember@example.com'},
|
||||
HTTP_HOST='www.example:dr.frankenstein@evil.tld'
|
||||
response = self.client.post(
|
||||
'/admin_password_reset/',
|
||||
{'email': 'staffmember@example.com'},
|
||||
HTTP_HOST='www.example:dr.frankenstein@evil.tld'
|
||||
)
|
||||
self.assertEqual(response.status_code, 400)
|
||||
self.assertEqual(len(mail.outbox), 0)
|
||||
@@ -356,7 +358,7 @@ class ChangePasswordTest(AuthViewsTestCase):
|
||||
'password': password,
|
||||
})
|
||||
self.assertFormError(response, AuthenticationForm.error_messages['invalid_login'] % {
|
||||
'username': User._meta.get_field('username').verbose_name
|
||||
'username': User._meta.get_field('username').verbose_name
|
||||
})
|
||||
|
||||
def logout(self):
|
||||
@@ -490,8 +492,8 @@ class LoginTest(AuthViewsTestCase):
|
||||
'good_url': urlquote(good_url),
|
||||
}
|
||||
response = self.client.post(safe_url, {
|
||||
'username': 'testclient',
|
||||
'password': password,
|
||||
'username': 'testclient',
|
||||
'password': password,
|
||||
})
|
||||
self.assertEqual(response.status_code, 302)
|
||||
self.assertTrue(good_url in response.url,
|
||||
|
||||
@@ -240,12 +240,10 @@ class GenericRelation(ForeignObject):
|
||||
|
||||
"""
|
||||
return self.rel.to._base_manager.db_manager(using).filter(**{
|
||||
"%s__pk" % self.content_type_field_name:
|
||||
ContentType.objects.db_manager(using).get_for_model(
|
||||
self.model, for_concrete_model=self.for_concrete_model).pk,
|
||||
"%s__in" % self.object_id_field_name:
|
||||
[obj.pk for obj in objs]
|
||||
})
|
||||
"%s__pk" % self.content_type_field_name: ContentType.objects.db_manager(using).get_for_model(
|
||||
self.model, for_concrete_model=self.for_concrete_model).pk,
|
||||
"%s__in" % self.object_id_field_name: [obj.pk for obj in objs]
|
||||
})
|
||||
|
||||
|
||||
class ReverseGenericRelatedObjectsDescriptor(object):
|
||||
@@ -352,8 +350,7 @@ def create_generic_related_manager(superclass):
|
||||
db = self._db or router.db_for_read(self.model, instance=instances[0])
|
||||
query = {
|
||||
'%s__pk' % self.content_type_field_name: self.content_type.id,
|
||||
'%s__in' % self.object_id_field_name:
|
||||
set(obj._get_pk_val() for obj in instances)
|
||||
'%s__in' % self.object_id_field_name: set(obj._get_pk_val() for obj in instances)
|
||||
}
|
||||
qs = super(GenericRelatedObjectManager, self).get_queryset().using(db).filter(**query)
|
||||
# We (possibly) need to convert object IDs to the type of the
|
||||
|
||||
@@ -27,24 +27,24 @@ class FlatpageTemplateTagTests(TestCase):
|
||||
def test_get_flatpages_tag(self):
|
||||
"The flatpage template tag retrives unregistered prefixed flatpages by default"
|
||||
out = Template(
|
||||
"{% load flatpages %}"
|
||||
"{% get_flatpages as flatpages %}"
|
||||
"{% for page in flatpages %}"
|
||||
"{{ page.title }},"
|
||||
"{% endfor %}"
|
||||
"{% load flatpages %}"
|
||||
"{% get_flatpages as flatpages %}"
|
||||
"{% for page in flatpages %}"
|
||||
"{{ page.title }},"
|
||||
"{% endfor %}"
|
||||
).render(Context())
|
||||
self.assertEqual(out, "A Flatpage,A Nested Flatpage,")
|
||||
|
||||
def test_get_flatpages_tag_for_anon_user(self):
|
||||
"The flatpage template tag retrives unregistered flatpages for an anonymous user"
|
||||
out = Template(
|
||||
"{% load flatpages %}"
|
||||
"{% get_flatpages for anonuser as flatpages %}"
|
||||
"{% for page in flatpages %}"
|
||||
"{{ page.title }},"
|
||||
"{% endfor %}"
|
||||
"{% load flatpages %}"
|
||||
"{% get_flatpages for anonuser as flatpages %}"
|
||||
"{% for page in flatpages %}"
|
||||
"{{ page.title }},"
|
||||
"{% endfor %}"
|
||||
).render(Context({
|
||||
'anonuser': AnonymousUser()
|
||||
'anonuser': AnonymousUser()
|
||||
}))
|
||||
self.assertEqual(out, "A Flatpage,A Nested Flatpage,")
|
||||
|
||||
@@ -53,37 +53,37 @@ class FlatpageTemplateTagTests(TestCase):
|
||||
"The flatpage template tag retrives all flatpages for an authenticated user"
|
||||
me = User.objects.create_user('testuser', 'test@example.com', 's3krit')
|
||||
out = Template(
|
||||
"{% load flatpages %}"
|
||||
"{% get_flatpages for me as flatpages %}"
|
||||
"{% for page in flatpages %}"
|
||||
"{{ page.title }},"
|
||||
"{% endfor %}"
|
||||
"{% load flatpages %}"
|
||||
"{% get_flatpages for me as flatpages %}"
|
||||
"{% for page in flatpages %}"
|
||||
"{{ page.title }},"
|
||||
"{% endfor %}"
|
||||
).render(Context({
|
||||
'me': me
|
||||
'me': me
|
||||
}))
|
||||
self.assertEqual(out, "A Flatpage,A Nested Flatpage,Sekrit Nested Flatpage,Sekrit Flatpage,")
|
||||
|
||||
def test_get_flatpages_with_prefix(self):
|
||||
"The flatpage template tag retrives unregistered prefixed flatpages by default"
|
||||
out = Template(
|
||||
"{% load flatpages %}"
|
||||
"{% get_flatpages '/location/' as location_flatpages %}"
|
||||
"{% for page in location_flatpages %}"
|
||||
"{{ page.title }},"
|
||||
"{% endfor %}"
|
||||
"{% load flatpages %}"
|
||||
"{% get_flatpages '/location/' as location_flatpages %}"
|
||||
"{% for page in location_flatpages %}"
|
||||
"{{ page.title }},"
|
||||
"{% endfor %}"
|
||||
).render(Context())
|
||||
self.assertEqual(out, "A Nested Flatpage,")
|
||||
|
||||
def test_get_flatpages_with_prefix_for_anon_user(self):
|
||||
"The flatpage template tag retrives unregistered prefixed flatpages for an anonymous user"
|
||||
out = Template(
|
||||
"{% load flatpages %}"
|
||||
"{% get_flatpages '/location/' for anonuser as location_flatpages %}"
|
||||
"{% for page in location_flatpages %}"
|
||||
"{{ page.title }},"
|
||||
"{% endfor %}"
|
||||
"{% load flatpages %}"
|
||||
"{% get_flatpages '/location/' for anonuser as location_flatpages %}"
|
||||
"{% for page in location_flatpages %}"
|
||||
"{{ page.title }},"
|
||||
"{% endfor %}"
|
||||
).render(Context({
|
||||
'anonuser': AnonymousUser()
|
||||
'anonuser': AnonymousUser()
|
||||
}))
|
||||
self.assertEqual(out, "A Nested Flatpage,")
|
||||
|
||||
@@ -92,26 +92,26 @@ class FlatpageTemplateTagTests(TestCase):
|
||||
"The flatpage template tag retrive prefixed flatpages for an authenticated user"
|
||||
me = User.objects.create_user('testuser', 'test@example.com', 's3krit')
|
||||
out = Template(
|
||||
"{% load flatpages %}"
|
||||
"{% get_flatpages '/location/' for me as location_flatpages %}"
|
||||
"{% for page in location_flatpages %}"
|
||||
"{{ page.title }},"
|
||||
"{% endfor %}"
|
||||
"{% load flatpages %}"
|
||||
"{% get_flatpages '/location/' for me as location_flatpages %}"
|
||||
"{% for page in location_flatpages %}"
|
||||
"{{ page.title }},"
|
||||
"{% endfor %}"
|
||||
).render(Context({
|
||||
'me': me
|
||||
'me': me
|
||||
}))
|
||||
self.assertEqual(out, "A Nested Flatpage,Sekrit Nested Flatpage,")
|
||||
|
||||
def test_get_flatpages_with_variable_prefix(self):
|
||||
"The prefix for the flatpage template tag can be a template variable"
|
||||
out = Template(
|
||||
"{% load flatpages %}"
|
||||
"{% get_flatpages location_prefix as location_flatpages %}"
|
||||
"{% for page in location_flatpages %}"
|
||||
"{{ page.title }},"
|
||||
"{% endfor %}"
|
||||
"{% load flatpages %}"
|
||||
"{% get_flatpages location_prefix as location_flatpages %}"
|
||||
"{% for page in location_flatpages %}"
|
||||
"{{ page.title }},"
|
||||
"{% endfor %}"
|
||||
).render(Context({
|
||||
'location_prefix': '/location/'
|
||||
'location_prefix': '/location/'
|
||||
}))
|
||||
self.assertEqual(out, "A Nested Flatpage,")
|
||||
|
||||
|
||||
@@ -70,8 +70,8 @@ class BaseStorage(object):
|
||||
|
||||
if wizard_files and not self.file_storage:
|
||||
raise NoFileStorageConfigured(
|
||||
"You need to define 'file_storage' in your "
|
||||
"wizard view in order to handle file uploads.")
|
||||
"You need to define 'file_storage' in your "
|
||||
"wizard view in order to handle file uploads.")
|
||||
|
||||
files = {}
|
||||
for field, field_dict in six.iteritems(wizard_files):
|
||||
@@ -84,8 +84,8 @@ class BaseStorage(object):
|
||||
def set_step_files(self, step, files):
|
||||
if files and not self.file_storage:
|
||||
raise NoFileStorageConfigured(
|
||||
"You need to define 'file_storage' in your "
|
||||
"wizard view in order to handle file uploads.")
|
||||
"You need to define 'file_storage' in your "
|
||||
"wizard view in order to handle file uploads.")
|
||||
|
||||
if step not in self.data[self.step_files_key]:
|
||||
self.data[self.step_files_key][step] = {}
|
||||
|
||||
@@ -184,8 +184,8 @@ class WizardView(TemplateView):
|
||||
if (isinstance(field, forms.FileField) and
|
||||
not hasattr(cls, 'file_storage')):
|
||||
raise NoFileStorageConfigured(
|
||||
"You need to define 'file_storage' in your "
|
||||
"wizard view in order to handle file uploads.")
|
||||
"You need to define 'file_storage' in your "
|
||||
"wizard view in order to handle file uploads.")
|
||||
|
||||
# build the kwargs for the wizardview instances
|
||||
kwargs['form_list'] = computed_form_list
|
||||
|
||||
@@ -10,15 +10,15 @@ from django.contrib.gis.measure import Area, Distance
|
||||
|
||||
|
||||
ALL_TERMS = set([
|
||||
'bbcontains', 'bboverlaps', 'contained', 'contains',
|
||||
'contains_properly', 'coveredby', 'covers', 'crosses', 'disjoint',
|
||||
'distance_gt', 'distance_gte', 'distance_lt', 'distance_lte',
|
||||
'dwithin', 'equals', 'exact',
|
||||
'intersects', 'overlaps', 'relate', 'same_as', 'touches', 'within',
|
||||
'left', 'right', 'overlaps_left', 'overlaps_right',
|
||||
'overlaps_above', 'overlaps_below',
|
||||
'strictly_above', 'strictly_below'
|
||||
])
|
||||
'bbcontains', 'bboverlaps', 'contained', 'contains',
|
||||
'contains_properly', 'coveredby', 'covers', 'crosses', 'disjoint',
|
||||
'distance_gt', 'distance_gte', 'distance_lt', 'distance_lte',
|
||||
'dwithin', 'equals', 'exact',
|
||||
'intersects', 'overlaps', 'relate', 'same_as', 'touches', 'within',
|
||||
'left', 'right', 'overlaps_left', 'overlaps_right',
|
||||
'overlaps_above', 'overlaps_below',
|
||||
'strictly_above', 'strictly_below'
|
||||
])
|
||||
ALL_TERMS.update(sql.constants.QUERY_TERMS)
|
||||
|
||||
class GeoQuery(sql.Query):
|
||||
|
||||
@@ -46,7 +46,7 @@ class GeoWhereNode(WhereNode):
|
||||
if isinstance(lvalue, GeoConstraint):
|
||||
data, params = lvalue.process(lookup_type, params_or_value, connection)
|
||||
spatial_sql, spatial_params = connection.ops.spatial_lookup_sql(
|
||||
data, lookup_type, params_or_value, lvalue.field, qn)
|
||||
data, lookup_type, params_or_value, lvalue.field, qn)
|
||||
return spatial_sql, spatial_params + params
|
||||
else:
|
||||
return super(GeoWhereNode, self).make_atom(child, qn, connection)
|
||||
|
||||
@@ -155,7 +155,7 @@ class OGRGeometry(GDALBase):
|
||||
"Constructs a Polygon from a bounding box (4-tuple)."
|
||||
x0, y0, x1, y1 = bbox
|
||||
return OGRGeometry('POLYGON((%s %s, %s %s, %s %s, %s %s, %s %s))' % (
|
||||
x0, y0, x0, y1, x1, y1, x1, y0, x0, y0))
|
||||
x0, y0, x0, y1, x1, y1, x1, y0, x0, y0))
|
||||
|
||||
### Geometry set-like operations ###
|
||||
# g = g1 | g2
|
||||
|
||||
@@ -133,11 +133,12 @@ class GEOSMutationTest(unittest.TestCase):
|
||||
|
||||
# _set_list
|
||||
pg._set_list(2, (((1,2),(10,0),(12,9),(-1,15),(1,2)),
|
||||
((4,2),(5,2),(5,3),(4,2))))
|
||||
self.assertEqual(pg.coords,
|
||||
(((1.0,2.0),(10.0,0.0),(12.0,9.0),(-1.0,15.0),(1.0,2.0)),
|
||||
((4.0,2.0),(5.0,2.0),(5.0,3.0),(4.0,2.0))),
|
||||
'Polygon _set_list')
|
||||
((4,2),(5,2),(5,3),(4,2))))
|
||||
self.assertEqual(
|
||||
pg.coords,
|
||||
(((1.0,2.0),(10.0,0.0),(12.0,9.0),(-1.0,15.0),(1.0,2.0)),
|
||||
((4.0,2.0),(5.0,2.0),(5.0,3.0),(4.0,2.0))),
|
||||
'Polygon _set_list')
|
||||
|
||||
lsa = Polygon(*pg.coords)
|
||||
for f in geos_function_tests:
|
||||
|
||||
@@ -354,11 +354,11 @@ class BaseTests(object):
|
||||
'success'])
|
||||
|
||||
@override_settings_tags(MESSAGE_TAGS={
|
||||
constants.INFO: 'info',
|
||||
constants.DEBUG: '',
|
||||
constants.WARNING: '',
|
||||
constants.ERROR: 'bad',
|
||||
29: 'custom',
|
||||
constants.INFO: 'info',
|
||||
constants.DEBUG: '',
|
||||
constants.WARNING: '',
|
||||
constants.ERROR: 'bad',
|
||||
29: 'custom',
|
||||
}
|
||||
)
|
||||
def test_custom_tags(self):
|
||||
|
||||
@@ -13,7 +13,7 @@ from .models import Redirect
|
||||
@override_settings(
|
||||
APPEND_SLASH=False,
|
||||
MIDDLEWARE_CLASSES=list(settings.MIDDLEWARE_CLASSES) +
|
||||
['django.contrib.redirects.middleware.RedirectFallbackMiddleware'],
|
||||
['django.contrib.redirects.middleware.RedirectFallbackMiddleware'],
|
||||
SITE_ID=1,
|
||||
)
|
||||
class RedirectTests(TestCase):
|
||||
@@ -72,7 +72,7 @@ class OverriddenRedirectFallbackMiddleware(RedirectFallbackMiddleware):
|
||||
|
||||
@override_settings(
|
||||
MIDDLEWARE_CLASSES=list(settings.MIDDLEWARE_CLASSES) +
|
||||
['django.contrib.redirects.tests.OverriddenRedirectFallbackMiddleware'],
|
||||
['django.contrib.redirects.tests.OverriddenRedirectFallbackMiddleware'],
|
||||
SITE_ID=1,
|
||||
)
|
||||
class OverriddenRedirectMiddlewareTests(TestCase):
|
||||
|
||||
@@ -31,7 +31,7 @@ def index(request, sitemaps,
|
||||
site = site()
|
||||
protocol = req_protocol if site.protocol is None else site.protocol
|
||||
sitemap_url = urlresolvers.reverse(
|
||||
sitemap_url_name, kwargs={'section': section})
|
||||
sitemap_url_name, kwargs={'section': section})
|
||||
absolute_url = '%s://%s%s' % (protocol, req_site.domain, sitemap_url)
|
||||
sites.append(absolute_url)
|
||||
for page in range(2, site.paginator.num_pages + 1):
|
||||
|
||||
@@ -165,9 +165,9 @@ class BaseHandler(object):
|
||||
response = callback(request, **param_dict)
|
||||
except:
|
||||
signals.got_request_exception.send(
|
||||
sender=self.__class__, request=request)
|
||||
sender=self.__class__, request=request)
|
||||
response = self.handle_uncaught_exception(request,
|
||||
resolver, sys.exc_info())
|
||||
resolver, sys.exc_info())
|
||||
|
||||
except SuspiciousOperation as e:
|
||||
# The request logger receives events for any problematic request
|
||||
@@ -181,9 +181,9 @@ class BaseHandler(object):
|
||||
response = callback(request, **param_dict)
|
||||
except:
|
||||
signals.got_request_exception.send(
|
||||
sender=self.__class__, request=request)
|
||||
sender=self.__class__, request=request)
|
||||
response = self.handle_uncaught_exception(request,
|
||||
resolver, sys.exc_info())
|
||||
resolver, sys.exc_info())
|
||||
|
||||
except SystemExit:
|
||||
# Allow sys.exit() to actually exit. See tickets #1023 and #4701
|
||||
|
||||
@@ -78,7 +78,7 @@ class Command(BaseCommand):
|
||||
except DatabaseError as e:
|
||||
raise CommandError(
|
||||
"Cache table '%s' could not be created.\nThe error was: %s." %
|
||||
(tablename, force_text(e)))
|
||||
(tablename, force_text(e)))
|
||||
for statement in index_output:
|
||||
curs.execute(statement)
|
||||
if self.verbosity > 1:
|
||||
|
||||
@@ -46,8 +46,8 @@ class Command(BaseCommand):
|
||||
|
||||
if not len(fixture_labels):
|
||||
raise CommandError(
|
||||
"No database fixture specified. Please provide the path "
|
||||
"of at least one fixture in the command line.")
|
||||
"No database fixture specified. Please provide the path "
|
||||
"of at least one fixture in the command line.")
|
||||
|
||||
self.verbosity = int(options.get('verbosity'))
|
||||
|
||||
@@ -140,10 +140,10 @@ class Command(BaseCommand):
|
||||
obj.save(using=self.using)
|
||||
except (DatabaseError, IntegrityError) as e:
|
||||
e.args = ("Could not load %(app_label)s.%(object_name)s(pk=%(pk)s): %(error_msg)s" % {
|
||||
'app_label': obj.object._meta.app_label,
|
||||
'object_name': obj.object._meta.object_name,
|
||||
'pk': obj.object.pk,
|
||||
'error_msg': force_text(e)
|
||||
'app_label': obj.object._meta.app_label,
|
||||
'object_name': obj.object._meta.object_name,
|
||||
'pk': obj.object.pk,
|
||||
'error_msg': force_text(e)
|
||||
},)
|
||||
raise
|
||||
|
||||
@@ -176,8 +176,8 @@ class Command(BaseCommand):
|
||||
# Check kept for backwards-compatibility; it doesn't look very useful.
|
||||
if '.' in os.path.basename(fixture_name):
|
||||
raise CommandError(
|
||||
"Problem installing fixture '%s': %s is not a known "
|
||||
"serialization format." % tuple(fixture_name.rsplit('.')))
|
||||
"Problem installing fixture '%s': %s is not a known "
|
||||
"serialization format." % tuple(fixture_name.rsplit('.')))
|
||||
|
||||
if self.verbosity >= 2:
|
||||
self.stdout.write("Loading '%s' fixtures..." % fixture_name)
|
||||
@@ -210,8 +210,8 @@ class Command(BaseCommand):
|
||||
# duplicates are only allowed in different directories.
|
||||
if len(fixture_files_in_dir) > 1:
|
||||
raise CommandError(
|
||||
"Multiple fixtures named '%s' in %s. Aborting." %
|
||||
(fixture_name, humanize(fixture_dir)))
|
||||
"Multiple fixtures named '%s' in %s. Aborting." %
|
||||
(fixture_name, humanize(fixture_dir)))
|
||||
fixture_files.extend(fixture_files_in_dir)
|
||||
|
||||
if fixture_name != 'initial_data' and not fixture_files:
|
||||
|
||||
@@ -225,7 +225,7 @@ class Command(NoArgsCommand):
|
||||
|
||||
if (locale is None and not process_all) or self.domain is None:
|
||||
raise CommandError("Type '%s help %s' for usage information." % (
|
||||
os.path.basename(sys.argv[0]), sys.argv[1]))
|
||||
os.path.basename(sys.argv[0]), sys.argv[1]))
|
||||
|
||||
if self.verbosity > 1:
|
||||
self.stdout.write('examining files with the extensions: %s\n'
|
||||
|
||||
@@ -177,7 +177,7 @@ class Deserializer(base.Deserializer):
|
||||
data = {}
|
||||
if node.hasAttribute('pk'):
|
||||
data[Model._meta.pk.attname] = Model._meta.pk.to_python(
|
||||
node.getAttribute('pk'))
|
||||
node.getAttribute('pk'))
|
||||
|
||||
# Also start building a dict of m2m data (this is saved as
|
||||
# {m2m_accessor_attribute : [list_of_related_objects]})
|
||||
@@ -272,15 +272,15 @@ class Deserializer(base.Deserializer):
|
||||
if not model_identifier:
|
||||
raise base.DeserializationError(
|
||||
"<%s> node is missing the required '%s' attribute"
|
||||
% (node.nodeName, attr))
|
||||
% (node.nodeName, attr))
|
||||
try:
|
||||
Model = models.get_model(*model_identifier.split("."))
|
||||
except TypeError:
|
||||
Model = None
|
||||
if Model is None:
|
||||
raise base.DeserializationError(
|
||||
"<%s> node has invalid model identifier: '%s'" %
|
||||
(node.nodeName, model_identifier))
|
||||
"<%s> node has invalid model identifier: '%s'"
|
||||
% (node.nodeName, model_identifier))
|
||||
return Model
|
||||
|
||||
|
||||
|
||||
@@ -107,16 +107,20 @@ class ModelBase(type):
|
||||
|
||||
new_class.add_to_class('_meta', Options(meta, **kwargs))
|
||||
if not abstract:
|
||||
new_class.add_to_class('DoesNotExist', subclass_exception(str('DoesNotExist'),
|
||||
tuple(x.DoesNotExist
|
||||
for x in parents if hasattr(x, '_meta') and not x._meta.abstract)
|
||||
or (ObjectDoesNotExist,),
|
||||
module, attached_to=new_class))
|
||||
new_class.add_to_class('MultipleObjectsReturned', subclass_exception(str('MultipleObjectsReturned'),
|
||||
tuple(x.MultipleObjectsReturned
|
||||
for x in parents if hasattr(x, '_meta') and not x._meta.abstract)
|
||||
or (MultipleObjectsReturned,),
|
||||
module, attached_to=new_class))
|
||||
new_class.add_to_class(
|
||||
'DoesNotExist',
|
||||
subclass_exception(
|
||||
str('DoesNotExist'),
|
||||
tuple(x.DoesNotExist for x in parents if hasattr(x, '_meta') and not x._meta.abstract) or (ObjectDoesNotExist,),
|
||||
module,
|
||||
attached_to=new_class))
|
||||
new_class.add_to_class(
|
||||
'MultipleObjectsReturned',
|
||||
subclass_exception(
|
||||
str('MultipleObjectsReturned'),
|
||||
tuple(x.MultipleObjectsReturned for x in parents if hasattr(x, '_meta') and not x._meta.abstract) or (MultipleObjectsReturned,),
|
||||
module,
|
||||
attached_to=new_class))
|
||||
if base_meta and not base_meta.abstract:
|
||||
# Non-abstract child classes inherit some attributes from their
|
||||
# non-abstract parent (unless an ABC comes before it in the
|
||||
@@ -565,9 +569,9 @@ class Model(six.with_metaclass(ModelBase)):
|
||||
field_names.add(field.attname)
|
||||
deferred_fields = [
|
||||
f.attname for f in self._meta.fields
|
||||
if f.attname not in self.__dict__
|
||||
and isinstance(self.__class__.__dict__[f.attname],
|
||||
DeferredAttribute)]
|
||||
if (f.attname not in self.__dict__ and
|
||||
isinstance(self.__class__.__dict__[f.attname], DeferredAttribute))
|
||||
]
|
||||
|
||||
loaded_fields = field_names.difference(deferred_fields)
|
||||
if loaded_fields:
|
||||
|
||||
@@ -694,7 +694,7 @@ class QuerySet(object):
|
||||
def _filter_or_exclude(self, negate, *args, **kwargs):
|
||||
if args or kwargs:
|
||||
assert self.query.can_filter(), \
|
||||
"Cannot filter a query once a slice has been taken."
|
||||
"Cannot filter a query once a slice has been taken."
|
||||
|
||||
clone = self._clone()
|
||||
if negate:
|
||||
|
||||
@@ -1681,7 +1681,7 @@ class Query(object):
|
||||
count = self.aggregates_module.Count('*', is_summary=True)
|
||||
else:
|
||||
assert len(self.select) == 1, \
|
||||
"Cannot add count col with multiple cols in 'select': %r" % self.select
|
||||
"Cannot add count col with multiple cols in 'select': %r" % self.select
|
||||
count = self.aggregates_module.Count(self.select[0].col)
|
||||
else:
|
||||
opts = self.get_meta()
|
||||
@@ -1693,7 +1693,7 @@ class Query(object):
|
||||
# Because of SQL portability issues, multi-column, distinct
|
||||
# counts need a sub-query -- see get_count() for details.
|
||||
assert len(self.select) == 1, \
|
||||
"Cannot add count col with multiple cols in 'select'."
|
||||
"Cannot add count col with multiple cols in 'select'."
|
||||
|
||||
count = self.aggregates_module.Count(self.select[0].col, distinct=True)
|
||||
# Distinct handling is done in Count(), so don't do it at this
|
||||
|
||||
@@ -262,7 +262,7 @@ class DateTimeQuery(DateQuery):
|
||||
|
||||
def _check_field(self, field):
|
||||
assert isinstance(field, DateTimeField), \
|
||||
"%r isn't a DateTimeField." % field.name
|
||||
"%r isn't a DateTimeField." % field.name
|
||||
|
||||
def _get_select(self, col, lookup_type):
|
||||
if self.tzinfo is None:
|
||||
|
||||
@@ -17,8 +17,8 @@ import warnings
|
||||
from functools import wraps
|
||||
|
||||
from django.db import (
|
||||
connections, DEFAULT_DB_ALIAS,
|
||||
DatabaseError, ProgrammingError)
|
||||
connections, DEFAULT_DB_ALIAS,
|
||||
DatabaseError, ProgrammingError)
|
||||
from django.utils.decorators import available_attrs
|
||||
|
||||
|
||||
|
||||
@@ -687,7 +687,7 @@ class BaseModelFormSet(BaseFormSet):
|
||||
else:
|
||||
return ugettext("Please correct the duplicate data for %(field)s, "
|
||||
"which must be unique.") % {
|
||||
"field": get_text_list(unique_check, six.text_type(_("and"))),
|
||||
"field": get_text_list(unique_check, six.text_type(_("and"))),
|
||||
}
|
||||
|
||||
def get_date_error_message(self, date_check):
|
||||
@@ -1042,8 +1042,8 @@ class ModelChoiceIterator(object):
|
||||
yield self.choice(obj)
|
||||
|
||||
def __len__(self):
|
||||
return len(self.queryset) +\
|
||||
(1 if self.field.empty_label is not None else 0)
|
||||
return (len(self.queryset) +
|
||||
(1 if self.field.empty_label is not None else 0))
|
||||
|
||||
def choice(self, obj):
|
||||
return (self.field.prepare_value(obj), self.field.label_from_instance(obj))
|
||||
|
||||
@@ -62,9 +62,9 @@ class Media(object):
|
||||
# We need to sort the keys, and iterate over the sorted list.
|
||||
media = sorted(self._css.keys())
|
||||
return chain(*[
|
||||
[format_html('<link href="{0}" type="text/css" media="{1}" rel="stylesheet" />', self.absolute_path(path), medium)
|
||||
for path in self._css[medium]]
|
||||
for medium in media])
|
||||
[format_html('<link href="{0}" type="text/css" media="{1}" rel="stylesheet" />', self.absolute_path(path), medium)
|
||||
for path in self._css[medium]]
|
||||
for medium in media])
|
||||
|
||||
def absolute_path(self, path, prefix=None):
|
||||
if path.startswith(('http://', 'https://', '/')):
|
||||
|
||||
@@ -59,8 +59,8 @@ def fix_IE_for_attach(request, response):
|
||||
pass
|
||||
if response.has_header('Cache-Control'):
|
||||
cache_control_values = [value.strip() for value in
|
||||
response['Cache-Control'].split(',')
|
||||
if value.strip().lower() not in offending_headers]
|
||||
response['Cache-Control'].split(',')
|
||||
if value.strip().lower() not in offending_headers]
|
||||
|
||||
if not len(cache_control_values):
|
||||
del response['Cache-Control']
|
||||
|
||||
@@ -38,7 +38,7 @@ class LocaleMiddleware(object):
|
||||
def process_response(self, request, response):
|
||||
language = translation.get_language()
|
||||
language_from_path = translation.get_language_from_path(
|
||||
request.path_info, supported=self._supported_languages
|
||||
request.path_info, supported=self._supported_languages
|
||||
)
|
||||
if (response.status_code == 404 and not language_from_path
|
||||
and self.is_language_prefix_patterns_used()):
|
||||
|
||||
@@ -279,7 +279,7 @@ def setup_databases(verbosity, interactive, **kwargs):
|
||||
connection = connections[alias]
|
||||
if test_db_name is None:
|
||||
test_db_name = connection.creation.create_test_db(
|
||||
verbosity, autoclobber=not interactive)
|
||||
verbosity, autoclobber=not interactive)
|
||||
destroy = True
|
||||
else:
|
||||
connection.settings_dict['NAME'] = test_db_name
|
||||
|
||||
@@ -740,7 +740,7 @@ class TransactionTestCase(SimpleTestCase):
|
||||
conn = connections[db_name]
|
||||
if conn.features.supports_sequence_reset:
|
||||
sql_list = conn.ops.sequence_reset_by_name_sql(
|
||||
no_style(), conn.introspection.sequence_list())
|
||||
no_style(), conn.introspection.sequence_list())
|
||||
if sql_list:
|
||||
with transaction.commit_on_success_unless_managed(using=db_name):
|
||||
cursor = conn.cursor()
|
||||
|
||||
@@ -97,8 +97,8 @@ def format_html_join(sep, format_string, args_generator):
|
||||
|
||||
"""
|
||||
return mark_safe(conditional_escape(sep).join(
|
||||
format_html(format_string, *tuple(args))
|
||||
for args in args_generator))
|
||||
format_html(format_string, *tuple(args))
|
||||
for args in args_generator))
|
||||
|
||||
|
||||
def linebreaks(value, autoescape=False):
|
||||
|
||||
@@ -14,8 +14,8 @@ from django.utils.encoding import force_str, force_text
|
||||
from django.utils.functional import allow_lazy
|
||||
from django.utils import six
|
||||
from django.utils.six.moves.urllib.parse import (
|
||||
quote, quote_plus, unquote, unquote_plus, urlparse,
|
||||
urlencode as original_urlencode)
|
||||
quote, quote_plus, unquote, unquote_plus, urlparse,
|
||||
urlencode as original_urlencode)
|
||||
|
||||
ETAG_MATCH = re.compile(r'(?:W/)?"((?:\\.|[^"])*)"')
|
||||
|
||||
|
||||
@@ -143,14 +143,14 @@ class JsLexer(Lexer):
|
||||
]
|
||||
|
||||
states = {
|
||||
'div': # slash will mean division
|
||||
both_before + [
|
||||
Tok("punct", literals("/= /"), next='reg'),
|
||||
] + both_after,
|
||||
# slash will mean division
|
||||
'div': both_before + [
|
||||
Tok("punct", literals("/= /"), next='reg'),
|
||||
] + both_after,
|
||||
|
||||
'reg': # slash will mean regex
|
||||
both_before + [
|
||||
Tok("regex",
|
||||
# slash will mean regex
|
||||
'reg': both_before + [
|
||||
Tok("regex",
|
||||
r"""
|
||||
/ # opening slash
|
||||
# First character is..
|
||||
@@ -174,7 +174,7 @@ class JsLexer(Lexer):
|
||||
/ # closing slash
|
||||
[a-zA-Z0-9]* # trailing flags
|
||||
""", next='div'),
|
||||
] + both_after,
|
||||
] + both_after,
|
||||
}
|
||||
|
||||
def __init__(self):
|
||||
|
||||
@@ -136,7 +136,7 @@ class LocalTimezone(ReferenceLocalTimezone):
|
||||
except (OverflowError, ValueError) as exc:
|
||||
exc_type = type(exc)
|
||||
exc_value = exc_type(
|
||||
"Unsupported value: %r. You should install pytz." % dt)
|
||||
"Unsupported value: %r. You should install pytz." % dt)
|
||||
exc_value.__cause__ = exc
|
||||
six.reraise(exc_type, exc_value, sys.exc_info()[2])
|
||||
|
||||
|
||||
@@ -366,7 +366,7 @@ class BaseDateListView(MultipleObjectMixin, DateMixin, View):
|
||||
is_empty = len(qs) == 0 if paginate_by is None else not qs.exists()
|
||||
if is_empty:
|
||||
raise Http404(_("No %(verbose_name_plural)s available") % {
|
||||
'verbose_name_plural': force_text(qs.model._meta.verbose_name_plural)
|
||||
'verbose_name_plural': force_text(qs.model._meta.verbose_name_plural)
|
||||
})
|
||||
|
||||
return qs
|
||||
|
||||
@@ -65,8 +65,8 @@ class MultipleObjectMixin(ContextMixin):
|
||||
return (paginator, page, page.object_list, page.has_other_pages())
|
||||
except InvalidPage as e:
|
||||
raise Http404(_('Invalid page (%(page_number)s): %(message)s') % {
|
||||
'page_number': page_number,
|
||||
'message': str(e)
|
||||
'page_number': page_number,
|
||||
'message': str(e)
|
||||
})
|
||||
|
||||
def get_paginate_by(self, queryset):
|
||||
|
||||
Reference in New Issue
Block a user