[Python-modules-commits] [django-polymorphic] 02/02: New upstream version 1.3

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 72b565ea66e06fdff5be6b4ab8d34cd650a727cd
Author: Michael Fladischer <FladischerMichael at fladi.at>
Date:   Tue Aug 8 10:49:09 2017 +0200

    New upstream version 1.3
---
 .travis.yml                                   |  65 +-----------
 AUTHORS.rst                                   |   1 +
 README.rst                                    |  14 +--
 docs/_ext/djangoext/docstrings.py             |  14 +--
 docs/changelog.rst                            |  10 ++
 docs/conf.py                                  |   7 +-
 docs/managers.rst                             |   4 -
 docs/migrating.rst                            |   1 +
 docs/quickstart.rst                           |   3 +-
 example/example/settings.py                   |   5 +-
 example/pexp/management/commands/p2cmd.py     |  47 ++++-----
 example/pexp/management/commands/polybench.py |  29 +++---
 example/pexp/models.py                        |   9 +-
 polymorphic/__init__.py                       |  32 +-----
 polymorphic/admin/generic.py                  |   6 +-
 polymorphic/admin/inlines.py                  |   6 +-
 polymorphic/admin/parentadmin.py              |  56 +++-------
 polymorphic/base.py                           |  15 ++-
 polymorphic/formsets/generic.py               |   6 +-
 polymorphic/formsets/models.py                |   6 +-
 polymorphic/locale/en/LC_MESSAGES/django.po   |   8 +-
 polymorphic/locale/fr/LC_MESSAGES/django.po   |   8 +-
 polymorphic/managers.py                       |  29 ++----
 polymorphic/models.py                         |  18 ++--
 polymorphic/query.py                          | 138 +++++++++++-------------
 polymorphic/query_translate.py                |  41 +++-----
 polymorphic/showfields.py                     |  12 +--
 polymorphic/tests/__init__.py                 |  47 ++++-----
 polymorphic/tests/test_multidb.py             |  12 +--
 polymorphic/tests/test_orm.py                 |  28 +----
 polymorphic/tools_for_tests.py                | 144 --------------------------
 runtests.py                                   |  73 +++++--------
 setup.py                                      |  17 ++-
 tox.ini                                       |  30 +++---
 34 files changed, 269 insertions(+), 672 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 5601d0a..a6f737b 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -2,20 +2,12 @@ sudo: false
 language: python
 cache: pip
 python:
-  - "2.6"
   - "2.7"
-  - "3.2"
-  - "3.3"
   - "3.4"
   - "3.5"
   - "3.6"
 env:
-  - TOXENV="django14"
-  - TOXENV="django15"
-  - TOXENV="django16"
-  - TOXENV="django17"
   - TOXENV="django18"
-  - TOXENV="django19"
   - TOXENV="django110"
   - TOXENV="django111"
   - TOXENV="djangodev"
@@ -24,71 +16,16 @@ matrix:
   fast_finish: true
   exclude:
     - 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.5"
-      env: TOXENV="django14"
-    - python: "3.5"
-      env: TOXENV="django15"
-    - python: "3.5"
-      env: TOXENV="django16"
-    - python: "3.5"
-      env: TOXENV="django17"
-
-    - 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.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"
+    - python: "2.7"
       env: TOXENV="djangodev"
 
   allow_failures:
diff --git a/AUTHORS.rst b/AUTHORS.rst
index 5e562ce..ee00aa9 100644
--- a/AUTHORS.rst
+++ b/AUTHORS.rst
@@ -22,6 +22,7 @@ Contributors
 * Hugo Osvaldo Barrera
 * Jacob Rief
 * Jedediah Smith (proxy models support)
+* Jerome Leclanche
 * John Furr
 * Jonas Obrist
 * Julian Wachholz
diff --git a/README.rst b/README.rst
index f72b011..5b67d04 100644
--- a/README.rst
+++ b/README.rst
@@ -46,12 +46,11 @@ Features
 * Full admin integration.
 * ORM integration:
 
- * support for ForeignKey, ManyToManyField, OneToOneField descriptors.
- * Filtering/ordering of inherited models (``ArtProject___artist``).
- * Filtering model types: ``instance_of(...)`` and ``not_instance_of(...)``
- * Combining querysets of different models (``qs3 = qs1 | qs2``)
- * Support for custom user-defined managers.
-
+  * support for ForeignKey, ManyToManyField, OneToOneField descriptors.
+  * Filtering/ordering of inherited models (``ArtProject___artist``).
+  * Filtering model types: ``instance_of(...)`` and ``not_instance_of(...)``
+  * Combining querysets of different models (``qs3 = qs1 | qs2``)
+  * Support for custom user-defined managers.
 * Uses the minumum amount of queries needed to fetch the inherited models.
 * Disabling polymorphic behavior when needed.
 
@@ -61,6 +60,9 @@ Django to perform an ``INNER JOIN`` to fetch the model fields from the database.
 While taking this in mind, there are valid reasons for using subclassed models.
 That's what this library is designed for!
 
+The current release of *django-polymorphic* supports Django 1.8, 1.10, 1.11 and Python 2.7 and 3.4+ is supported.
+For older Django versions, install *django-polymorphic==1.2*.
+
 For more information, see the `documentation at Read the Docs <https://django-polymorphic.readthedocs.io/>`_.
 
 Installation
diff --git a/docs/_ext/djangoext/docstrings.py b/docs/_ext/djangoext/docstrings.py
index b626b73..d52abbb 100644
--- a/docs/_ext/djangoext/docstrings.py
+++ b/docs/_ext/djangoext/docstrings.py
@@ -2,22 +2,16 @@
 Automatically mention all model fields as parameters in the model construction.
 Based on http://djangosnippets.org/snippets/2533/
 """
-import django
-from django.utils.html import strip_tags
-from django.utils.encoding import force_text
 import inspect
+from django.utils.encoding import force_text
+from django.utils.html import strip_tags
 
 
 def improve_model_docstring(app, what, name, obj, options, lines):
     from django.db import models  # must be inside the function, to allow settings initialization first.
 
     if inspect.isclass(obj) and issubclass(obj, models.Model):
-        if django.VERSION >= (1,8):
-            model_fields = obj._meta.get_fields()
-        elif django.VERSION >= (1,6):
-            model_fields = obj._meta.fields
-        else:
-            model_fields = obj._meta._fields()
+        model_fields = obj._meta.get_fields()
 
         for field in model_fields:
             help_text = strip_tags(force_text(field.help_text))
@@ -39,9 +33,9 @@ def improve_model_docstring(app, what, name, obj, options, lines):
     # Return the extended docstring
     return lines
 
+
 # Allow this module to be used as sphinx extension:
 def setup(app):
     # Generate docstrings for Django model fields
     # Register the docstring processor with sphinx
     app.connect('autodoc-process-docstring', improve_model_docstring)
-
diff --git a/docs/changelog.rst b/docs/changelog.rst
index 23cd77d..0236d66 100644
--- a/docs/changelog.rst
+++ b/docs/changelog.rst
@@ -1,6 +1,16 @@
 Changelog
 =========
 
+Version 1.3 (2017-08-01)
+------------------------
+
+* **BACKWARDS INCOMPATIBILITY:** Dropped Django 1.4, 1.5, 1.6, 1.7, 1.9 and Python 2.6 support.
+  Only official Django releases (1.8, 1.10, 1.11) are supported now.
+* Allow expressions to pass unchanged in ``.order_by()``
+* Fixed Django 1.11 accessor checks (to support subclasses of ``ForwardManyToOneDescriptor``, like ``ForwardOneToOneDescriptor``)
+* Fixed polib syntax error messages in translations.
+
+
 Version 1.2 (2017-05-01)
 ------------------------
 
diff --git a/docs/conf.py b/docs/conf.py
index 5221d1b..b9b053f 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -23,8 +23,7 @@ sys.path.insert(0, os.path.abspath('_ext'))
 sys.path.insert(0, os.path.abspath('..'))
 os.environ['DJANGO_SETTINGS_MODULE'] = 'djangodummy.settings'
 
-if django.VERSION >= (1, 8):
-    django.setup()
+django.setup()
 
 # -- General configuration -----------------------------------------------------
 
@@ -62,9 +61,9 @@ copyright = u'2013, Bert Constantin, Chris Glass, Diederik van der Boor'
 # built documents.
 #
 # The short X.Y version.
-version = '1.2'
+version = '1.3'
 # The full version, including alpha/beta/rc tags.
-release = '1.2'
+release = '1.3'
 
 # The language for content autogenerated by Sphinx. Refer to documentation
 # for a list of supported languages.
diff --git a/docs/managers.rst b/docs/managers.rst
index 9ed04f7..8790593 100644
--- a/docs/managers.rst
+++ b/docs/managers.rst
@@ -32,8 +32,6 @@ Django as automatic manager for several purposes, including accessing
 related objects. It must not filter objects and it's safest to use
 the plain ``PolymorphicManager`` here.
 
-    Note that get_query_set is deprecated in Django 1.8 and creates warnings in Django 1.7.
-
 Manager Inheritance
 -------------------
 
@@ -69,8 +67,6 @@ regarding their start time and ``ArtProject.objects_ordered.most_recent()``
 will return the ten most recent art projects.
 .
 
-    Note that get_query_set is deprecated in Django 1.8 and creates warnings in Django 1.7.
-
 Using a Custom Queryset Class
 -----------------------------
 
diff --git a/docs/migrating.rst b/docs/migrating.rst
index b6f7d5c..866da3b 100644
--- a/docs/migrating.rst
+++ b/docs/migrating.rst
@@ -61,6 +61,7 @@ It's recommended to let ``makemigrations`` create the migration file,
 and include the ``RunPython`` manually before running the migration.
 
 .. versionadded:: 1.1
+
 When the model is created elsewhere, you can also use
 the :func:`polymorphic.utils.reset_polymorphic_ctype` function:
 
diff --git a/docs/quickstart.rst b/docs/quickstart.rst
index 254918a..3df803f 100644
--- a/docs/quickstart.rst
+++ b/docs/quickstart.rst
@@ -12,7 +12,8 @@ Update the settings file::
         'django.contrib.contenttypes',
     )
 
-The current release of *django-polymorphic* supports Django 1.4 till 1.10 and Python 3 is supported.
+The current release of *django-polymorphic* supports Django 1.8, 1.10, 1.11 and Python 2.7 and 3.4+ is supported.
+For older Django versions, use *django-polymorphic==1.2*.
 
 Making Your Models Polymorphic
 ------------------------------
diff --git a/example/example/settings.py b/example/example/settings.py
index 8679620..abb389b 100644
--- a/example/example/settings.py
+++ b/example/example/settings.py
@@ -1,4 +1,3 @@
-import django
 import os
 
 DEBUG = True
@@ -67,7 +66,6 @@ INSTALLED_APPS = (
     'django.contrib.admin',
     'django.contrib.contenttypes',
     'django.contrib.sessions',
-    #'django.contrib.sites',
     'django.contrib.messages',
     'django.contrib.staticfiles',
 
@@ -76,8 +74,7 @@ INSTALLED_APPS = (
     'orders',
 )
 
-if django.VERSION >= (1, 7):
-    TEST_RUNNER = 'django.test.runner.DiscoverRunner'  # silence system checks
+TEST_RUNNER = 'django.test.runner.DiscoverRunner'  # silence system checks
 
 # Logging configuration
 LOGGING = {
diff --git a/example/pexp/management/commands/p2cmd.py b/example/pexp/management/commands/p2cmd.py
index abb7608..0f8e0dc 100644
--- a/example/pexp/management/commands/p2cmd.py
+++ b/example/pexp/management/commands/p2cmd.py
@@ -3,34 +3,32 @@
 This module is a scratchpad for general development, testing & debugging
 Well, even more so than pcmd.py. You best ignore p2cmd.py.
 """
-from django.core.management.base import NoArgsCommand
-from pprint import pprint
-import time
 import sys
+import time
+from pprint import pprint
+from random import Random
+from django.core.management.base import NoArgsCommand
+from django.db import connection
 
 from pexp.models import *
 
 
-def reset_queries():
-    if django.VERSION < (1, 8):
-        connection.queries = []
-    else:
-        connection.queries_log.clear()
+rnd = Random()
 
 
 def show_queries():
-    print
-    print 'QUERIES:', len(connection.queries)
+    print()
+    print("QUERIES:", len(connection.queries))
     pprint(connection.queries)
-    print
+    print()
     connection.queries = []
 
 
 def print_timing(func, message='', iterations=1):
     def wrapper(*arg):
         results = []
-        reset_queries()
-        for i in xrange(iterations):
+        connection.queries_log.clear()
+        for i in range(iterations):
             t1 = time.time()
             x = func(*arg)
             t2 = time.time()
@@ -38,13 +36,12 @@ def print_timing(func, message='', iterations=1):
         res_sum = 0
         for r in results:
             res_sum += r
-        median = res_sum / len(results)
-        print '%s%-19s: %.4f ms, %i queries (%i times)' % (
+        print("%s%-19s: %.4f ms, %i queries (%i times)" % (
             message, func.func_name,
             res_sum,
             len(connection.queries),
             iterations
-        )
+        ))
         sys.stdout.flush()
     return wrapper
 
@@ -58,18 +55,18 @@ class Command(NoArgsCommand):
             a = TestModelA.objects.create(field1='A1')
             b = TestModelB.objects.create(field1='B1', field2='B2')
             c = TestModelC.objects.create(field1='C1', field2='C2', field3='C3')
-            reset_queries()
-            print TestModelC.base_objects.all()
+            connection.queries_log.clear()
+            print(TestModelC.base_objects.all())
             show_queries()
 
         if False:
             TestModelA.objects.all().delete()
-            for i in xrange(1000):
+            for i in range(1000):
                 a = TestModelA.objects.create(field1=str(i % 100))
                 b = TestModelB.objects.create(field1=str(i % 100), field2=str(i % 200))
                 c = TestModelC.objects.create(field1=str(i % 100), field2=str(i % 200), field3=str(i % 300))
                 if i % 100 == 0:
-                    print i
+                    print(i)
 
         f = print_timing(poly_sql_query, iterations=1000)
         f()
@@ -85,11 +82,7 @@ class Command(NoArgsCommand):
         c = NormalModelC.objects.create(field1='C1', field2='C2', field3='C3')
         qs = TestModelA.objects.raw("SELECT * from pexp_testmodela")
         for o in list(qs):
-            print o
-
-from django.db import connection, transaction
-from random import Random
-rnd = Random()
+            print(o)
 
 
 def poly_sql_query():
@@ -103,7 +96,7 @@ def poly_sql_query():
         ON pexp_testmodelb.testmodela_ptr_id = pexp_testmodelc.testmodelb_ptr_id
         WHERE pexp_testmodela.field1=%i
         ORDER BY pexp_testmodela.id
-        """ % rnd.randint(0, 100) )
+        """ % rnd.randint(0, 100))
     # row=cursor.fetchone()
     return
 
@@ -115,6 +108,6 @@ def poly_sql_query2():
         FROM pexp_testmodela
         WHERE pexp_testmodela.field1=%i
         ORDER BY pexp_testmodela.id
-        """ % rnd.randint(0, 100) )
+        """ % rnd.randint(0, 100))
     # row=cursor.fetchone()
     return
diff --git a/example/pexp/management/commands/polybench.py b/example/pexp/management/commands/polybench.py
index 8ca5913..c0b7efb 100644
--- a/example/pexp/management/commands/polybench.py
+++ b/example/pexp/management/commands/polybench.py
@@ -3,30 +3,25 @@
 This module is a scratchpad for general development, testing & debugging
 """
 
+import time
+import sys
+
 from django.core.management.base import NoArgsCommand
 from django.db import connection
 from pprint import pprint
-import sys
 from pexp.models import *
 
-num_objects = 1000
-
 
-def reset_queries():
-    if django.VERSION < (1, 8):
-        connection.queries = []
-    else:
-        connection.queries_log.clear()
+num_objects = 1000
 
 
 def show_queries():
-    print
-    print 'QUERIES:', len(connection.queries)
+    print()
+    print("QUERIES:", len(connection.queries))
     pprint(connection.queries)
-    print
-    reset_queries()
+    print()
+    connection.queries_log.clear()
 
-import time
 
 ###################################################################################
 # benchmark wrappers
@@ -35,8 +30,8 @@ import time
 def print_timing(func, message='', iterations=1):
     def wrapper(*arg):
         results = []
-        reset_queries()
-        for i in xrange(iterations):
+        connection.queries_log.clear()
+        for i in range(iterations):
             t1 = time.time()
             x = func(*arg)
             t2 = time.time()
@@ -45,11 +40,11 @@ def print_timing(func, message='', iterations=1):
         for r in results:
             res_sum += r
         median = res_sum / len(results)
-        print '%s%-19s: %.0f ms, %i queries' % (
+        print("%s%-19s: %.0f ms, %i queries" % (
             message, func.func_name,
             median,
             len(connection.queries) / len(results)
-        )
+        ))
         sys.stdout.flush()
     return wrapper
 
diff --git a/example/pexp/models.py b/example/pexp/models.py
index f49e9a1..26b4768 100644
--- a/example/pexp/models.py
+++ b/example/pexp/models.py
@@ -1,6 +1,5 @@
 # -*- coding: utf-8 -*-
 
-import django
 from django.db import models
 
 from polymorphic.models import PolymorphicModel
@@ -20,15 +19,9 @@ class ResearchProject(Project):
     supervisor = models.CharField(max_length=30)
 
 
-if django.VERSION < (1, 8):
-    from polymorphic.tools_for_tests import UUIDField
-else:
-    from django.db.models import UUIDField
-
-
 class UUIDModelA(ShowFieldTypeAndContent, PolymorphicModel):
     """UUID as primary key example"""
-    uuid_primary_key = UUIDField(primary_key=True)
+    uuid_primary_key = models.UUIDField(primary_key=True)
     field1 = models.CharField(max_length=10)
 
 
diff --git a/polymorphic/__init__.py b/polymorphic/__init__.py
index 6e75907..77d7fe2 100644
--- a/polymorphic/__init__.py
+++ b/polymorphic/__init__.py
@@ -6,36 +6,6 @@ Copyright:
 This code and affiliated files are (C) by Bert Constantin and individual contributors.
 Please see LICENSE and AUTHORS for more information.
 """
-import django
 
 # See PEP 440 (https://www.python.org/dev/peps/pep-0440/)
-__version__ = "1.2"
-
-
-# Monkey-patch Django < 1.5 to allow ContentTypes for proxy models.
-if django.VERSION[:2] < (1, 5):
-    from django.contrib.contenttypes.models import ContentTypeManager
-    from django.utils.encoding import smart_text
-
-    def get_for_model(self, model, for_concrete_model=True):
-        if for_concrete_model:
-            model = model._meta.concrete_model
-        elif model._deferred:
-            model = model._meta.proxy_for_model
-
-        opts = model._meta
-
-        try:
-            ct = self._get_from_cache(opts)
-        except KeyError:
-            ct, created = self.get_or_create(
-                app_label=opts.app_label,
-                model=opts.object_name.lower(),
-                defaults={'name': smart_text(opts.verbose_name_raw)},
-            )
-            self._add_to_cache(self.db, ct)
-
-        return ct
-
-    ContentTypeManager.get_for_model__original = ContentTypeManager.get_for_model
-    ContentTypeManager.get_for_model = get_for_model
+__version__ = "1.3"
diff --git a/polymorphic/admin/generic.py b/polymorphic/admin/generic.py
index 4a121af..bd3453f 100644
--- a/polymorphic/admin/generic.py
+++ b/polymorphic/admin/generic.py
@@ -1,14 +1,10 @@
+from django.contrib.contenttypes.admin import GenericInlineModelAdmin
 from django.contrib.contenttypes.models import ContentType
 from django.utils.functional import cached_property
 
 from polymorphic.formsets import polymorphic_child_forms_factory, BaseGenericPolymorphicInlineFormSet, GenericPolymorphicFormSetChild
 from .inlines import PolymorphicInlineModelAdmin
 
-try:
-    from django.contrib.contenttypes.admin import GenericInlineModelAdmin  # Django 1.7+
-except ImportError:
-    from django.contrib.contenttypes.generic import GenericInlineModelAdmin
-
 
 class GenericPolymorphicInlineModelAdmin(PolymorphicInlineModelAdmin, GenericInlineModelAdmin):
     """
diff --git a/polymorphic/admin/inlines.py b/polymorphic/admin/inlines.py
index 7e163f4..deee7bb 100644
--- a/polymorphic/admin/inlines.py
+++ b/polymorphic/admin/inlines.py
@@ -6,6 +6,7 @@ Each row in the inline can correspond with a different subclass.
 from functools import partial
 
 from django.contrib.admin.options import InlineModelAdmin
+from django.contrib.admin.utils import flatten_fieldsets
 from django.core.exceptions import ImproperlyConfigured
 from django.forms import Media
 
@@ -13,11 +14,6 @@ from polymorphic.formsets import polymorphic_child_forms_factory, BasePolymorphi
 from polymorphic.formsets.utils import add_media
 from .helpers import PolymorphicInlineSupportMixin
 
-try:
-    from django.contrib.admin.utils import flatten_fieldsets  # Django 1.7+
-except ImportError:
-    from django.contrib.admin.util import flatten_fieldsets
-
 
 class PolymorphicInlineModelAdmin(InlineModelAdmin):
     """
diff --git a/polymorphic/admin/parentadmin.py b/polymorphic/admin/parentadmin.py
index 0169225..da7dffc 100644
--- a/polymorphic/admin/parentadmin.py
+++ b/polymorphic/admin/parentadmin.py
@@ -8,12 +8,12 @@ import django
 from django.conf.urls import url
 from django.contrib import admin
 from django.contrib.admin.helpers import AdminErrorList, AdminForm
+from django.contrib.admin.templatetags.admin_urls import add_preserved_filters
 from django.contrib.contenttypes.models import ContentType
 from django.core.exceptions import PermissionDenied
 from django.core.urlresolvers import RegexURLResolver
 from django.http import Http404, HttpResponseRedirect
-from django.shortcuts import render_to_response
-from django.template.context import RequestContext
+from django.template.response import TemplateResponse
 from django.utils.encoding import force_text
 from django.utils.http import urlencode
 from django.utils.safestring import mark_safe
@@ -21,12 +21,6 @@ from django.utils.translation import ugettext_lazy as _
 
 from .forms import PolymorphicModelChoiceForm
 
-try:
-    # Django 1.6 implements this
-    from django.contrib.admin.templatetags.admin_urls import add_preserved_filters
-except ImportError:
-    def add_preserved_filters(context, form_url):
-        return form_url
 
 if sys.version_info[0] >= 3:
     long = int
@@ -72,7 +66,7 @@ class PolymorphicParentModelAdmin(admin.ModelAdmin):
     #: The regular expression to filter the primary key in the URL.
     #: This accepts only numbers as defensive measure against catch-all URLs.
     #: If your primary key consists of string values, update this regular expression.
