[Python-modules-commits] [django-polymorphic] 01/07: Import django-polymorphic_0.9.2.orig.tar.gz

Michael Fladischer fladi at moszumanska.debian.org
Thu May 12 16:48:44 UTC 2016


This is an automated email from the git hooks/post-receive script.

fladi pushed a commit to branch master
in repository django-polymorphic.

commit d95b26a48a4bb5c234781c000b2ef40933f5e20c
Author: Michael Fladischer <FladischerMichael at fladi.at>
Date:   Thu May 12 12:26:29 2016 +0200

    Import django-polymorphic_0.9.2.orig.tar.gz
---
 docs/changelog.rst      |  7 ++++
 docs/conf.py            |  4 +--
 polymorphic/__init__.py |  2 +-
 polymorphic/admin.py    | 14 ++++++--
 polymorphic/query.py    | 87 ++++++++++++++++++++++++-------------------------
 polymorphic/tests.py    | 14 ++++++++
 6 files changed, 78 insertions(+), 50 deletions(-)

diff --git a/docs/changelog.rst b/docs/changelog.rst
index 4c98807..6053688 100644
--- a/docs/changelog.rst
+++ b/docs/changelog.rst
@@ -1,6 +1,13 @@
 Changelog
 =========
 
+Version 0.9.2 (2016-05-04)
+--------------------------
+
+* Fix error when using ``date_hierarchy`` field in the admin
+* Fixed Django 1.10 warning in admin add-type view.
+
+
 Version 0.9.1 (2016-02-18)
 --------------------------
 
diff --git a/docs/conf.py b/docs/conf.py
index 44d4463..7f84262 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -55,9 +55,9 @@ copyright = u'2013, Bert Constantin, Chris Glass, Diederik van der Boor'
 # built documents.
 #
 # The short X.Y version.
-version = '0.9.1'
+version = '0.9.2'
 # The full version, including alpha/beta/rc tags.
-release = '0.9.1'
+release = '0.9.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 73822aa..e74c4b3 100644
--- a/polymorphic/__init__.py
+++ b/polymorphic/__init__.py
@@ -7,7 +7,7 @@ This code and affiliated files are (C) by Bert Constantin and individual contrib
 Please see LICENSE and AUTHORS for more information.
 """
 # See PEP 440 (https://www.python.org/dev/peps/pep-0440/)
-__version__ = "0.9.1"
+__version__ = "0.9.2"
 
 
 # Monkey-patch Django < 1.5 to allow ContentTypes for proxy models.
diff --git a/polymorphic/admin.py b/polymorphic/admin.py
index ad40a90..ee7a934 100644
--- a/polymorphic/admin.py
+++ b/polymorphic/admin.py
@@ -426,13 +426,21 @@ class PolymorphicParentModelAdmin(admin.ModelAdmin):
         })
         if hasattr(self.admin_site, 'root_path'):
             context['root_path'] = self.admin_site.root_path  # Django < 1.4
-        context_instance = RequestContext(request, current_app=self.admin_site.name)
-        return render_to_response(self.add_type_template or [
+
+        templates = self.add_type_template or [
             "admin/%s/%s/add_type_form.html" % (app_label, opts.object_name.lower()),
             "admin/%s/add_type_form.html" % app_label,
             "admin/polymorphic/add_type_form.html",  # added default here
             "admin/add_type_form.html"
-        ], context, context_instance=context_instance)
+        ]
+
+        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)
 
     @property
     def change_list_template(self):
diff --git a/polymorphic/query.py b/polymorphic/query.py
index 1b71bdd..b868764 100644
--- a/polymorphic/query.py
+++ b/polymorphic/query.py
@@ -182,54 +182,53 @@ class PolymorphicQuerySet(QuerySet):
     def _process_aggregate_args(self, args, kwargs):
         """for aggregate and annotate kwargs: allow ModelX___field syntax for kwargs, forbid it for args.
         Modifies kwargs if needed (these are Aggregate objects, we translate the lookup member variable)"""
-
-        def patch_lookup_lt_18(a):
-            a.lookup = translate_polymorphic_field_path(self.model, a.lookup)
-
-                    
-        def patch_lookup_gte_18(a):
-            # With Django > 1.8, the field on which the aggregate operates is
-            # stored inside a complex query expression.
-            if isinstance(a, Q):
-                translate_polymorphic_Q_object(self.model, a)
-            elif hasattr(a, 'get_source_expressions'):
-                for source_expression in a.get_source_expressions():
-                    patch_lookup_gte_18(source_expression)
-            else:
-                a.name = translate_polymorphic_field_path(self.model, a.name)
-                
         ___lookup_assert_msg = 'PolymorphicModel: annotate()/aggregate(): ___ model lookup supported for keyword arguments only'
-        def test___lookup_for_args_lt_18(a):
-            assert '___' not in a.lookup, ___lookup_assert_msg
-            
-        def test___lookup_for_args_gte_18(a):
-            """ *args might be complex expressions too in django 1.8 so
-            the testing for a '___' is rather complex on this one """
-            if isinstance(a, Q):
-                def tree_node_test___lookup(my_model, node):
-                    " process all children of this Q node "
-                    for i in range(len(node.children)):
-                        child = node.children[i]
-            
-                        if type(child) == tuple:
-                            # this Q object child is a tuple => a kwarg like Q( instance_of=ModelB )
-                            assert '___' not in child[0], ___lookup_assert_msg
-                        else:
-                            # this Q object child is another Q object, recursively process this as well
-                            tree_node_test___lookup(my_model, child)
-                            
-                tree_node_test___lookup(self.model, a)
-            elif hasattr(a, 'get_source_expressions'):
-                for source_expression in a.get_source_expressions():
-                    test___lookup_for_args_gte_18(source_expression)
-            else:
-                assert '___' not in a.name, ___lookup_assert_msg
-                    
+
+        if django.VERSION < (1, 8):
+            def patch_lookup(a):
+                a.lookup = translate_polymorphic_field_path(self.model, a.lookup)
+
+            def test___lookup(a):
+                assert '___' not in a.lookup, ___lookup_assert_msg
+        else:
+            def patch_lookup(a):
+                # With Django > 1.8, the field on which the aggregate operates is
+                # stored inside a complex query expression.
+                if isinstance(a, Q):
+                    translate_polymorphic_Q_object(self.model, a)
+                elif hasattr(a, 'get_source_expressions'):
+                    for source_expression in a.get_source_expressions():
+                        if source_expression is not None:
+                            patch_lookup(source_expression)
+                else:
+                    a.name = translate_polymorphic_field_path(self.model, a.name)
+
+            def test___lookup(a):
+                """ *args might be complex expressions too in django 1.8 so
+                the testing for a '___' is rather complex on this one """
+                if isinstance(a, Q):
+                    def tree_node_test___lookup(my_model, node):
+                        " process all children of this Q node "
+                        for i in range(len(node.children)):
+                            child = node.children[i]
+
+                            if type(child) == tuple:
+                                # this Q object child is a tuple => a kwarg like Q( instance_of=ModelB )
+                                assert '___' not in child[0], ___lookup_assert_msg
+                            else:
+                                # this Q object child is another Q object, recursively process this as well
+                                tree_node_test___lookup(my_model, child)
+
+                    tree_node_test___lookup(self.model, a)
+                elif hasattr(a, 'get_source_expressions'):
+                    for source_expression in a.get_source_expressions():
+                        test___lookup(source_expression)
+                else:
+                    assert '___' not in a.name, ___lookup_assert_msg
+
         for a in args:
-            test___lookup = test___lookup_for_args_lt_18 if django.VERSION < (1, 8) else test___lookup_for_args_gte_18
             test___lookup(a)
         for a in six.itervalues(kwargs):
-            patch_lookup = patch_lookup_lt_18 if django.VERSION < (1, 8) else patch_lookup_gte_18
             patch_lookup(a)
 
     def annotate(self, *args, **kwargs):
diff --git a/polymorphic/tests.py b/polymorphic/tests.py
index 3e1aa4f..ddc3a3b 100644
--- a/polymorphic/tests.py
+++ b/polymorphic/tests.py
@@ -420,6 +420,11 @@ class CustomPkInherit(CustomPkBase):
     i = models.CharField(max_length=1)
 
 
+class DateModel(PolymorphicModel):
+
+    date = models.DateTimeField()
+
+
 class PolymorphicTests(TestCase):
     """
     The test suite
@@ -1137,6 +1142,15 @@ class PolymorphicTests(TestCase):
         with self.assertRaisesMessage(AssertionError, 'PolymorphicModel: annotate()/aggregate(): ___ model lookup supported for keyword arguments only'):
             Model2A.objects.aggregate(ComplexAgg('Model2B___field2'))
 
+    @skipIf(django.VERSION < (1,8,), "This test needs Django >=1.8")
+    def test_polymorphic__expressions(self):
+
+        from django.db.models.expressions import DateTime
+        from django.utils.timezone import utc
+
+        # no exception raised
+        result = DateModel.objects.annotate(val=DateTime('date', 'day', utc))
+        self.assertEqual(list(result), [])
 
 
 class RegressionTests(TestCase):

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