[Python-modules-commits] [django-polymorphic] 01/02: Import django-polymorphic_1.2.orig.tar.gz
Michael Fladischer
fladi at moszumanska.debian.org
Tue Aug 8 11:01:10 UTC 2017
This is an automated email from the git hooks/post-receive script.
fladi pushed a commit to branch upstream
in repository django-polymorphic.
commit 1de6d9e066551f83c3c3a809148bea47201f448e
Author: Michael Fladischer <FladischerMichael at fladi.at>
Date: Fri May 12 15:38:44 2017 +0200
Import django-polymorphic_1.2.orig.tar.gz
---
.gitignore | 1 +
.travis.yml | 133 ++++++++++++---------
README.rst | 2 +-
docs/_ext/djangodummy/requirements.txt | 3 +-
docs/_ext/djangodummy/settings.py | 4 +
docs/_ext/djangoext/docstrings.py | 6 +-
docs/changelog.rst | 12 +-
docs/conf.py | 4 +-
polymorphic/__init__.py | 2 +-
polymorphic/admin/inlines.py | 1 +
polymorphic/admin/parentadmin.py | 4 +-
polymorphic/query.py | 127 +++++++++++++-------
.../static/polymorphic/css/polymorphic_inlines.css | 1 +
polymorphic/tests/__init__.py | 1 +
polymorphic/tests/test_orm.py | 10 +-
tox.ini | 14 ++-
16 files changed, 209 insertions(+), 116 deletions(-)
diff --git a/.gitignore b/.gitignore
index e63dffc..8699683 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,6 +5,7 @@
*.egg-info/
*.egg/
.coverage
+coverage.xml
.project
.idea/
.pydevproject
diff --git a/.travis.yml b/.travis.yml
index 8f1b076..5601d0a 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -8,75 +8,100 @@ python:
- "3.3"
- "3.4"
- "3.5"
+ - "3.6"
env:
- - DJANGO="Django>=1.4,<1.5"
- - DJANGO="Django>=1.5,<1.6"
- - DJANGO="Django>=1.6,<1.7"
- - DJANGO="Django>=1.7,<1.8"
- - DJANGO="Django>=1.8,<1.9"
- - DJANGO="Django>=1.9,<1.10"
- - DJANGO="Django>=1.10,<1.11"
- - DJANGO="https://github.com/django/django/tarball/master"
+ - TOXENV="django14"
+ - TOXENV="django15"
+ - TOXENV="django16"
+ - TOXENV="django17"
+ - TOXENV="django18"
+ - TOXENV="django19"
+ - TOXENV="django110"
+ - TOXENV="django111"
+ - TOXENV="djangodev"
matrix:
+ fast_finish: true
exclude:
- - python: "3.5"
- env: DJANGO="Django>=1.4,<1.5"
- - python: "3.5"
- env: DJANGO="Django>=1.5,<1.6"
- - python: "3.5"
- env: DJANGO="Django>=1.6,<1.7"
- - python: "3.5"
- env: DJANGO="Django>=1.7,<1.8"
+ - python: "3.6"
+ env: TOXENV="django14"
+ - python: "3.6"
+ env: TOXENV="django15"
+ - python: "3.6"
+ env: TOXENV="django16"
+ - python: "3.6"
+ env: TOXENV="django17"
+ - python: "3.6"
+ env: TOXENV="django18"
+ - python: "3.6"
+ env: TOXENV="django19"
+ - python: "3.6"
+ env: TOXENV="django110"
- - python: "3.4"
- env: DJANGO="Django>=1.4,<1.5"
- - python: "3.4"
- env: DJANGO="Django>=1.9,<1.10"
- - python: "3.4"
- env: DJANGO="Django>=1.10,<1.11"
+ - python: "3.5"
+ env: TOXENV="django14"
+ - python: "3.5"
+ env: TOXENV="django15"
+ - python: "3.5"
+ env: TOXENV="django16"
+ - python: "3.5"
+ env: TOXENV="django17"
- - python: "3.3"
- env: DJANGO="Django>=1.4,<1.5"
- - python: "3.3"
- env: DJANGO="Django>=1.9,<1.10"
- - python: "3.3"
- env: DJANGO="Django>=1.10,<1.11"
- - python: "3.3"
- env: DJANGO="https://github.com/django/django/tarball/master"
+ - python: "3.4"
+ env: TOXENV="django14"
+ - python: "3.4"
+ env: TOXENV="django19"
+ - python: "3.4"
+ env: TOXENV="django110"
+ - python: "3.4"
+ env: TOXENV="django111"
- - python: "3.2"
- env: DJANGO="Django>=1.4,<1.5"
- - python: "3.2"
- env: DJANGO="Django>=1.9,<1.10"
- - python: "3.2"
- env: DJANGO="Django>=1.10,<1.11"
- - python: "3.2"
- env: DJANGO="https://github.com/django/django/tarball/master"
+ - python: "3.3"
+ env: TOXENV="django14"
+ - python: "3.3"
+ env: TOXENV="django19"
+ - python: "3.3"
+ env: TOXENV="django110"
+ - python: "3.3"
+ env: TOXENV="django111"
+ - python: "3.3"
+ env: TOXENV="djangodev"
+
+ - python: "3.2"
+ env: TOXENV="django14"
+ - python: "3.2"
+ env: TOXENV="django19"
+ - python: "3.2"
+ env: TOXENV="django110"
+ - python: "3.2"
+ env: TOXENV="django111"
+ - python: "3.2"
+ env: TOXENV="djangodev"
+
+ - python: "2.6"
+ env: TOXENV="django17"
+ - python: "2.6"
+ env: TOXENV="django18"
+ - python: "2.6"
+ env: TOXENV="django19"
+ - python: "2.6"
+ env: TOXENV="django110"
+ - python: "2.6"
+ env: TOXENV="django111"
+ - python: "2.6"
+ env: TOXENV="djangodev"
- - python: "2.6"
- env: DJANGO="Django>=1.7,<1.8"
- - python: "2.6"
- env: DJANGO="Django>=1.8,<1.9"
- - python: "2.6"
- env: DJANGO="Django>=1.9,<1.10"
- - python: "2.6"
- env: DJANGO="Django>=1.10,<1.11"
- - python: "2.6"
- env: DJANGO="https://github.com/django/django/tarball/master"
allow_failures:
- - env: DJANGO="https://github.com/django/django/tarball/master"
+ - env: TOXENV="djangodev"
before_install:
-- pip install codecov
-
-install:
- - pip install -q $DJANGO coverage==3.6
+- pip install codecov coverage==3.6 tox
script:
- - coverage run --source=polymorphic runtests.py
+ - tox
after_success:
+- coverage xml -i
- codecov
branches:
diff --git a/README.rst b/README.rst
index 4c769cf..f72b011 100644
--- a/README.rst
+++ b/README.rst
@@ -1,4 +1,4 @@
-.. image:: https://travis-ci.org/django-polymorphic/django-polymorphic.png?branch=master
+.. image:: https://travis-ci.org/django-polymorphic/django-polymorphic.svg?branch=master
:target: http://travis-ci.org/django-polymorphic/django-polymorphic
.. image:: https://img.shields.io/pypi/v/django-polymorphic.svg
:target: https://pypi.python.org/pypi/django-polymorphic/
diff --git a/docs/_ext/djangodummy/requirements.txt b/docs/_ext/djangodummy/requirements.txt
index b5041fb..b182c33 100644
--- a/docs/_ext/djangodummy/requirements.txt
+++ b/docs/_ext/djangodummy/requirements.txt
@@ -1,3 +1,4 @@
# for readthedocs
# Remaining requirements are picked up from setup.py
-Django==1.5.10
+Django==1.11
+django-extra-views==0.9.0
diff --git a/docs/_ext/djangodummy/settings.py b/docs/_ext/djangodummy/settings.py
index 414e9fa..849666a 100644
--- a/docs/_ext/djangodummy/settings.py
+++ b/docs/_ext/djangodummy/settings.py
@@ -9,3 +9,7 @@ STATIC_URL = '/static/'
# Avoid error for missing the secret key
SECRET_KEY = 'docs'
+
+INSTALLED_APPS = [
+ 'django.contrib.contenttypes',
+]
diff --git a/docs/_ext/djangoext/docstrings.py b/docs/_ext/djangoext/docstrings.py
index 5ae5bf1..b626b73 100644
--- a/docs/_ext/djangoext/docstrings.py
+++ b/docs/_ext/djangoext/docstrings.py
@@ -4,7 +4,7 @@ Based on http://djangosnippets.org/snippets/2533/
"""
import django
from django.utils.html import strip_tags
-from django.utils.encoding import force_unicode
+from django.utils.encoding import force_text
import inspect
@@ -20,8 +20,8 @@ def improve_model_docstring(app, what, name, obj, options, lines):
model_fields = obj._meta._fields()
for field in model_fields:
- help_text = strip_tags(force_unicode(field.help_text))
- verbose_name = force_unicode(field.verbose_name).capitalize()
+ help_text = strip_tags(force_text(field.help_text))
+ verbose_name = force_text(field.verbose_name).capitalize()
# Add parameter
if help_text:
diff --git a/docs/changelog.rst b/docs/changelog.rst
index 1593c2c..23cd77d 100644
--- a/docs/changelog.rst
+++ b/docs/changelog.rst
@@ -1,7 +1,17 @@
Changelog
=========
-Version 1.1 (2017-01-27)
+Version 1.2 (2017-05-01)
+------------------------
+
+* Django 1.11 support.
+* Fixed ``PolymorphicInlineModelAdmin`` to explictly exclude ``polymorphic_ctype``.
+* Fixed Python 3 TypeError in the admin when preserving the query string.
+* Fixed Python 3 issue due to ``force_unicode()`` usage instead of ``force_text()``.
+* Fixed ``z-index`` attribute for admin menu appearance.
+
+
+Version 1.1 (2017-02-03)
------------------------
* Added class based formset views in ``polymorphic/contrib/extra_views``.
diff --git a/docs/conf.py b/docs/conf.py
index 8ae26d3..5221d1b 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -62,9 +62,9 @@ copyright = u'2013, Bert Constantin, Chris Glass, Diederik van der Boor'
# built documents.
#
# The short X.Y version.
-version = '1.1'
+version = '1.2'
# The full version, including alpha/beta/rc tags.
-release = '1.1'
+release = '1.2'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
diff --git a/polymorphic/__init__.py b/polymorphic/__init__.py
index 1a2fdc0..6e75907 100644
--- a/polymorphic/__init__.py
+++ b/polymorphic/__init__.py
@@ -9,7 +9,7 @@ Please see LICENSE and AUTHORS for more information.
import django
# See PEP 440 (https://www.python.org/dev/peps/pep-0440/)
-__version__ = "1.1"
+__version__ = "1.2"
# Monkey-patch Django < 1.5 to allow ContentTypes for proxy models.
diff --git a/polymorphic/admin/inlines.py b/polymorphic/admin/inlines.py
index 1a1d434..7e163f4 100644
--- a/polymorphic/admin/inlines.py
+++ b/polymorphic/admin/inlines.py
@@ -223,6 +223,7 @@ 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.
if self.exclude is None and hasattr(self.form, '_meta') and self.form._meta.exclude:
# Take the custom ModelForm's Meta.exclude into account only if the
diff --git a/polymorphic/admin/parentadmin.py b/polymorphic/admin/parentadmin.py
index 744ac28..0169225 100644
--- a/polymorphic/admin/parentadmin.py
+++ b/polymorphic/admin/parentadmin.py
@@ -359,7 +359,9 @@ class PolymorphicParentModelAdmin(admin.ModelAdmin):
extra_qs = ''
if request.META['QUERY_STRING']:
- extra_qs = '&' + request.META['QUERY_STRING']
+ # QUERY_STRING is bytes in Python 3, using force_text() to decode it as string.
+ # See QueryDict how Django deals with that.
+ extra_qs = '&{0}'.format(force_text(request.META['QUERY_STRING']))
choices = self.get_child_type_choices(request, 'add')
if len(choices) == 1:
diff --git a/polymorphic/query.py b/polymorphic/query.py
index c842414..8fab5e6 100644
--- a/polymorphic/query.py
+++ b/polymorphic/query.py
@@ -16,7 +16,7 @@ from .query_translate import translate_polymorphic_filter_definitions_in_kwargs,
from .query_translate import translate_polymorphic_field_path, translate_polymorphic_Q_object
# chunk-size: maximum number of objects requested per db-request
-# by the polymorphic queryset.iterator() implementation; we use the same chunk size as Django
+# by the PolymorphicModelIterable; we use the same chunk size as Django
try:
from django.db.models.query import CHUNK_SIZE # this is 100 for Django 1.1/1.2
except ImportError:
@@ -25,6 +25,59 @@ except ImportError:
Polymorphic_QuerySet_objects_per_request = CHUNK_SIZE
+def _polymorhic_iterator(queryset, base_iter):
+ """
+ Here we do the same as::
+
+ real_results = queryset._get_real_instances(list(base_iter))
+ for o in real_results: yield o
+
+ but it requests the objects in chunks from the database,
+ with Polymorphic_QuerySet_objects_per_request per chunk
+ """
+ while True:
+ base_result_objects = []
+ reached_end = False
+
+ # Make sure the base iterator is read in chunks instead of
+ # reading it completely, in case our caller read only a few objects.
+ for i in range(Polymorphic_QuerySet_objects_per_request):
+
+ try:
+ o = next(base_iter)
+ base_result_objects.append(o)
+ except StopIteration:
+ reached_end = True
+ break
+
+ real_results = queryset._get_real_instances(base_result_objects)
+
+ for o in real_results:
+ yield o
+
+ if reached_end:
+ return
+
+
+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):
+ """
+ ModelIterable for PolymorphicModel
+
+ Yields real instances if qs.polymorphic_disabled is False,
+ otherwise acts like a regular ModelIterable.
+ """
+
+ def __iter__(self):
+ base_iter = super(PolymorphicModelIterable, self).__iter__()
+ if self.queryset.polymorphic_disabled:
+ return base_iter
+ return _polymorhic_iterator(self.queryset, base_iter)
+
+
def transmogrify(cls, obj):
"""
Upcast a class to a different type without asking questions.
@@ -63,7 +116,11 @@ class PolymorphicQuerySet(QuerySet):
"""
def __init__(self, *args, **kwargs):
- # init our queryset object member variables
+ 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
+
self.polymorphic_disabled = False
# A parallel structure to django.db.models.query.Query.deferred_loading,
# which we maintain with the untranslated field names passed to
@@ -71,7 +128,6 @@ class PolymorphicQuerySet(QuerySet):
# retrieving the real instance (so that the deferred fields apply
# to that queryset as well).
self.polymorphic_deferred_loading = (set([]), True)
- super(PolymorphicQuerySet, self).__init__(*args, **kwargs)
def _clone(self, *args, **kwargs):
# Django's _clone only copies its own variables, so we need to copy ours here
@@ -407,49 +463,34 @@ class PolymorphicQuerySet(QuerySet):
return resultlist
- def iterator(self):
- """
- This function is used by Django for all object retrieval.
- By overriding it, we modify the objects that this queryset returns
- when it is evaluated (or its get method or other object-returning methods are called).
-
- Here we do the same as::
-
- base_result_objects = list(super(PolymorphicQuerySet, self).iterator())
- real_results = self._get_real_instances(base_result_objects)
- for o in real_results: yield o
-
- but it requests the objects in chunks from the database,
- with Polymorphic_QuerySet_objects_per_request per chunk
- """
- base_iter = super(PolymorphicQuerySet, self).iterator()
-
- # disabled => work just like a normal queryset
- if self.polymorphic_disabled:
- for o in base_iter:
- yield o
- return
-
- while True:
- base_result_objects = []
- reached_end = False
-
- for i in range(Polymorphic_QuerySet_objects_per_request):
- try:
- o = next(base_iter)
- base_result_objects.append(o)
- except StopIteration:
- reached_end = True
- break
-
- real_results = self._get_real_instances(base_result_objects)
+ if django.VERSION < (1, 9):
+ # On django 1.9+, we can define self._iterator_class instead of iterator()
+ def iterator(self):
+ """
+ This function is used by Django 1.8 and earlier for all object retrieval.
+ By overriding it, we modify the objects that this queryset returns
+ when it is evaluated (or its get method or other object-returning methods are called).
+
+ Here we do the same as::
+
+ base_result_objects = list(super(PolymorphicQuerySet, self).iterator())
+ real_results = self._get_real_instances(base_result_objects)
+ for o in real_results: yield o
+
+ but it requests the objects in chunks from the database,
+ with Polymorphic_QuerySet_objects_per_request per chunk
+ """
+ base_iter = super(PolymorphicQuerySet, self).iterator()
+
+ # disabled => work just like a normal queryset
+ if self.polymorphic_disabled:
+ for o in base_iter:
+ yield o
+ return
- for o in real_results:
+ for o in _polymorhic_iterator(self, base_iter):
yield o
- if reached_end:
- return
-
def __repr__(self, *args, **kwargs):
if self.model.polymorphic_query_multiline_output:
result = [repr(o) for o in self.all()]
diff --git a/polymorphic/static/polymorphic/css/polymorphic_inlines.css b/polymorphic/static/polymorphic/css/polymorphic_inlines.css
index a4ad938..0da9ae0 100644
--- a/polymorphic/static/polymorphic/css/polymorphic_inlines.css
+++ b/polymorphic/static/polymorphic/css/polymorphic_inlines.css
@@ -15,6 +15,7 @@
border-radius: 4px;
padding: 2px;
background-color: #fff;
+ z-index: 1000;
}
.polymorphic-type-menu ul {
diff --git a/polymorphic/tests/__init__.py b/polymorphic/tests/__init__.py
index 892e570..bfee088 100644
--- a/polymorphic/tests/__init__.py
+++ b/polymorphic/tests/__init__.py
@@ -204,6 +204,7 @@ 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
objects = PolymorphicManager()
diff --git a/polymorphic/tests/test_orm.py b/polymorphic/tests/test_orm.py
index 9498312..65601a5 100644
--- a/polymorphic/tests/test_orm.py
+++ b/polymorphic/tests/test_orm.py
@@ -360,7 +360,7 @@ class PolymorphicTests(TestCase):
# no pretty printing
ModelShow1_plain.objects.create(field1='abc')
ModelShow2_plain.objects.create(field1='abc', field2='def')
- self.assertEqual(qrepr(ModelShow1_plain.objects.all()), '<QuerySet [<ModelShow1_plain: ModelShow1_plain object>, <ModelShow2_plain: ModelShow2_plain object>]>')
+ self.assertEqual(qrepr(ModelShow1_plain.objects.all()), '<PolymorphicQuerySet [<ModelShow1_plain: ModelShow1_plain object>, <ModelShow2_plain: ModelShow2_plain object>]>')
def test_extra_method(self):
self.create_model2abcd()
@@ -809,9 +809,13 @@ def qrepr(data):
Ensure consistent repr() output for the QuerySet object.
"""
if isinstance(data, QuerySet):
- if django.VERSION >= (1, 10):
+ if django.VERSION >= (1, 11):
return repr(data)
+ elif django.VERSION >= (1, 10):
+ # Django 1.11 still shows "<QuerySet [", not taking the actual type into account.
+ return '<{} {}'.format(data.__class__.__name__, repr(data)[10:])
else:
- return '<QuerySet %r>' % data
+ # Simulate Django 1.11 behavior for older Django versions.
+ return '<{} {}>'.format(data.__class__.__name__, repr(data))
return repr(data)
diff --git a/tox.ini b/tox.ini
index 6a3af4e..cff1ea7 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,16 +1,17 @@
[tox]
envlist=
py26-django{14,15,16},
- py27-django{14,15,16,17,18,19,110},
+ py27-django{14,15,16,17,18,19,110,111},
py32-django{15,16,17,18},
py33-django{15,16,17,18},
- py34-django{15,16,17,18,19,110},
- py35-django{18,19,110}
- # py33-django-dev,
+ py34-django{15,16,17,18,19,110,111},
+ py35-django{18,19,110,111,dev},
+ py36-django{111,dev},
docs,
[testenv]
deps =
+ coverage == 3.6
django14: Django >= 1.4, < 1.5
django15: Django >= 1.5, < 1.6
django16: Django >= 1.6, < 1.7
@@ -18,9 +19,10 @@ deps =
django18: Django >= 1.8, < 1.9
django19: Django >= 1.9, < 1.10
django110: Django >= 1.10, < 1.11
- django-dev: https://github.com/django/django/tarball/master
+ django111: Django >= 1.11, < 1.12
+ djangodev: https://github.com/django/django/tarball/master
commands=
- python runtests.py
+ coverage run --source polymorphic runtests.py
[testenv:docs]
deps=Sphinx
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/django-polymorphic.git
More information about the Python-modules-commits
mailing list