-    pk_regex = '(\d+|__fk__)'
+    pk_regex = r"(\d+|__fk__)"
 
     def __init__(self, model, admin_site, *args, **kwargs):
         super(PolymorphicParentModelAdmin, self).__init__(model, admin_site, *args, **kwargs)
@@ -210,13 +204,6 @@ class PolymorphicParentModelAdmin(admin.ModelAdmin):
             qs = qs.non_polymorphic()
         return qs
 
-    # For Django 1.5:
-    def queryset(self, request):
-        qs = super(PolymorphicParentModelAdmin, self).queryset(request)
-        if not self.polymorphic_list:
-            qs = qs.non_polymorphic()
-        return qs
-
     def add_view(self, request, form_url='', extra_context=None):
         """Redirect the add view to the real admin."""
         ct_id = int(request.GET.get('ct_id', 0))
@@ -238,17 +225,16 @@ class PolymorphicParentModelAdmin(admin.ModelAdmin):
         real_admin = self._get_real_admin(object_id)
         return real_admin.change_view(request, object_id, *args, **kwargs)
 
-    if django.VERSION >= (1, 7):
-        def changeform_view(self, request, object_id=None, *args, **kwargs):
-            # The `changeform_view` is available as of Django 1.7, combining the add_view and change_view.
-            # As it's directly called by django-reversion, this method is also overwritten to make sure it
-            # also redirects to the child admin.
-            if object_id:
-                real_admin = self._get_real_admin(object_id)
-                return real_admin.changeform_view(request, object_id, *args, **kwargs)
-            else:
-                # Add view. As it should already be handled via `add_view`, this means something custom is done here!
-                return super(PolymorphicParentModelAdmin, self).changeform_view(request, object_id, *args, **kwargs)
+    def changeform_view(self, request, object_id=None, *args, **kwargs):
+        # The `changeform_view` is available as of Django 1.7, combining the add_view and change_view.
+        # As it's directly called by django-reversion, this method is also overwritten to make sure it
+        # also redirects to the child admin.
+        if object_id:
+            real_admin = self._get_real_admin(object_id)
+            return real_admin.changeform_view(request, object_id, *args, **kwargs)
+        else:
+            # Add view. As it should already be handled via `add_view`, this means something custom is done here!
+            return super(PolymorphicParentModelAdmin, self).changeform_view(request, object_id, *args, **kwargs)
 
     def history_view(self, request, object_id, extra_context=None):
         """Redirect the history view to the real admin."""
@@ -407,8 +393,6 @@ class PolymorphicParentModelAdmin(admin.ModelAdmin):
             'add': True,
             'save_on_top': self.save_on_top,
         })
-        if hasattr(self.admin_site, 'root_path'):
-            context['root_path'] = self.admin_site.root_path  # Django < 1.4
 
         templates = self.add_type_template or [
             "admin/%s/%s/add_type_form.html" % (app_label, opts.object_name.lower()),
@@ -417,13 +401,8 @@ class PolymorphicParentModelAdmin(admin.ModelAdmin):
             "admin/add_type_form.html"
         ]
 
-        if django.VERSION >= (1, 8):
-            from django.template.response import TemplateResponse
-            request.current_app = self.admin_site.name
-            return TemplateResponse(request, templates, context)
-        else:
-            context_instance = RequestContext(request, current_app=self.admin_site.name)
-            return render_to_response(templates, context, context_instance=context_instance)
+        request.current_app = self.admin_site.name
+        return TemplateResponse(request, templates, context)
 
     @property
     def change_list_template(self):
@@ -445,7 +424,4 @@ class PolymorphicParentModelAdmin(admin.ModelAdmin):
 
 
 def _get_opt(model):
-    try:
-        return model._meta.app_label, model._meta.model_name  # Django 1.7 format
-    except AttributeError:
-        return model._meta.app_label, model._meta.module_name
+    return model._meta.app_label, model._meta.model_name
diff --git a/polymorphic/base.py b/polymorphic/base.py
index c42ce89..b6a5a74 100644
--- a/polymorphic/base.py
+++ b/polymorphic/base.py
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
-""" PolymorphicModel Meta Class
-    Please see README.rst or DOCS.rst or http://chrisglass.github.com/django_polymorphic/
+"""
+PolymorphicModel Meta Class
 """
 from __future__ import absolute_import
 
@@ -132,6 +132,17 @@ class PolymorphicModelBase(ModelBase):
                     if type(manager) == models.manager.ManagerDescriptor:
                         manager = manager.manager
 
+                    # As of Django 1.5, the abstract models don't get any managers, only a
+                    # AbstractManagerDescriptor as substitute.
+                    if type(manager) == AbstractManagerDescriptor and base.__name__ == 'PolymorphicModel':
+                        model = manager.model
+                        if key == 'objects':
+                            manager = PolymorphicManager()
+                            manager.model = model
+                        elif key == 'base_objects':
+                            manager = models.Manager()
+                            manager.model = model
+
                     if AbstractManagerDescriptor is not None:
                         # Django 1.4 unconditionally assigned managers to a model. As of Django 1.5 however,
                         # the abstract models don't get any managers, only a AbstractManagerDescriptor as substitute.
diff --git a/polymorphic/formsets/generic.py b/polymorphic/formsets/generic.py
index 90c0ec1..c085757 100644
--- a/polymorphic/formsets/generic.py
+++ b/polymorphic/formsets/generic.py
@@ -1,15 +1,11 @@
 import django
+from django.contrib.contenttypes.forms import BaseGenericInlineFormSet, generic_inlineformset_factory
 from django.contrib.contenttypes.models import ContentType
 from django.db import models
 from django.forms.models import ModelForm
 
 from .models import BasePolymorphicModelFormSet, polymorphic_child_forms_factory, PolymorphicFormSetChild
 
-try:
-    from django.contrib.contenttypes.forms import BaseGenericInlineFormSet, generic_inlineformset_factory  # Django 1.7+
-except ImportError:
-    from django.contrib.contenttypes.generic import BaseGenericInlineFormSet, generic_inlineformset_factory
-
 
 class GenericPolymorphicFormSetChild(PolymorphicFormSetChild):
     """
diff --git a/polymorphic/formsets/models.py b/polymorphic/formsets/models.py
index d715e72..b13adf8 100644
--- a/polymorphic/formsets/models.py
+++ b/polymorphic/formsets/models.py
@@ -1,3 +1,4 @@
+from collections import OrderedDict
 
 import django
 from django import forms
@@ -7,11 +8,6 @@ from django.forms.models import ModelForm, BaseModelFormSet, BaseInlineFormSet,
 from django.utils.functional import cached_property
 from .utils import add_media
 
-try:
-    from collections import OrderedDict
-except ImportError:
-    from django.utils.datastructures import SortedDict as OrderedDict  # Python 2.6
-
 
 class PolymorphicFormSetChild(object):
     """
diff --git a/polymorphic/locale/en/LC_MESSAGES/django.po b/polymorphic/locale/en/LC_MESSAGES/django.po
index 8766f6a..b1aa82c 100644
--- a/polymorphic/locale/en/LC_MESSAGES/django.po
+++ b/polymorphic/locale/en/LC_MESSAGES/django.po
@@ -26,10 +26,10 @@ msgid "Content type"
 msgstr ""
 
 # This is already translated in Django
-#: admin.py:333
-#, python-format
-#msgid "Add %s"
-#msgstr ""
+# #: admin.py:333
+# #, python-format
+# msgid "Add %s"
+# msgstr ""
 
 #: admin.py:403
 msgid "Contents"
diff --git a/polymorphic/locale/fr/LC_MESSAGES/django.po b/polymorphic/locale/fr/LC_MESSAGES/django.po
index 052bc0d..eb43c2a 100644
--- a/polymorphic/locale/fr/LC_MESSAGES/django.po
+++ b/polymorphic/locale/fr/LC_MESSAGES/django.po
@@ -27,10 +27,10 @@ msgid "Content type"
 msgstr "Type de contenu"
 
 # This is already translated in Django
-#: admin.py:333
-#, python-format
-#msgid "Add %s"
-#msgstr ""
+# #: admin.py:333
+# #, python-format
+# msgid "Add %s"
+# msgstr ""
 
 #: admin.py:403
 msgid "Contents"
diff --git a/polymorphic/managers.py b/polymorphic/managers.py
index d2e677e..d743eec 100644
--- a/polymorphic/managers.py
+++ b/polymorphic/managers.py
@@ -4,15 +4,10 @@ The manager class for use in the models.
 """
 from __future__ import unicode_literals
 import warnings
-import django
 from django.db import models
+from django.utils.six import python_2_unicode_compatible
 from polymorphic.query import PolymorphicQuerySet
 
