Corrected black code wrapping when lines had long comments.

fix_request_path_info
Diederik van der Boor 2019-07-15 18:09:27 +02:00
parent 6af023dafd
commit db864cd8a8
No known key found for this signature in database
GPG Key ID: 4FA014E0305E73C1
9 changed files with 50 additions and 66 deletions

View File

@ -32,9 +32,8 @@ class PolymorphicInlineAdminFormSet(InlineAdminFormSet):
"""
def __init__(self, *args, **kwargs):
self.request = kwargs.pop(
"request", None
) # Assigned later via PolymorphicInlineSupportMixin later.
# Assigned later via PolymorphicInlineSupportMixin later.
self.request = kwargs.pop("request", None)
self.obj = kwargs.pop("obj", None)
super(PolymorphicInlineAdminFormSet, self).__init__(*args, **kwargs)

View File

@ -229,9 +229,8 @@ class PolymorphicInlineModelAdmin(InlineModelAdmin):
exclude = list(self.exclude)
exclude.extend(self.get_readonly_fields(request, obj))
exclude.append(
"polymorphic_ctype"
) # Django 1.10 blocks it, as it's a readonly field.
# Add forcefully, as Django 1.10 doesn't include readonly fields.
exclude.append("polymorphic_ctype")
if (
self.exclude is None

View File

@ -177,9 +177,8 @@ class PolymorphicParentModelAdmin(admin.ModelAdmin):
model_class = ct.model_class()
if not model_class:
raise Http404(
"No model found for '{0}.{1}'.".format(*ct.natural_key())
) # Handle model deletion
# Handle model deletion
raise Http404("No model found for '{0}.{1}'.".format(*ct.natural_key()))
return self._get_real_admin_by_model(model_class, super_if_self=super_if_self)

View File

@ -28,9 +28,8 @@ class PolymorphicManager(models.Manager):
manager = super(PolymorphicManager, cls).from_queryset(
queryset_class, class_name=class_name
)
manager.queryset_class = (
queryset_class
) # also set our version, Django uses _queryset_class
# also set our version, Django uses _queryset_class
manager.queryset_class = queryset_class
return manager
def get_queryset(self):

View File

@ -245,26 +245,23 @@ class PolymorphicModel(with_metaclass(PolymorphicModelBase, models.Model)):
def add_all_super_models(model, result):
for super_cls, field_to_super in model._meta.parents.items():
if field_to_super is not None: # if not a link to a proxy model
field_name = (
field_to_super.name
) # the field on model can have a different name to super_cls._meta.module_name, if the field is created manually using 'parent_link'
if field_to_super is not None:
# if not a link to a proxy model, the field on model can have
# a different name to super_cls._meta.module_name, when the field
# is created manually using 'parent_link'
field_name = field_to_super.name
add_model_if_regular(super_cls, field_name, result)
add_all_super_models(super_cls, result)
def add_all_sub_models(super_cls, result):
for (
sub_cls
) in super_cls.__subclasses__(): # go through all subclasses of model
if (
super_cls in sub_cls._meta.parents
): # super_cls may not be in sub_cls._meta.parents if super_cls is a proxy model
field_to_super = sub_cls._meta.parents[
super_cls
] # get the field that links sub_cls to super_cls
if (
field_to_super is not None
): # if filed_to_super is not a link to a proxy model
# go through all subclasses of model
for sub_cls in super_cls.__subclasses__():
# super_cls may not be in sub_cls._meta.parents if super_cls is a proxy model
if super_cls in sub_cls._meta.parents:
# get the field that links sub_cls to super_cls
field_to_super = sub_cls._meta.parents[super_cls]
# if filed_to_super is not a link to a proxy model
if field_to_super is not None:
super_to_sub_related_field = field_to_super.remote_field
if super_to_sub_related_field.related_name is None:
# if related name is None the related field is the name of the subclass

View File

@ -164,10 +164,11 @@ class PolymorphicQuerySet(QuerySet):
# We override this internal Django functon as it is used for all filter member functions.
q_objects = translate_polymorphic_filter_definitions_in_args(
self.model, args, using=self.db
) # the Q objects
)
# filter_field='data'
additional_args = translate_polymorphic_filter_definitions_in_kwargs(
self.model, kwargs, using=self.db
) # filter_field='data'
)
return super(PolymorphicQuerySet, self)._filter_or_exclude(
negate, *(list(q_objects) + additional_args), **kwargs
)
@ -408,9 +409,8 @@ class PolymorphicQuerySet(QuerySet):
real_objects = real_concrete_class._base_objects.db_manager(self.db).filter(
**{("%s__in" % pk_name): idlist}
)
real_objects.query.select_related = (
self.query.select_related
) # copy select related configuration to new qs
# copy select related configuration to new qs
real_objects.query.select_related = self.query.select_related
# Copy deferred fields configuration to the new queryset
deferred_loading_fields = []
@ -479,17 +479,15 @@ class PolymorphicQuerySet(QuerySet):
# set polymorphic_annotate_names in all objects (currently just used for debugging/printing)
if self.query.annotations:
annotate_names = list(
self.query.annotations.keys()
) # get annotate field list
# get annotate field list
annotate_names = list(self.query.annotations.keys())
for real_object in resultlist:
real_object.polymorphic_annotate_names = annotate_names
# set polymorphic_extra_select_names in all objects (currently just used for debugging/printing)
if self.query.extra_select:
extra_select_names = list(
self.query.extra_select.keys()
) # get extra select field list
# get extra select field list
extra_select_names = list(self.query.extra_select.keys())
for real_object in resultlist:
real_object.polymorphic_extra_select_names = extra_select_names

View File

@ -13,9 +13,8 @@ RE_DEFERRED = re.compile("_Deferred_.*")
class ShowFieldBase(object):
""" base class for the ShowField... model mixins, does the work """
polymorphic_query_multiline_output = (
True
) # cause nicer multiline PolymorphicQuery output
# cause nicer multiline PolymorphicQuery output
polymorphic_query_multiline_output = True
polymorphic_showfield_type = False
polymorphic_showfield_content = False

View File

@ -157,9 +157,8 @@ class ModelUnderRelChild(PolymorphicModel):
class MyManagerQuerySet(PolymorphicQuerySet):
def my_queryset_foo(self):
return (
self.all()
) # Just a method to prove the existance of the custom queryset.
# Just a method to prove the existence of the custom queryset.
return self.all()
class MyManager(PolymorphicManager):
@ -205,9 +204,8 @@ class MROBase2(MROBase1):
class MROBase3(models.Model):
base_3_id = models.AutoField(
primary_key=True
) # make sure 'id' field doesn't clash, detected by Django 1.11
# make sure 'id' field doesn't clash, detected by Django 1.11
base_3_id = models.AutoField(primary_key=True)
objects = models.Manager()
@ -232,9 +230,8 @@ class ChildModelWithManager(PolymorphicModel):
class PlainMyManagerQuerySet(QuerySet):
def my_queryset_foo(self):
return (
self.all()
) # Just a method to prove the existence of the custom queryset.
# Just a method to prove the existence of the custom queryset.
return self.all()
class PlainMyManager(models.Manager):

View File

@ -812,9 +812,8 @@ class PolymorphicTests(TransactionTestCase):
ModelWithMyManager.objects.create(field1="D1a", field4="D4a")
ModelWithMyManager.objects.create(field1="D1b", field4="D4b")
objects = (
ModelWithMyManager.objects.all()
) # MyManager should reverse the sorting of field1
# MyManager should reverse the sorting of field1
objects = ModelWithMyManager.objects.all()
self.assertQuerysetEqual(
objects,
[(ModelWithMyManager, "D1b", "D4b"), (ModelWithMyManager, "D1a", "D4a")],
@ -830,9 +829,8 @@ class PolymorphicTests(TransactionTestCase):
ModelWithMyManagerNoDefault.objects.create(field1="D1a", field4="D4a")
ModelWithMyManagerNoDefault.objects.create(field1="D1b", field4="D4b")
objects = (
ModelWithMyManagerNoDefault.my_objects.all()
) # MyManager should reverse the sorting of field1
# MyManager should reverse the sorting of field1
objects = ModelWithMyManagerNoDefault.my_objects.all()
self.assertQuerysetEqual(
objects,
[
@ -1049,9 +1047,8 @@ class PolymorphicTests(TransactionTestCase):
p = ModelShow1_plain.objects.non_polymorphic().get(
field1="TestParentLinkAndRelatedName"
)
self.assertNotEqual(
p, t
) # p should be Plain1 and t TestParentLinkAndRelatedName, so not equal
# p should be Plain1 and t TestParentLinkAndRelatedName, so not equal
self.assertNotEqual(p, t)
self.assertEqual(p, t.superclass)
self.assertEqual(p.related_name_subclass, t)
@ -1228,12 +1225,12 @@ class PolymorphicTests(TransactionTestCase):
qs = RelatingModel.objects.order_by("pk").prefetch_related("many2many")
objects = list(qs)
self.assertEqual(len(objects[0].many2many.all()), 1)
self.assertEqual(
len(objects[1].many2many.all()), 0
) # derived object was not fetched
self.assertEqual(
len(objects[1].many2many.non_polymorphic()), 1
) # base object does exist
# derived object was not fetched
self.assertEqual(len(objects[1].many2many.all()), 0)
# base object does exist
self.assertEqual(len(objects[1].many2many.non_polymorphic()), 1)
def test_refresh_from_db_fields(self):
"""Test whether refresh_from_db(fields=..) works as it performs .only() queries"""