Fix PEP8 block comment issues (E265)
parent
aaf06c71a5
commit
b7431b2d06
|
|
@ -96,7 +96,7 @@ def poly_sql_query():
|
||||||
WHERE pexp_modela.field1=%i
|
WHERE pexp_modela.field1=%i
|
||||||
ORDER BY pexp_modela.id
|
ORDER BY pexp_modela.id
|
||||||
""" % rnd.randint(0, 100) )
|
""" % rnd.randint(0, 100) )
|
||||||
#row=cursor.fetchone()
|
# row=cursor.fetchone()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -108,5 +108,5 @@ def poly_sql_query2():
|
||||||
WHERE pexp_modela.field1=%i
|
WHERE pexp_modela.field1=%i
|
||||||
ORDER BY pexp_modela.id
|
ORDER BY pexp_modela.id
|
||||||
""" % rnd.randint(0, 100) )
|
""" % rnd.randint(0, 100) )
|
||||||
#row=cursor.fetchone()
|
# row=cursor.fetchone()
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ def show_queries():
|
||||||
import time
|
import time
|
||||||
|
|
||||||
###################################################################################
|
###################################################################################
|
||||||
### benchmark wrappers
|
# benchmark wrappers
|
||||||
|
|
||||||
|
|
||||||
def print_timing(func, message='', iterations=1):
|
def print_timing(func, message='', iterations=1):
|
||||||
|
|
@ -54,12 +54,12 @@ def run_vanilla_any_poly(func, iterations=1):
|
||||||
|
|
||||||
|
|
||||||
###################################################################################
|
###################################################################################
|
||||||
### benchmarks
|
# benchmarks
|
||||||
|
|
||||||
def bench_create(model):
|
def bench_create(model):
|
||||||
for i in xrange(num_objects):
|
for i in xrange(num_objects):
|
||||||
model.objects.create(field1='abc' + str(i), field2='abcd' + str(i), field3='abcde' + str(i))
|
model.objects.create(field1='abc' + str(i), field2='abcd' + str(i), field3='abcde' + str(i))
|
||||||
#print 'count:',model.objects.count()
|
# print 'count:',model.objects.count()
|
||||||
|
|
||||||
|
|
||||||
def bench_load1(model):
|
def bench_load1(model):
|
||||||
|
|
@ -92,7 +92,7 @@ def bench_delete(model):
|
||||||
model.objects.all().delete()
|
model.objects.all().delete()
|
||||||
|
|
||||||
###################################################################################
|
###################################################################################
|
||||||
### Command
|
# Command
|
||||||
|
|
||||||
|
|
||||||
class Command(NoArgsCommand):
|
class Command(NoArgsCommand):
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ except ImportError:
|
||||||
|
|
||||||
|
|
||||||
###################################################################################
|
###################################################################################
|
||||||
### PolymorphicModel meta class
|
# PolymorphicModel meta class
|
||||||
|
|
||||||
class PolymorphicModelBase(ModelBase):
|
class PolymorphicModelBase(ModelBase):
|
||||||
"""
|
"""
|
||||||
|
|
@ -53,7 +53,7 @@ class PolymorphicModelBase(ModelBase):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __new__(self, model_name, bases, attrs):
|
def __new__(self, model_name, bases, attrs):
|
||||||
#print; print '###', model_name, '- bases:', bases
|
# print; print '###', model_name, '- bases:', bases
|
||||||
|
|
||||||
# Workaround compatibility issue with six.with_metaclass() and custom Django model metaclasses:
|
# Workaround compatibility issue with six.with_metaclass() and custom Django model metaclasses:
|
||||||
if not attrs and model_name == 'NewBase':
|
if not attrs and model_name == 'NewBase':
|
||||||
|
|
@ -75,7 +75,7 @@ class PolymorphicModelBase(ModelBase):
|
||||||
|
|
||||||
# add the managers to the new model
|
# add the managers to the new model
|
||||||
for source_name, mgr_name, manager in inherited_managers:
|
for source_name, mgr_name, manager in inherited_managers:
|
||||||
#print '** add inherited manager from model %s, manager %s, %s' % (source_name, mgr_name, manager.__class__.__name__)
|
# print '** add inherited manager from model %s, manager %s, %s' % (source_name, mgr_name, manager.__class__.__name__)
|
||||||
new_manager = manager._copy_to_model(new_class)
|
new_manager = manager._copy_to_model(new_class)
|
||||||
if mgr_name == '_default_manager':
|
if mgr_name == '_default_manager':
|
||||||
new_class._default_manager = new_manager
|
new_class._default_manager = new_manager
|
||||||
|
|
@ -86,7 +86,7 @@ class PolymorphicModelBase(ModelBase):
|
||||||
# this value is used by the related objects, restoring access to custom queryset methods on related objects.
|
# this value is used by the related objects, restoring access to custom queryset methods on related objects.
|
||||||
user_manager = self.get_first_user_defined_manager(new_class)
|
user_manager = self.get_first_user_defined_manager(new_class)
|
||||||
if user_manager:
|
if user_manager:
|
||||||
#print '## add default manager', type(def_mgr)
|
# print '## add default manager', type(def_mgr)
|
||||||
new_class._default_manager = user_manager._copy_to_model(new_class)
|
new_class._default_manager = user_manager._copy_to_model(new_class)
|
||||||
new_class._default_manager._inherited = False # the default mgr was defined by the user, not inherited
|
new_class._default_manager._inherited = False # the default mgr was defined by the user, not inherited
|
||||||
|
|
||||||
|
|
@ -111,7 +111,7 @@ class PolymorphicModelBase(ModelBase):
|
||||||
use correct mro, only use managers with _inherited==False (they are of no use),
|
use correct mro, only use managers with _inherited==False (they are of no use),
|
||||||
skip managers that are overwritten by the user with same-named class attributes (in attrs)
|
skip managers that are overwritten by the user with same-named class attributes (in attrs)
|
||||||
"""
|
"""
|
||||||
#print "** ", self.__name__
|
# print "** ", self.__name__
|
||||||
add_managers = []
|
add_managers = []
|
||||||
add_managers_keys = set()
|
add_managers_keys = set()
|
||||||
for base in self.__mro__[1:]:
|
for base in self.__mro__[1:]:
|
||||||
|
|
@ -147,7 +147,7 @@ class PolymorphicModelBase(ModelBase):
|
||||||
continue # manager with that name already added, skip
|
continue # manager with that name already added, skip
|
||||||
if manager._inherited:
|
if manager._inherited:
|
||||||
continue # inherited managers (on the bases) have no significance, they are just copies
|
continue # inherited managers (on the bases) have no significance, they are just copies
|
||||||
#print '## {0} {1}'.format(self.__name__, key)
|
# print '## {0} {1}'.format(self.__name__, key)
|
||||||
|
|
||||||
if isinstance(manager, PolymorphicManager): # validate any inherited polymorphic managers
|
if isinstance(manager, PolymorphicManager): # validate any inherited polymorphic managers
|
||||||
self.validate_model_manager(manager, self.__name__, key)
|
self.validate_model_manager(manager, self.__name__, key)
|
||||||
|
|
@ -175,7 +175,7 @@ class PolymorphicModelBase(ModelBase):
|
||||||
# if there are user defined managers, use first one as _default_manager
|
# if there are user defined managers, use first one as _default_manager
|
||||||
if mgr_list:
|
if mgr_list:
|
||||||
_, manager_name, manager = sorted(mgr_list)[0]
|
_, manager_name, manager = sorted(mgr_list)[0]
|
||||||
#sys.stderr.write( '\n# first user defined manager for model "{model}":\n# "{mgrname}": {mgr}\n# manager model: {mgrmodel}\n\n'
|
# sys.stderr.write( '\n# first user defined manager for model "{model}":\n# "{mgrname}": {mgr}\n# manager model: {mgrmodel}\n\n'
|
||||||
# .format( model=self.__name__, mgrname=manager_name, mgr=manager, mgrmodel=manager.model ) )
|
# .format( model=self.__name__, mgrname=manager_name, mgr=manager, mgrmodel=manager.model ) )
|
||||||
return manager
|
return manager
|
||||||
return None
|
return None
|
||||||
|
|
@ -241,8 +241,8 @@ class PolymorphicModelBase(ModelBase):
|
||||||
frm = inspect.stack()[1] # frm[1] is caller file name, frm[3] is caller function name
|
frm = inspect.stack()[1] # frm[1] is caller file name, frm[3] is caller function name
|
||||||
if 'django/core/management/commands/dumpdata.py' in frm[1]:
|
if 'django/core/management/commands/dumpdata.py' in frm[1]:
|
||||||
return self.base_objects
|
return self.base_objects
|
||||||
#caller_mod_name = inspect.getmodule(frm[0]).__name__ # does not work with python 2.4
|
# caller_mod_name = inspect.getmodule(frm[0]).__name__ # does not work with python 2.4
|
||||||
#if caller_mod_name == 'django.core.management.commands.dumpdata':
|
# if caller_mod_name == 'django.core.management.commands.dumpdata':
|
||||||
|
|
||||||
return super(PolymorphicModelBase, self).__getattribute__(name)
|
return super(PolymorphicModelBase, self).__getattribute__(name)
|
||||||
# TODO: investigate Django how this can be avoided
|
# TODO: investigate Django how this can be avoided
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ from .manager import PolymorphicManager
|
||||||
from .query_translate import translate_polymorphic_Q_object
|
from .query_translate import translate_polymorphic_Q_object
|
||||||
|
|
||||||
###################################################################################
|
###################################################################################
|
||||||
### PolymorphicModel
|
# PolymorphicModel
|
||||||
|
|
||||||
|
|
||||||
class PolymorphicModel(six.with_metaclass(PolymorphicModelBase, models.Model)):
|
class PolymorphicModel(six.with_metaclass(PolymorphicModelBase, models.Model)):
|
||||||
|
|
@ -216,10 +216,10 @@ class PolymorphicModel(six.with_metaclass(PolymorphicModelBase, models.Model)):
|
||||||
if field_to_super is not None: # if filed_to_super is not a link to a proxy model
|
if field_to_super is not None: # if filed_to_super is not a link to a proxy model
|
||||||
super_to_sub_related_field = field_to_super.rel
|
super_to_sub_related_field = field_to_super.rel
|
||||||
if super_to_sub_related_field.related_name is None:
|
if super_to_sub_related_field.related_name is None:
|
||||||
#if related name is None the related field is the name of the subclass
|
# if related name is None the related field is the name of the subclass
|
||||||
to_subclass_fieldname = sub_cls.__name__.lower()
|
to_subclass_fieldname = sub_cls.__name__.lower()
|
||||||
else:
|
else:
|
||||||
#otherwise use the given related name
|
# otherwise use the given related name
|
||||||
to_subclass_fieldname = super_to_sub_related_field.related_name
|
to_subclass_fieldname = super_to_sub_related_field.related_name
|
||||||
|
|
||||||
add_model_if_regular(sub_cls, to_subclass_fieldname, result)
|
add_model_if_regular(sub_cls, to_subclass_fieldname, result)
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ def transmogrify(cls, obj):
|
||||||
|
|
||||||
|
|
||||||
###################################################################################
|
###################################################################################
|
||||||
### PolymorphicQuerySet
|
# PolymorphicQuerySet
|
||||||
|
|
||||||
def _query_annotations(query):
|
def _query_annotations(query):
|
||||||
try:
|
try:
|
||||||
|
|
@ -160,7 +160,7 @@ class PolymorphicQuerySet(QuerySet):
|
||||||
# The resulting objects are required to have a unique primary key within the result set
|
# The resulting objects are required to have a unique primary key within the result set
|
||||||
# (otherwise an error is thrown).
|
# (otherwise an error is thrown).
|
||||||
# The "polymorphic" keyword argument is not supported anymore.
|
# The "polymorphic" keyword argument is not supported anymore.
|
||||||
#def extra(self, *args, **kwargs):
|
# def extra(self, *args, **kwargs):
|
||||||
|
|
||||||
def _get_real_instances(self, base_result_objects):
|
def _get_real_instances(self, base_result_objects):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ from functools import reduce
|
||||||
|
|
||||||
|
|
||||||
###################################################################################
|
###################################################################################
|
||||||
### PolymorphicQuerySet support functions
|
# PolymorphicQuerySet support functions
|
||||||
|
|
||||||
# These functions implement the additional filter- and Q-object functionality.
|
# These functions implement the additional filter- and Q-object functionality.
|
||||||
# They form a kind of small framework for easily adding more
|
# They form a kind of small framework for easily adding more
|
||||||
|
|
|
||||||
|
|
@ -368,7 +368,7 @@ class ProxyModelB(ProxyModelBase):
|
||||||
|
|
||||||
|
|
||||||
# test bad field name
|
# test bad field name
|
||||||
#class TestBadFieldModel(ShowFieldType, PolymorphicModel):
|
# class TestBadFieldModel(ShowFieldType, PolymorphicModel):
|
||||||
# instance_of = models.CharField(max_length=10)
|
# instance_of = models.CharField(max_length=10)
|
||||||
|
|
||||||
# validation error: "polymorphic.relatednameclash: Accessor for field 'polymorphic_ctype' clashes
|
# validation error: "polymorphic.relatednameclash: Accessor for field 'polymorphic_ctype' clashes
|
||||||
|
|
@ -377,7 +377,7 @@ class ProxyModelB(ProxyModelBase):
|
||||||
class RelatedNameClash(ShowFieldType, PolymorphicModel):
|
class RelatedNameClash(ShowFieldType, PolymorphicModel):
|
||||||
ctype = models.ForeignKey(ContentType, null=True, editable=False)
|
ctype = models.ForeignKey(ContentType, null=True, editable=False)
|
||||||
|
|
||||||
#class with a parent_link to superclass, and a related_name back to subclass
|
# class with a parent_link to superclass, and a related_name back to subclass
|
||||||
|
|
||||||
|
|
||||||
class TestParentLinkAndRelatedName(ModelShow1_plain):
|
class TestParentLinkAndRelatedName(ModelShow1_plain):
|
||||||
|
|
@ -929,7 +929,7 @@ class PolymorphicTests(TestCase):
|
||||||
self.assertEqual(repr(qs[1]), '<CustomPkInherit: id 2, b (CharField) "b", custom_id (AutoField/pk) 1, i (CharField) "i">')
|
self.assertEqual(repr(qs[1]), '<CustomPkInherit: id 2, b (CharField) "b", custom_id (AutoField/pk) 1, i (CharField) "i">')
|
||||||
|
|
||||||
def test_fix_getattribute(self):
|
def test_fix_getattribute(self):
|
||||||
### fixed issue in PolymorphicModel.__getattribute__: field name same as model name
|
# fixed issue in PolymorphicModel.__getattribute__: field name same as model name
|
||||||
o = ModelFieldNameTest.objects.create(modelfieldnametest='1')
|
o = ModelFieldNameTest.objects.create(modelfieldnametest='1')
|
||||||
self.assertEqual(repr(o), '<ModelFieldNameTest: id 1, modelfieldnametest (CharField)>')
|
self.assertEqual(repr(o), '<ModelFieldNameTest: id 1, modelfieldnametest (CharField)>')
|
||||||
|
|
||||||
|
|
@ -943,17 +943,17 @@ class PolymorphicTests(TestCase):
|
||||||
t.save()
|
t.save()
|
||||||
p = ModelShow1_plain.objects.get(field1="TestParentLinkAndRelatedName")
|
p = ModelShow1_plain.objects.get(field1="TestParentLinkAndRelatedName")
|
||||||
|
|
||||||
#check that p is equal to the
|
# check that p is equal to the
|
||||||
self.assertIsInstance(p, TestParentLinkAndRelatedName)
|
self.assertIsInstance(p, TestParentLinkAndRelatedName)
|
||||||
self.assertEqual(p, t)
|
self.assertEqual(p, t)
|
||||||
|
|
||||||
#check that the accessors to parent and sublass work correctly and return the right object
|
# check that the accessors to parent and sublass work correctly and return the right object
|
||||||
p = ModelShow1_plain.objects.non_polymorphic().get(field1="TestParentLinkAndRelatedName")
|
p = ModelShow1_plain.objects.non_polymorphic().get(field1="TestParentLinkAndRelatedName")
|
||||||
self.assertNotEqual(p, t) # p should be Plain1 and t TestParentLinkAndRelatedName, so not equal
|
self.assertNotEqual(p, t) # p should be Plain1 and t TestParentLinkAndRelatedName, so not equal
|
||||||
self.assertEqual(p, t.superclass)
|
self.assertEqual(p, t.superclass)
|
||||||
self.assertEqual(p.related_name_subclass, t)
|
self.assertEqual(p.related_name_subclass, t)
|
||||||
|
|
||||||
#test that we can delete the object
|
# test that we can delete the object
|
||||||
t.delete()
|
t.delete()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -103,11 +103,11 @@ class UUIDField(six.with_metaclass(models.SubfieldBase, models.CharField)):
|
||||||
# instance), everything works.
|
# instance), everything works.
|
||||||
#
|
#
|
||||||
|
|
||||||
#if not value:
|
# if not value:
|
||||||
# return None
|
# return None
|
||||||
#if isinstance(value, uuid.UUID):
|
# if isinstance(value, uuid.UUID):
|
||||||
# return smart_text(value)
|
# return smart_text(value)
|
||||||
#else:
|
# else:
|
||||||
# return value
|
# return value
|
||||||
|
|
||||||
def pre_save(self, model_instance, add):
|
def pre_save(self, model_instance, add):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue