Merge pull request #276 from meshy/django-1.11-iterator
WIP: Get tests running on django 1.11fix_request_path_info
commit
4134c152a5
|
|
@ -90,7 +90,6 @@ matrix:
|
||||||
- python: "2.6"
|
- python: "2.6"
|
||||||
env: DJANGO="https://github.com/django/django/tarball/master"
|
env: DJANGO="https://github.com/django/django/tarball/master"
|
||||||
allow_failures:
|
allow_failures:
|
||||||
- env: DJANGO="Django>=1.11,<1.12"
|
|
||||||
- env: DJANGO="https://github.com/django/django/tarball/master"
|
- env: DJANGO="https://github.com/django/django/tarball/master"
|
||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,25 @@ except ImportError:
|
||||||
Polymorphic_QuerySet_objects_per_request = CHUNK_SIZE
|
Polymorphic_QuerySet_objects_per_request = CHUNK_SIZE
|
||||||
|
|
||||||
|
|
||||||
|
if django.VERSION >= (1, 9):
|
||||||
|
# We ignore this on django < 1.9, as ModelIterable didn't yet exist.
|
||||||
|
from django.db.models.query import ModelIterable
|
||||||
|
|
||||||
|
|
||||||
|
class PolymorphicModelIterable(ModelIterable):
|
||||||
|
def __iter__(self):
|
||||||
|
base_iter = super(PolymorphicModelIterable, self).__iter__()
|
||||||
|
|
||||||
|
if self.queryset.polymorphic_disabled:
|
||||||
|
for o in base_iter:
|
||||||
|
yield o
|
||||||
|
return
|
||||||
|
|
||||||
|
real_instances = self.queryset._get_real_instances(base_iter)
|
||||||
|
for obj in real_instances:
|
||||||
|
yield obj
|
||||||
|
|
||||||
|
|
||||||
def transmogrify(cls, obj):
|
def transmogrify(cls, obj):
|
||||||
"""
|
"""
|
||||||
Upcast a class to a different type without asking questions.
|
Upcast a class to a different type without asking questions.
|
||||||
|
|
@ -72,6 +91,9 @@ class PolymorphicQuerySet(QuerySet):
|
||||||
# to that queryset as well).
|
# to that queryset as well).
|
||||||
self.polymorphic_deferred_loading = (set([]), True)
|
self.polymorphic_deferred_loading = (set([]), True)
|
||||||
super(PolymorphicQuerySet, self).__init__(*args, **kwargs)
|
super(PolymorphicQuerySet, self).__init__(*args, **kwargs)
|
||||||
|
if django.VERSION >= (1, 9):
|
||||||
|
# On django < 1.9 we override the iterator() method instead
|
||||||
|
self._iterable_class = PolymorphicModelIterable
|
||||||
|
|
||||||
def _clone(self, *args, **kwargs):
|
def _clone(self, *args, **kwargs):
|
||||||
# Django's _clone only copies its own variables, so we need to copy ours here
|
# Django's _clone only copies its own variables, so we need to copy ours here
|
||||||
|
|
@ -407,6 +429,8 @@ class PolymorphicQuerySet(QuerySet):
|
||||||
|
|
||||||
return resultlist
|
return resultlist
|
||||||
|
|
||||||
|
if django.VERSION < (1, 9):
|
||||||
|
# On django 1.9+, we can define self._iterator_class instead of iterator()
|
||||||
def iterator(self):
|
def iterator(self):
|
||||||
"""
|
"""
|
||||||
This function is used by Django for all object retrieval.
|
This function is used by Django for all object retrieval.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue