Added Python 3 compatibility to sample project.
Removed utils file and moved map_path function to settings.py. Refactored tests for Python 2 and 3 compatibility. Added inheritance check to get proper determination if a SortableForeignKey field is defined but the specified model does not inherit from Sortable.
This commit is contained in:
+14
-8
@@ -1,9 +1,13 @@
|
||||
from .models import Sortable, SortableForeignKey
|
||||
|
||||
|
||||
def check_inheritance(obj):
|
||||
return issubclass(type(obj), Sortable)
|
||||
|
||||
|
||||
def get_is_sortable(objects):
|
||||
if objects:
|
||||
if issubclass(type(objects[0]), Sortable):
|
||||
if check_inheritance(objects[0]):
|
||||
if objects.count() > 1:
|
||||
return True
|
||||
return False
|
||||
@@ -11,7 +15,8 @@ def get_is_sortable(objects):
|
||||
|
||||
def is_self_referential(cls):
|
||||
cls_type = type(cls)
|
||||
sortable_subclass = issubclass(cls_type, Sortable)
|
||||
sortable_subclass = check_inheritance(cls_type)
|
||||
# sortable_subclass = issubclass(cls_type, Sortable)
|
||||
sortable_foreign_key_subclass = issubclass(cls_type, SortableForeignKey)
|
||||
if sortable_foreign_key_subclass and not sortable_subclass:
|
||||
return True
|
||||
@@ -20,11 +25,12 @@ def is_self_referential(cls):
|
||||
|
||||
def check_model_is_sortable(cls):
|
||||
if cls:
|
||||
if is_self_referential(cls):
|
||||
objects = cls.model.objects
|
||||
else:
|
||||
objects = cls.objects
|
||||
if check_inheritance(cls):
|
||||
if is_self_referential(cls):
|
||||
objects = cls.model.objects
|
||||
else:
|
||||
objects = cls.objects
|
||||
|
||||
if objects.count() > 1:
|
||||
return True
|
||||
if objects.count() > 1:
|
||||
return True
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user