flake8 fixes
parent
3170ea95c2
commit
4aa3355f5c
|
|
@ -6,12 +6,13 @@ Copyright:
|
||||||
This code and affiliated files are (C) by Bert Constantin and individual contributors.
|
This code and affiliated files are (C) by Bert Constantin and individual contributors.
|
||||||
Please see LICENSE and AUTHORS for more information.
|
Please see LICENSE and AUTHORS for more information.
|
||||||
"""
|
"""
|
||||||
|
import django
|
||||||
|
|
||||||
# See PEP 440 (https://www.python.org/dev/peps/pep-0440/)
|
# See PEP 440 (https://www.python.org/dev/peps/pep-0440/)
|
||||||
__version__ = "1.0.2"
|
__version__ = "1.0.2"
|
||||||
|
|
||||||
|
|
||||||
# Monkey-patch Django < 1.5 to allow ContentTypes for proxy models.
|
# Monkey-patch Django < 1.5 to allow ContentTypes for proxy models.
|
||||||
import django
|
|
||||||
if django.VERSION[:2] < (1, 5):
|
if django.VERSION[:2] < (1, 5):
|
||||||
from django.contrib.contenttypes.models import ContentTypeManager
|
from django.contrib.contenttypes.models import ContentTypeManager
|
||||||
from django.utils.encoding import smart_text
|
from django.utils.encoding import smart_text
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,7 @@ __all__ = (
|
||||||
'PolymorphicInlineAdminFormSet',
|
'PolymorphicInlineAdminFormSet',
|
||||||
'PolymorphicInlineSupportMixin',
|
'PolymorphicInlineSupportMixin',
|
||||||
'PolymorphicInlineModelAdmin',
|
'PolymorphicInlineModelAdmin',
|
||||||
|
'StackedPolymorphicInline',
|
||||||
'GenericPolymorphicInlineModelAdmin',
|
'GenericPolymorphicInlineModelAdmin',
|
||||||
'GenericStackedPolymorphicInline',
|
'GenericStackedPolymorphicInline',
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -225,7 +225,7 @@ class PolymorphicInlineModelAdmin(InlineModelAdmin):
|
||||||
# InlineModelAdmin doesn't define its own.
|
# InlineModelAdmin doesn't define its own.
|
||||||
exclude.extend(self.form._meta.exclude)
|
exclude.extend(self.form._meta.exclude)
|
||||||
|
|
||||||
#can_delete = self.can_delete and self.has_delete_permission(request, obj)
|
# can_delete = self.can_delete and self.has_delete_permission(request, obj)
|
||||||
defaults = {
|
defaults = {
|
||||||
"form": self.form,
|
"form": self.form,
|
||||||
"fields": fields,
|
"fields": fields,
|
||||||
|
|
|
||||||
|
|
@ -91,17 +91,17 @@ def generic_polymorphic_inlineformset_factory(model, formset_children, form=Mode
|
||||||
'validate_min': validate_min,
|
'validate_min': validate_min,
|
||||||
'validate_max': validate_max,
|
'validate_max': validate_max,
|
||||||
'for_concrete_model': for_concrete_model,
|
'for_concrete_model': for_concrete_model,
|
||||||
#'localized_fields': localized_fields,
|
# 'localized_fields': localized_fields,
|
||||||
#'labels': labels,
|
# 'labels': labels,
|
||||||
#'help_texts': help_texts,
|
# 'help_texts': help_texts,
|
||||||
#'error_messages': error_messages,
|
# 'error_messages': error_messages,
|
||||||
#'field_classes': field_classes,
|
# 'field_classes': field_classes,
|
||||||
}
|
}
|
||||||
if child_form_kwargs is None:
|
if child_form_kwargs is None:
|
||||||
child_form_kwargs = {}
|
child_form_kwargs = {}
|
||||||
|
|
||||||
child_kwargs = {
|
child_kwargs = {
|
||||||
#'exclude': exclude,
|
# 'exclude': exclude,
|
||||||
'ct_field': ct_field,
|
'ct_field': ct_field,
|
||||||
'fk_field': fk_field,
|
'fk_field': fk_field,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -63,12 +63,12 @@ class PolymorphicFormSetChild(object):
|
||||||
'formfield_callback': self.formfield_callback,
|
'formfield_callback': self.formfield_callback,
|
||||||
'fields': self.fields,
|
'fields': self.fields,
|
||||||
'exclude': exclude,
|
'exclude': exclude,
|
||||||
#'for_concrete_model': for_concrete_model,
|
# 'for_concrete_model': for_concrete_model,
|
||||||
'localized_fields': self.localized_fields,
|
'localized_fields': self.localized_fields,
|
||||||
'labels': self.labels,
|
'labels': self.labels,
|
||||||
'help_texts': self.help_texts,
|
'help_texts': self.help_texts,
|
||||||
'error_messages': self.error_messages,
|
'error_messages': self.error_messages,
|
||||||
#'field_classes': field_classes,
|
# 'field_classes': field_classes,
|
||||||
}
|
}
|
||||||
defaults.update(kwargs)
|
defaults.update(kwargs)
|
||||||
|
|
||||||
|
|
@ -293,7 +293,7 @@ def polymorphic_modelformset_factory(model, formset_children,
|
||||||
FormSet = modelformset_factory(**kwargs)
|
FormSet = modelformset_factory(**kwargs)
|
||||||
|
|
||||||
child_kwargs = {
|
child_kwargs = {
|
||||||
#'exclude': exclude,
|
# 'exclude': exclude,
|
||||||
}
|
}
|
||||||
if child_form_kwargs:
|
if child_form_kwargs:
|
||||||
child_kwargs.update(child_form_kwargs)
|
child_kwargs.update(child_form_kwargs)
|
||||||
|
|
@ -359,7 +359,7 @@ def polymorphic_inlineformset_factory(parent_model, model, formset_children,
|
||||||
FormSet = inlineformset_factory(**kwargs)
|
FormSet = inlineformset_factory(**kwargs)
|
||||||
|
|
||||||
child_kwargs = {
|
child_kwargs = {
|
||||||
#'exclude': exclude,
|
# 'exclude': exclude,
|
||||||
}
|
}
|
||||||
if child_form_kwargs:
|
if child_form_kwargs:
|
||||||
child_kwargs.update(child_form_kwargs)
|
child_kwargs.update(child_form_kwargs)
|
||||||
|
|
|
||||||
|
|
@ -187,7 +187,7 @@ class PolymorphicModel(six.with_metaclass(PolymorphicModelBase, models.Model)):
|
||||||
for name, model in subclasses_and_superclasses_accessors.items():
|
for name, model in subclasses_and_superclasses_accessors.items():
|
||||||
orig_accessor = getattr(self.__class__, name, None)
|
orig_accessor = getattr(self.__class__, name, None)
|
||||||
if type(orig_accessor) in [ReverseOneToOneDescriptor, ForwardManyToOneDescriptor]:
|
if type(orig_accessor) in [ReverseOneToOneDescriptor, ForwardManyToOneDescriptor]:
|
||||||
#print >>sys.stderr, '---------- replacing', name, orig_accessor, '->', model
|
# print >>sys.stderr, '---------- replacing', name, orig_accessor, '->', model
|
||||||
setattr(self.__class__, name, property(create_accessor_function_for_model(model, name)))
|
setattr(self.__class__, name, property(create_accessor_function_for_model(model, name)))
|
||||||
|
|
||||||
def _get_inheritance_relation_fields_and_models(self):
|
def _get_inheritance_relation_fields_and_models(self):
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ def transmogrify(cls, obj):
|
||||||
"""
|
"""
|
||||||
Upcast a class to a different type without asking questions.
|
Upcast a class to a different type without asking questions.
|
||||||
"""
|
"""
|
||||||
if not '__init__' in obj.__dict__:
|
if '__init__' not in obj.__dict__:
|
||||||
# Just assign __class__ to a different value.
|
# Just assign __class__ to a different value.
|
||||||
new = obj
|
new = obj
|
||||||
new.__class__ = cls
|
new.__class__ = cls
|
||||||
|
|
@ -317,7 +317,7 @@ class PolymorphicQuerySet(QuerySet):
|
||||||
ordered_id_list.append(base_object.pk)
|
ordered_id_list.append(base_object.pk)
|
||||||
|
|
||||||
# check if id of the result object occurres more than once - this can happen e.g. with base_objects.extra(tables=...)
|
# check if id of the result object occurres more than once - this can happen e.g. with base_objects.extra(tables=...)
|
||||||
if not base_object.pk in base_result_objects_by_id:
|
if base_object.pk not in base_result_objects_by_id:
|
||||||
base_result_objects_by_id[base_object.pk] = base_object
|
base_result_objects_by_id[base_object.pk] = base_object
|
||||||
|
|
||||||
if base_object.polymorphic_ctype_id == self_model_class_id:
|
if base_object.polymorphic_ctype_id == self_model_class_id:
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ from __future__ import absolute_import
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
import django
|
import django
|
||||||
|
from functools import reduce
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.db.models import Q, FieldDoesNotExist
|
from django.db.models import Q, FieldDoesNotExist
|
||||||
|
|
@ -26,9 +27,6 @@ else:
|
||||||
REL_FIELD_CLASSES = (RelatedField, ForeignObjectRel)
|
REL_FIELD_CLASSES = (RelatedField, ForeignObjectRel)
|
||||||
|
|
||||||
|
|
||||||
from functools import reduce
|
|
||||||
|
|
||||||
|
|
||||||
###################################################################################
|
###################################################################################
|
||||||
# PolymorphicQuerySet support functions
|
# PolymorphicQuerySet support functions
|
||||||
|
|
||||||
|
|
@ -128,7 +126,7 @@ def _translate_polymorphic_filter_definition(queryset_model, field_path, field_v
|
||||||
return _create_model_filter_Q(field_val, using=using)
|
return _create_model_filter_Q(field_val, using=using)
|
||||||
elif field_path == 'not_instance_of':
|
elif field_path == 'not_instance_of':
|
||||||
return _create_model_filter_Q(field_val, not_instance_of=True, using=using)
|
return _create_model_filter_Q(field_val, not_instance_of=True, using=using)
|
||||||
elif not '___' in field_path:
|
elif '___' not in field_path:
|
||||||
return None # no change
|
return None # no change
|
||||||
|
|
||||||
# filter expression contains '___' (i.e. filter for polymorphic field)
|
# filter expression contains '___' (i.e. filter for polymorphic field)
|
||||||
|
|
|
||||||
|
|
@ -136,7 +136,7 @@ class ShowFieldBase(object):
|
||||||
|
|
||||||
if (self.polymorphic_showfield_max_line_width
|
if (self.polymorphic_showfield_max_line_width
|
||||||
and xpos + len(p) > self.polymorphic_showfield_max_line_width
|
and xpos + len(p) > self.polymorphic_showfield_max_line_width
|
||||||
and possible_line_break_pos != None):
|
and possible_line_break_pos is not None):
|
||||||
rest = out[possible_line_break_pos:]
|
rest = out[possible_line_break_pos:]
|
||||||
out = out[:possible_line_break_pos]
|
out = out[:possible_line_break_pos]
|
||||||
out += '\n' + indentstr + rest
|
out += '\n' + indentstr + rest
|
||||||
|
|
|
||||||
|
|
@ -6,17 +6,10 @@ from __future__ import print_function
|
||||||
import uuid
|
import uuid
|
||||||
import re
|
import re
|
||||||
import django
|
import django
|
||||||
try:
|
|
||||||
from unittest import skipIf
|
|
||||||
except ImportError:
|
|
||||||
# python<2.7
|
|
||||||
from django.utils.unittest import skipIf
|
|
||||||
from django.db.models.query import QuerySet
|
from django.db.models.query import QuerySet
|
||||||
|
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.db.models import Q, Count
|
from django.db.models import Q, Count
|
||||||
if django.VERSION >= (1, 8):
|
|
||||||
from django.db.models import Case, When
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.utils import six
|
from django.utils import six
|
||||||
|
|
@ -26,6 +19,16 @@ from polymorphic.models import PolymorphicModel
|
||||||
from polymorphic.managers import PolymorphicManager
|
from polymorphic.managers import PolymorphicManager
|
||||||
from polymorphic.query import PolymorphicQuerySet
|
from polymorphic.query import PolymorphicQuerySet
|
||||||
from polymorphic.showfields import ShowFieldContent, ShowFieldType, ShowFieldTypeAndContent
|
from polymorphic.showfields import ShowFieldContent, ShowFieldType, ShowFieldTypeAndContent
|
||||||
|
|
||||||
|
try:
|
||||||
|
from unittest import skipIf
|
||||||
|
except ImportError:
|
||||||
|
# python<2.7
|
||||||
|
from django.utils.unittest import skipIf
|
||||||
|
|
||||||
|
if django.VERSION >= (1, 8):
|
||||||
|
from django.db.models import Case, When
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from django.db.models import UUIDField
|
from django.db.models import UUIDField
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue