[Python-modules-commits] [django-polymorphic] 01/04: Import django-polymorphic_0.7.2.orig.tar.gz
Michael Fladischer
fladi at moszumanska.debian.org
Mon Oct 12 11:12:59 UTC 2015
This is an automated email from the git hooks/post-receive script.
fladi pushed a commit to branch master
in repository django-polymorphic.
commit 5388ff514d9a6f87d435cc4316dafd7cfde55832
Author: Michael Fladischer <FladischerMichael at fladi.at>
Date: Mon Oct 12 12:49:13 2015 +0200
Import django-polymorphic_0.7.2.orig.tar.gz
---
.travis.yml | 26 +++++-----
docs/admin.rst | 2 +
docs/changelog.rst | 12 ++++-
docs/conf.py | 4 +-
polymorphic/__version__.py | 2 +-
polymorphic/admin.py | 9 ++--
polymorphic/base.py | 15 +++---
polymorphic/query.py | 14 +++++-
polymorphic/tests.py | 22 ++++++++
tox.ini | 122 ++++++---------------------------------------
10 files changed, 90 insertions(+), 138 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index a769642..5553c32 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -4,29 +4,29 @@ python:
- "2.7"
- "3.2"
- "3.3"
+ - "3.4"
env:
- - DJANGO=django==1.4.5
- - DJANGO=django==1.5
- - DJANGO=django==1.6
- - DJANGO=django==1.7
- - DJANGO=django==1.8
- #- DJANGO=https://github.com/django/django/archive/stable/1.6.x.zip
+ - DJANGO=">=1.4,<1.5"
+ - DJANGO=">=1.5,<1.6"
+ - DJANGO=">=1.6,<1.7"
+ - DJANGO=">=1.7,<1.8"
+ - DJANGO=">=1.8,<1.9"
matrix:
exclude:
+ - python: "3.4"
+ env: DJANGO=">=1.4,<1.5"
- python: "3.3"
- env: DJANGO=django==1.4.5
+ env: DJANGO=">=1.4,<1.5"
- python: "3.2"
- env: DJANGO=django==1.4.5
+ env: DJANGO=">=1.4,<1.5"
- python: "2.6"
- env: DJANGO=django==1.7
+ env: DJANGO=">=1.7,<1.8"
- python: "2.6"
- env: DJANGO=django==1.8
- - python: "2.6"
- env: DJANGO=https://www.djangoproject.com/download/1.8a1/tarball/
+ env: DJANGO=">=1.8,<1.9"
install:
- - pip install $DJANGO coverage==3.6
+ - pip install django$DJANGO coverage==3.6
script:
- coverage run --source=polymorphic runtests.py
diff --git a/docs/admin.rst b/docs/admin.rst
index 3da96d6..7de3048 100644
--- a/docs/admin.rst
+++ b/docs/admin.rst
@@ -86,10 +86,12 @@ The models are taken from :ref:`advanced-features`.
class ModelBAdmin(ModelAChildAdmin):
+ base_model = ModelB
# define custom features here
class ModelCAdmin(ModelBAdmin):
+ base_model = ModelC
# define custom features here
diff --git a/docs/changelog.rst b/docs/changelog.rst
index e67f2ea..cb657f3 100644
--- a/docs/changelog.rst
+++ b/docs/changelog.rst
@@ -1,7 +1,17 @@
Changelog
==========
-Version 0.7.1 (2015-04/30)
+Version 0.7.2 (2015-10-01)
+--------------------------
+
+* Added ``queryset.as_manager()`` support for Django 1.7/1.8
+* Optimize model access for non-dumpdata usage; avoid ``__getattribute__()`` call each time to access the manager.
+* Fixed 500 error when using invalid PK's in the admin URL, return 404 instead.
+* Fixed possible issues when using an custom ``AdminSite`` class for the parent object.
+* Fixed Pickle exception when polymorphic model is cached.
+
+
+Version 0.7.1 (2015-04-30)
--------------------------
* Fixed Django 1.8 support for related field widgets.
diff --git a/docs/conf.py b/docs/conf.py
index 0103ca2..da84e0f 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -54,9 +54,9 @@ copyright = u'2013, Bert Constantin, Chris Glass, Diederik van der Boor'
# built documents.
#
# The short X.Y version.
-version = '0.7'
+version = '0.7.2'
# The full version, including alpha/beta/rc tags.
-release = '0.7'
+release = '0.7.2'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
diff --git a/polymorphic/__version__.py b/polymorphic/__version__.py
index d9c80ff..32f061a 100644
--- a/polymorphic/__version__.py
+++ b/polymorphic/__version__.py
@@ -2,4 +2,4 @@
"""
See PEP 440 (https://www.python.org/dev/peps/pep-0440/)
"""
-__version__ = "0.7.1"
+__version__ = "0.7.2"
diff --git a/polymorphic/admin.py b/polymorphic/admin.py
index 310a6b8..216f74f 100644
--- a/polymorphic/admin.py
+++ b/polymorphic/admin.py
@@ -6,7 +6,6 @@ from django import forms
from django.conf.urls import patterns, url
from django.contrib import admin
from django.contrib.admin.helpers import AdminForm, AdminErrorList
-from django.contrib.admin.sites import AdminSite
from django.contrib.admin.widgets import AdminRadioSelect
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import PermissionDenied
@@ -125,7 +124,7 @@ class PolymorphicParentModelAdmin(admin.ModelAdmin):
def __init__(self, model, admin_site, *args, **kwargs):
super(PolymorphicParentModelAdmin, self).__init__(model, admin_site, *args, **kwargs)
- self._child_admin_site = AdminSite(name=self.admin_site.name)
+ self._child_admin_site = self.admin_site.__class__(name=self.admin_site.name)
self._is_setup = False
@@ -199,7 +198,11 @@ class PolymorphicParentModelAdmin(admin.ModelAdmin):
def _get_real_admin(self, object_id):
- obj = self.model.objects.non_polymorphic().values('polymorphic_ctype').get(pk=object_id)
+ try:
+ obj = self.model.objects.non_polymorphic() \
+ .values('polymorphic_ctype').get(pk=object_id)
+ except self.model.DoesNotExist:
+ raise Http404
return self._get_real_admin_by_ct(obj['polymorphic_ctype'])
diff --git a/polymorphic/base.py b/polymorphic/base.py
index 83cb7a4..10fe58c 100644
--- a/polymorphic/base.py
+++ b/polymorphic/base.py
@@ -229,21 +229,20 @@ class PolymorphicModelBase(ModelBase):
# Django's management command 'dumpdata' relies on non-polymorphic
# behaviour of the _default_manager. Therefore, we catch any access to _default_manager
# here and return the non-polymorphic default manager instead if we are called from 'dumpdata.py'
+ # Otherwise, the base objects will be upcasted to polymorphic models, and be outputted as such.
# (non-polymorphic default manager is 'base_objects' for polymorphic models).
# This way we don't need to patch django.core.management.commands.dumpdata
# for all supported Django versions.
- # TODO: investigate Django how this can be avoided
- _dumpdata_command_running = False
- if len(sys.argv) > 1:
- _dumpdata_command_running = (sys.argv[1] == 'dumpdata')
+ if len(sys.argv) > 1 and sys.argv[1] == 'dumpdata':
+ # manage.py dumpdata is running
- def __getattribute__(self, name):
- if name == '_default_manager':
- if self._dumpdata_command_running:
+ def __getattribute__(self, name):
+ if name == '_default_manager':
frm = inspect.stack()[1] # frm[1] is caller file name, frm[3] is caller function name
if 'django/core/management/commands/dumpdata.py' in frm[1]:
return self.base_objects
#caller_mod_name = inspect.getmodule(frm[0]).__name__ # does not work with python 2.4
#if caller_mod_name == 'django.core.management.commands.dumpdata':
- return super(PolymorphicModelBase, self).__getattribute__(name)
+ return super(PolymorphicModelBase, self).__getattribute__(name)
+ # TODO: investigate Django how this can be avoided
diff --git a/polymorphic/query.py b/polymorphic/query.py
index 5c4dee7..3ecaea5 100644
--- a/polymorphic/query.py
+++ b/polymorphic/query.py
@@ -64,6 +64,16 @@ class PolymorphicQuerySet(QuerySet):
new.polymorphic_disabled = self.polymorphic_disabled
return new
+ if django.VERSION >= (1,7):
+ def as_manager(cls):
+ # Make sure the Django 1.7 way of creating managers works.
+ from .manager import PolymorphicManager
+ manager = PolymorphicManager.from_queryset(cls)()
+ manager._built_with_as_manager = True
+ return manager
+ as_manager.queryset_only = True
+ as_manager = classmethod(as_manager)
+
def non_polymorphic(self, *args, **kwargs):
"""switch off polymorphic behaviour for this query.
When the queryset is evaluated, only objects of the type of the
@@ -246,13 +256,13 @@ class PolymorphicQuerySet(QuerySet):
# set polymorphic_annotate_names in all objects (currently just used for debugging/printing)
if self.query.aggregates:
- annotate_names = six.iterkeys(self.query.aggregates) # get annotate field list
+ annotate_names = list(six.iterkeys(self.query.aggregates)) # get annotate field list
for real_object in resultlist:
real_object.polymorphic_annotate_names = annotate_names
# set polymorphic_extra_select_names in all objects (currently just used for debugging/printing)
if self.query.extra_select:
- extra_select_names = six.iterkeys(self.query.extra_select) # get extra select field list
+ extra_select_names = list(six.iterkeys(self.query.extra_select)) # get extra select field list
for real_object in resultlist:
real_object.polymorphic_extra_select_names = extra_select_names
diff --git a/polymorphic/tests.py b/polymorphic/tests.py
index b14503e..14def4d 100644
--- a/polymorphic/tests.py
+++ b/polymorphic/tests.py
@@ -6,6 +6,7 @@ from __future__ import print_function
import uuid
import re
import django
+from django.utils.unittest import skipIf
from django.db.models.query import QuerySet
from django.test import TestCase
@@ -113,6 +114,11 @@ class ModelWithMyManager(ShowFieldTypeAndContent, Model2A):
objects = MyManager()
field4 = models.CharField(max_length=10)
+if django.VERSION >= (1,7):
+ class ModelWithMyManager2(ShowFieldTypeAndContent, Model2A):
+ objects = MyManagerQuerySet.as_manager()
+ field4 = models.CharField(max_length=10)
+
class MROBase1(ShowFieldType, PolymorphicModel):
objects = MyManager()
field1 = models.CharField(max_length=10) # needed as MyManager uses it
@@ -684,6 +690,21 @@ class PolymorphicTests(TestCase):
self.assertIs(type(ModelWithMyManager._default_manager), MyManager)
self.assertIs(type(ModelWithMyManager.base_objects), models.Manager)
+ @skipIf(django.VERSION < (1,7), "This test needs Django 1.7+")
+ def test_user_defined_queryset_as_manager(self):
+ self.create_model2abcd()
+ ModelWithMyManager2.objects.create(field1='D1a', field4='D4a')
+ ModelWithMyManager2.objects.create(field1='D1b', field4='D4b')
+
+ objects = ModelWithMyManager2.objects.all()
+ self.assertEqual(repr(objects[0]), '<ModelWithMyManager2: id 5, field1 (CharField) "D1a", field4 (CharField) "D4a">')
+ self.assertEqual(repr(objects[1]), '<ModelWithMyManager2: id 6, field1 (CharField) "D1b", field4 (CharField) "D4b">')
+ self.assertEqual(len(objects), 2)
+
+ self.assertEqual(type(ModelWithMyManager2.objects).__name__, 'PolymorphicManagerFromMyManagerQuerySet')
+ self.assertEqual(type(ModelWithMyManager2._default_manager).__name__, 'PolymorphicManagerFromMyManagerQuerySet')
+ self.assertIs(type(ModelWithMyManager2.base_objects), models.Manager)
+
def test_manager_inheritance(self):
# by choice of MRO, should be MyManager from MROBase1.
@@ -829,6 +850,7 @@ class PolymorphicTests(TestCase):
t.delete()
+
class RegressionTests(TestCase):
def test_for_query_result_incomplete_with_inheritance(self):
diff --git a/tox.ini b/tox.ini
index 014fa21..5a551f2 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,119 +1,25 @@
[tox]
envlist=
- py26-django14,
- py26-django15,
- py26-django16,
-
- py27-django14,
- py27-django15,
- py27-django16,
- py27-django17,
- py27-django18,
-
- py32-django15,
- py32-django16,
- py32-django17,
- py32-django18,
-
- py33-django15,
- py33-django16,
- py33-django17,
- py33-django18,
-
- py33-django-dev,
+ py26-django{14,15,16},
+ py27-django{14,15,16,17,18},
+ py32-django{15,16,17,18},
+ py33-django{15,16,17,18},
+ py34-django{15,16,17,18},
+ # py33-django-dev,
docs,
[testenv]
+deps =
+ django14: Django >= 1.4, < 1.5
+ django15: Django >= 1.5, < 1.6
+ django16: Django >= 1.6, < 1.7
+ django17: Django >= 1.7, < 1.8
+ django18: Django >= 1.8, < 1.9
+ django19: Django >= 1.9a1, < 1.10
+ django-dev: https://github.com/django/django/tarball/master
commands=
python runtests.py
-# Build configurations
-
-[testenv:py26-django14]
-basepython=python2.6
-deps=
- django==1.4.5
-
-[testenv:py26-django15]
-basepython=python2.6
-deps=
- django==1.5
-
-[testenv:py26-django16]
-basepython=python2.6
-deps=
- django==1.6
-
-[testenv:py27-django14]
-basepython=python2.7
-deps=
- django==1.4.5
-
-[testenv:py27-django15]
-basepython=python2.7
-deps=
- django==1.5
-
-[testenv:py27-django16]
-basepython=python2.7
-deps=
- django==1.6
-
-[testenv:py27-django17]
-basepython=python2.7
-deps=
- django==1.7
-
-[testenv:py27-django18]
-basepython=python2.7
-deps=
- django==1.8
-
-[testenv:py32-django15]
-basepython=python3.2
-deps=
- django==1.5
-
-[testenv:py32-django16]
-basepython=python3.2
-deps=
- django==1.6
-
-[testenv:py32-django17]
-basepython=python3.2
-deps=
- django==1.7
-
-[testenv:py32-django18]
-basepython=python3.2
-deps=
- django==1.8
-
-[testenv:py33-django15]
-basepython=python3.3
-deps=
- django==1.5
-
-[testenv:py33-django16]
-basepython=python3.3
-deps=
- django==1.6
-
-[testenv:py33-django17]
-basepython=python3.3
-deps=
- django==1.7
-
-[testenv:py33-django18]
-basepython=python3.3
-deps=
- django==1.8
-
-[testenv:py33-django-dev]
-basepython=python3.3
-deps=
- https://github.com/django/django/archive/master.zip
-
[testenv:docs]
changedir=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