-try:
-    from django.utils.six import python_2_unicode_compatible
-except ImportError:
-    from django.utils.encoding import python_2_unicode_compatible  # Django 1.5
-
 
 __all__ = (
     'PolymorphicManager',
@@ -32,6 +27,12 @@ class PolymorphicManager(models.Manager):
     use_for_related_fields = True
     queryset_class = PolymorphicQuerySet
 
+    @classmethod
+    def from_queryset(cls, queryset_class, class_name=None):
+        manager = super(PolymorphicManager, cls).from_queryset(queryset_class, class_name=class_name)
+        manager.queryset_class = queryset_class  # also set our version, Django uses _queryset_class
+        return manager
+
     def __init__(self, queryset_class=None, *args, **kwrags):
         # Up till polymorphic 0.4, the queryset class could be specified as parameter to __init__.
         # However, this doesn't work for related managers which instantiate a new version of this class.
@@ -44,18 +45,11 @@ class PolymorphicManager(models.Manager):
         super(PolymorphicManager, self).__init__(*args, **kwrags)
 
     def get_queryset(self):
-        if django.VERSION >= (1, 7):
-            qs = self.queryset_class(self.model, using=self._db, hints=self._hints)
-        else:
-            qs = self.queryset_class(self.model, using=self._db)
+        qs = self.queryset_class(self.model, using=self._db, hints=self._hints)
         if self.model._meta.proxy:
             qs = qs.instance_of(self.model)
         return qs
 
-    # For Django 1.5
-    if django.VERSION < (1, 7):
-        get_query_set = get_queryset
-
     def __str__(self):
         return '%s (PolymorphicManager) using %s' % (self.__class__.__name__, self.queryset_class.__name__)
 
@@ -71,10 +65,3 @@ class PolymorphicManager(models.Manager):
 
     def get_real_instances(self, base_result_objects=None):
         return self.all().get_real_instances(base_result_objects=base_result_objects)
-
-    if django.VERSION >= (1, 7):
-        @classmethod
-        def from_queryset(cls, queryset_class, class_name=None):
-            manager = super(PolymorphicManager, cls).from_queryset(queryset_class, class_name=class_name)
-            manager.queryset_class = queryset_class  # also set our version, Django uses _queryset_class
-            return manager
diff --git a/polymorphic/models.py b/polymorphic/models.py
index ef98991..f0af431 100644
--- a/polymorphic/models.py
+++ b/polymorphic/models.py
@@ -4,9 +4,9 @@ Seamless Polymorphic Inheritance for Django Models
 """
 from __future__ import absolute_import
 
+from django.contrib.contenttypes.models import ContentType
 from django.db import models
 from django.db.utils import DEFAULT_DB_ALIAS
-from django.contrib.contenttypes.models import ContentType
 from django.utils import six
 
 from .base import PolymorphicModelBase
@@ -37,8 +37,10 @@ class PolymorphicModel(six.with_metaclass(PolymorphicModelBase, models.Model)):
 
     # avoid ContentType related field accessor clash (an error emitted by model validation)
     #: The model field that stores the :class:`~django.contrib.contenttypes.models.ContentType` reference to the actual class.
-    polymorphic_ctype = models.ForeignKey(ContentType, null=True, editable=False,
-                                          related_name='polymorphic_%(app_label)s.%(class)s_set+')
+    polymorphic_ctype = models.ForeignKey(
+        ContentType, null=True, editable=False, on_delete=models.CASCADE,
+        related_name='polymorphic_%(app_label)s.%(class)s_set+'
+    )
 
     # some applications want to know the name of the fields that are added to its models
     polymorphic_internal_model_fields = ['polymorphic_ctype']
@@ -85,11 +87,7 @@ class PolymorphicModel(six.with_metaclass(PolymorphicModelBase, models.Model)):
         # so we use the following version, which uses the ContentType manager cache.
         # Note that model_class() can return None for stale content types;
         # when the content type record still exists but no longer refers to an existing model.
-        try:
-            model = ContentType.objects.db_manager(self._state.db).get_for_id(self.polymorphic_ctype_id).model_class()
-        except AttributeError:
-            # Django <1.6 workaround
-            return None
+        model = ContentType.objects.db_manager(self._state.db).get_for_id(self.polymorphic_ctype_id).model_class()
 
         # Protect against bad imports (dumpdata without --natural) or other
         # issues missing with the ContentType models.
@@ -173,9 +171,9 @@ class PolymorphicModel(six.with_metaclass(PolymorphicModelBase, models.Model)):
                 ReverseSingleRelatedObjectDescriptor as ForwardManyToOneDescriptor,
             )
         for name, model in subclasses_and_superclasses_accessors.items():
+            # Here be dragons.
             orig_accessor = getattr(self.__class__, name, None)
-            if type(orig_accessor) in [ReverseOneToOneDescriptor, ForwardManyToOneDescriptor]:
-                # print >>sys.stderr, '---------- replacing', name, orig_accessor, '->', model
+            if issubclass(type(orig_accessor), (ReverseOneToOneDescriptor, ForwardManyToOneDescriptor)):
                 setattr(self.__class__, name, property(create_accessor_function_for_model(model, name)))
 
     def _get_inheritance_relation_fields_and_models(self):
diff --git a/polymorphic/query.py b/polymorphic/query.py
index 8fab5e6..3d881d8 100644
--- a/polymorphic/query.py
+++ b/polymorphic/query.py
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
... 964 lines suppressed ...

-- 
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