File: django-1.7.patch

package info (click to toggle)
django-polymorphic 0.6-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 436 kB
  • ctags: 586
  • sloc: python: 2,208; makefile: 142
file content (334 lines) | stat: -rw-r--r-- 11,244 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
Description: Fix tests for Django-1.7
 Taken from upstream to fix the testsuite for Django 1.7.
Author: Chad Shryock <cdshryock@gannett.com>
Last-Update: 2014-09-19
Origin: https://github.com/chrisglass/django_polymorphic/pull/102
Bug: https://bugs.debian.org/755602

--- a/polymorphic/admin.py
+++ b/polymorphic/admin.py
@@ -220,8 +220,17 @@
 
 
     def queryset(self, request):
+        return self.get_queryset(request)
+
+
+    def get_queryset(self, request):
         # optimize the list display.
-        qs = super(PolymorphicParentModelAdmin, self).queryset(request)
+        parent_self = super(PolymorphicParentModelAdmin, self)
+        if hasattr(parent_self, 'get_queryset'):
+            qs = parent_self.get_queryset(request)
+        else:
+            qs = parent_self.queryset(request)
+
         if not self.polymorphic_list:
             qs = qs.non_polymorphic()
         return qs
@@ -262,7 +271,8 @@
         Expose the custom URLs for the subclasses and the URL resolver.
         """
         urls = super(PolymorphicParentModelAdmin, self).get_urls()
-        info = self.model._meta.app_label, self.model._meta.module_name
+        meta = self.model._meta
+        info = meta.app_label, getattr(meta, 'model_name', meta.module_name)
 
         # Patch the change URL so it's not a big catch-all; allowing all custom URLs to be added to the end.
         # The url needs to be recreated, patching url.regex is not an option Django 1.4's LocaleRegexProvider changed it.
--- a/polymorphic/manager.py
+++ b/polymorphic/manager.py
@@ -30,9 +30,13 @@
 
         super(PolymorphicManager, self).__init__(*args, **kwrags)
 
-    def get_query_set(self):
+    def get_queryset(self):
         return self.queryset_class(self.model, using=self._db)
 
+    def get_query_set(self):
+        return self.get_queryset()
+
+
     # Proxy all unknown method calls to the queryset, so that its members are
     # directly accessible as PolymorphicModel.objects.*
     # The advantage of this method is that not yet known member functions of derived querysets will be proxied as well.
--- a/runtests.py
+++ b/runtests.py
@@ -18,6 +18,10 @@
 # Detect location and available modules
 module_root = dirname(realpath(__file__))
 
+test_runner = 'django.test.runner.DiscoverRunner'
+if django.VERSION[:2] < (1, 6):
+    test_runner = 'django.test.simple.DjangoTestSuiteRunner'
+
 # Inline settings file
 settings.configure(
     DEBUG = False,  # will be False anyway by DjangoTestRunner.
@@ -43,9 +47,15 @@
         'polymorphic',
     ),
     SITE_ID = 3,
+    TEST_RUNNER = test_runner,
+    MIDDLEWARE_CLASSES = (),
 )
 
-call_command('syncdb', verbosity=1, interactive=False)
+if django.VERSION[:2] > (1, 6):
+    django.setup()
+    call_command('migrate', verbosity=1, interactive=False)
+else:
+    call_command('syncdb', verbosity=1, interactive=False)
 
 
 # ---- app start
--- a/polymorphic/tests.py
+++ b/polymorphic/tests.py
@@ -5,6 +5,7 @@
 from __future__ import print_function
 import uuid
 import re
+import django
 from django.db.models.query import QuerySet
 
 from django.test import TestCase
@@ -66,21 +67,45 @@
 class ModelY(Base):
     field_y = models.CharField(max_length=10)
 
-class Enhance_Plain(models.Model):
-    field_p = models.CharField(max_length=10)
-class Enhance_Base(ShowFieldTypeAndContent, PolymorphicModel):
-    field_b = models.CharField(max_length=10)
-class Enhance_Inherit(Enhance_Base, Enhance_Plain):
-    field_i = models.CharField(max_length=10)
-
-class DiamondBase(models.Model):
-    field_b = models.CharField(max_length=10)
-class DiamondX(DiamondBase):
-    field_x = models.CharField(max_length=10)
-class DiamondY(DiamondBase):
-    field_y = models.CharField(max_length=10)
-class DiamondXY(DiamondX, DiamondY):
-    pass
+if django.VERSION[:2] > (1, 6):
+    class Enhance_Plain(models.Model):
+        field_p = models.CharField(max_length=10)
+    class Enhance_Base(ShowFieldTypeAndContent, PolymorphicModel):
+        base_id = models.AutoField(primary_key=True)
+        field_b = models.CharField(max_length=10)
+    class Enhance_Inherit(Enhance_Base, Enhance_Plain):
+        field_i = models.CharField(max_length=10)
+
+    class DiamondBase(models.Model):
+        field_b = models.CharField(max_length=10)
+    class DiamondX(DiamondBase):
+        x_id = models.AutoField(primary_key=True)
+        field_x = models.CharField(max_length=10)
+    class DiamondY(DiamondBase):
+        y_id = models.AutoField(primary_key=True)
+        field_y = models.CharField(max_length=10)
+    class DiamondXY(DiamondBase):
+        xy_id = models.AutoField(primary_key=True)
+        field_x = models.CharField(max_length=10)
+        field_y = models.CharField(max_length=10)
+else:
+    class Enhance_Plain(models.Model):
+        field_p = models.CharField(max_length=10)
+    class Enhance_Base(ShowFieldTypeAndContent, PolymorphicModel):
+        field_b = models.CharField(max_length=10)
+    class Enhance_Inherit(Enhance_Base, Enhance_Plain):
+        field_i = models.CharField(max_length=10)
+
+    class DiamondBase(models.Model):
+        field_b = models.CharField(max_length=10)
+    class DiamondX(DiamondBase):
+        x_id = models.AutoField(primary_key=True)
+        field_x = models.CharField(max_length=10)
+    class DiamondY(DiamondBase):
+        y_id = models.AutoField(primary_key=True)
+        field_y = models.CharField(max_length=10)
+    class DiamondXY(DiamondX, DiamondY):
+        xy_id = models.AutoField(primary_key=True)
 
 class RelationBase(ShowFieldTypeAndContent, PolymorphicModel):
     field_base = models.CharField(max_length=10)
@@ -110,6 +135,9 @@
 class MyManager(PolymorphicManager):
     queryset_class = MyManagerQuerySet
 
+    def get_queryset(self):
+        return super(MyManager, self).get_queryset().order_by('-field1')
+
     def get_query_set(self):
         return super(MyManager, self).get_query_set().order_by('-field1')
 
@@ -143,9 +171,12 @@
     def my_queryset_foo(self):
         return self.get_query_set().my_queryset_foo()
 
-    def get_query_set(self):
+    def get_queryset(self):
         return PlainMyManagerQuerySet(self.model, using=self._db)
 
+    def get_query_set(self):
+        return self.get_queryset()
+
 class PlainParentModelWithManager(models.Model):
     pass
 
@@ -254,6 +285,10 @@
     The test suite
     """
     def test_diamond_inheritance(self):
+        if django.VERSION[:2] > (1, 6):
+            print('')
+            print("# Django 1.7 doesn't allow multiple inheritance when two id fields exist. https://docs.djangoproject.com/en/dev/topics/db/models/#multiple-inheritance")
+
         # Django diamond problem
         # https://code.djangoproject.com/ticket/10808
         o1 = DiamondXY.objects.create(field_b='b', field_x='x', field_y='y')
@@ -616,11 +651,14 @@
         Enhance_Inherit.objects.create(field_b='b-inherit', field_p='p', field_i='i')
 
         qs = Enhance_Base.objects.all()
-        self.assertEqual(repr(qs[0]), '<Enhance_Base: id 1, field_b (CharField) "b-base">')
-        self.assertEqual(repr(qs[1]), '<Enhance_Inherit: id 2, field_b (CharField) "b-inherit", field_p (CharField) "p", field_i (CharField) "i">')
+        if django.VERSION[:2] > (1, 6):
+            self.assertEqual(repr(qs[0]), '<Enhance_Base: base_id (AutoField/pk) 1, field_b (CharField) "b-base">')
+            self.assertEqual(repr(qs[1]), '<Enhance_Inherit: base_id (AutoField/pk) 2, field_b (CharField) "b-inherit", id 1, field_p (CharField) "p", field_i (CharField) "i">')
+        else:
+            self.assertEqual(repr(qs[0]), '<Enhance_Base: id 1, field_b (CharField) "b-base">')
+            self.assertEqual(repr(qs[1]), '<Enhance_Inherit: id 2, field_b (CharField) "b-inherit", field_p (CharField) "p", field_i (CharField) "i">')
         self.assertEqual(len(qs), 2)
 
-
     def test_relation_base(self):
         # ForeignKey, ManyToManyField
         obase = RelationBase.objects.create(field_base='base')
--- a/docs/managers.rst
+++ b/docs/managers.rst
@@ -13,12 +13,12 @@
     from polymorphic import PolymorphicModel, PolymorphicManager
 
    class TimeOrderedManager(PolymorphicManager):
-        def get_query_set(self):
-            qs = super(TimeOrderedManager,self).get_query_set()
+        def get_queryset(self):
+            qs = super(TimeOrderedManager,self).get_queryset()
             return qs.order_by('-start_date')        # order the queryset
 
         def most_recent(self):
-            qs = self.get_query_set()                # get my ordered queryset
+            qs = self.get_queryset()                # get my ordered queryset
             return qs[:10]                           # limit => get ten most recent entries
 
     class Project(PolymorphicModel):
@@ -31,6 +31,8 @@
 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
 -------------------
 
@@ -42,12 +44,12 @@
    from polymorphic import PolymorphicModel, PolymorphicManager
 
    class TimeOrderedManager(PolymorphicManager):
-        def get_query_set(self):
-            qs = super(TimeOrderedManager,self).get_query_set()
+        def get_queryset(self):
+            qs = super(TimeOrderedManager,self).get_queryset()
             return qs.order_by('-start_date')        # order the queryset
 
         def most_recent(self):
-            qs = self.get_query_set()                # get my ordered queryset
+            qs = self.get_queryset()                # get my ordered queryset
             return qs[:10]                           # limit => get ten most recent entries
 
     class Project(PolymorphicModel):
@@ -65,6 +67,8 @@
 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
 -----------------------------
 
--- a/tox.ini
+++ b/tox.ini
@@ -7,12 +7,15 @@
     py27-django14,
     py27-django15,
     py27-django16,
+    py27-django17,
 
     py32-django15,
     py32-django16,
+    py32-django17,
 
     py33-django15,
     py33-django16,
+    py33-django17,
 
     py33-django-dev,
     docs,
@@ -53,6 +56,11 @@
 deps=
     django==1.6
 
+[testenv:py27-django17]
+basepython=python2.7
+deps=
+    django==1.7
+
 [testenv:py32-django15]
 basepython=python3.2
 deps=
@@ -63,6 +71,11 @@
 deps=
     django==1.6
 
+[testenv:py32-django17]
+basepython=python3.2
+deps=
+    django==1.7
+
 [testenv:py33-django15]
 basepython=python3.3
 deps=
@@ -73,6 +86,11 @@
 deps=
     django==1.6
 
+[testenv:py33-django17]
+basepython=python3.3
+deps=
+    django==1.7
+
 [testenv:py33-django-dev]
 basepython=python3.3
 deps=
--- a/.travis.yml
+++ b/.travis.yml
@@ -8,6 +8,7 @@
   - DJANGO=django==1.4.5
   - DJANGO=django==1.5
   - DJANGO=django==1.6
+  - DJANGO=django==1.7
   #- DJANGO=https://github.com/django/django/archive/stable/1.6.x.zip
 
 matrix:
@@ -16,6 +17,8 @@
     env: DJANGO=django==1.4.5
   - python: "3.2"
     env: DJANGO=django==1.4.5
+  - python: "2.6"
+    env: DJANGO=django==1.7
 
 install:
   - pip install $DJANGO coverage==3.6