diff --git a/django/contrib/admin/checks.py b/django/contrib/admin/checks.py
index 48539fe..62c3710 100644
|
a
|
b
|
def check_dependencies(**kwargs):
|
| 58 | 58 | "'django.contrib.auth.context_processors.auth' must be in " |
| 59 | 59 | "TEMPLATES in order to use the admin application.", |
| 60 | 60 | id="admin.E402" |
| 61 | | ) |
| | 61 | ) |
| 62 | 62 | errors.append(missing_template) |
| 63 | 63 | return errors |
| 64 | 64 | |
diff --git a/django/contrib/flatpages/forms.py b/django/contrib/flatpages/forms.py
index b990fa3..19f3b63 100644
|
a
|
b
|
from django.utils.translation import ugettext, ugettext_lazy as _
|
| 5 | 5 | |
| 6 | 6 | |
| 7 | 7 | class FlatpageForm(forms.ModelForm): |
| 8 | | url = forms.RegexField(label=_("URL"), max_length=100, regex=r'^[-\w/\.~]+$', |
| 9 | | help_text=_("Example: '/about/contact/'. Make sure to have leading" |
| 10 | | " and trailing slashes."), |
| | 8 | url = forms.RegexField( |
| | 9 | label=_("URL"), |
| | 10 | max_length=100, |
| | 11 | regex=r'^[-\w/\.~]+$', |
| | 12 | help_text=_("Example: '/about/contact/'. Make sure to have leading and trailing slashes."), |
| 11 | 13 | error_messages={ |
| 12 | | "invalid": _("This value must contain only letters, numbers," |
| 13 | | " dots, underscores, dashes, slashes or tildes."), |
| | 14 | "invalid": _( |
| | 15 | "This value must contain only letters, numbers, dots, " |
| | 16 | "underscores, dashes, slashes or tildes." |
| | 17 | ), |
| 14 | 18 | }, |
| 15 | 19 | ) |
| 16 | 20 | |
diff --git a/django/contrib/flatpages/models.py b/django/contrib/flatpages/models.py
index 67e1a30..b3cad73 100644
|
a
|
b
|
class FlatPage(models.Model):
|
| 13 | 13 | title = models.CharField(_('title'), max_length=200) |
| 14 | 14 | content = models.TextField(_('content'), blank=True) |
| 15 | 15 | enable_comments = models.BooleanField(_('enable comments'), default=False) |
| 16 | | template_name = models.CharField(_('template name'), max_length=70, blank=True, |
| | 16 | template_name = models.CharField( |
| | 17 | _('template name'), |
| | 18 | max_length=70, |
| | 19 | blank=True, |
| 17 | 20 | help_text=_( |
| 18 | 21 | "Example: 'flatpages/contact_page.html'. If this isn't provided, " |
| 19 | 22 | "the system will use 'flatpages/default.html'." |
diff --git a/django/contrib/gis/gdal/prototypes/raster.py b/django/contrib/gis/gdal/prototypes/raster.py
index 4058e19..8b3c350 100644
|
a
|
b
|
get_band_ds = voidptr_output(std_call('GDALGetBandDataset'), [c_void_p])
|
| 62 | 62 | get_band_datatype = int_output(std_call('GDALGetRasterDataType'), [c_void_p]) |
| 63 | 63 | get_band_nodata_value = double_output(std_call('GDALGetRasterNoDataValue'), [c_void_p, POINTER(c_int)]) |
| 64 | 64 | set_band_nodata_value = void_output(std_call('GDALSetRasterNoDataValue'), [c_void_p, c_double]) |
| 65 | | get_band_statistics = void_output(std_call('GDALGetRasterStatistics'), |
| | 65 | get_band_statistics = void_output( |
| | 66 | std_call('GDALGetRasterStatistics'), |
| 66 | 67 | [ |
| 67 | 68 | c_void_p, c_int, c_int, POINTER(c_double), POINTER(c_double), |
| 68 | 69 | POINTER(c_double), POINTER(c_double), c_void_p, c_void_p, |
diff --git a/django/views/generic/dates.py b/django/views/generic/dates.py
index d403db8..52b3b39 100644
|
a
|
b
|
class BaseDateDetailView(YearMixin, MonthMixin, DayMixin, DateMixin, BaseDetailV
|
| 658 | 658 | if not self.get_allow_future() and date > datetime.date.today(): |
| 659 | 659 | raise Http404(_( |
| 660 | 660 | "Future %(verbose_name_plural)s not available because " |
| 661 | | "%(class_name)s.allow_future is False.") % { |
| | 661 | "%(class_name)s.allow_future is False." |
| | 662 | ) % { |
| 662 | 663 | 'verbose_name_plural': qs.model._meta.verbose_name_plural, |
| 663 | 664 | 'class_name': self.__class__.__name__, |
| 664 | | }, |
| 665 | | ) |
| | 665 | }) |
| 666 | 666 | |
| 667 | 667 | # Filter down a queryset from self.queryset using the date from the |
| 668 | 668 | # URL. This'll get passed as the queryset to DetailView.get_object, |
diff --git a/setup.cfg b/setup.cfg
index 8579282..f6ab266 100644
|
a
|
b
|
install-script = scripts/rpm-install.sh
|
| 4 | 4 | |
| 5 | 5 | [flake8] |
| 6 | 6 | exclude = build,.git,./django/utils/lru_cache.py,./django/utils/six.py,./django/conf/app_template/*,./django/dispatch/weakref_backports.py,./tests/.env,./xmlrunner,tests/view_tests/tests/py3_test_debug.py,tests/template_tests/annotated_tag_function.py |
| 7 | | ignore = E123,E128,E402,W503,W601 |
| | 7 | ignore = E128,E402,W503,W601 |
| 8 | 8 | max-line-length = 119 |
| 9 | 9 | |
| 10 | 10 | [isort] |
diff --git a/tests/many_to_one/tests.py b/tests/many_to_one/tests.py
index b3028e0..52ea5d9 100644
|
a
|
b
|
class ManyToOneTests(TestCase):
|
| 64 | 64 | |
| 65 | 65 | self.r.article_set.add(new_article2, bulk=False) |
| 66 | 66 | self.assertEqual(new_article2.reporter.id, self.r.id) |
| 67 | | self.assertQuerysetEqual(self.r.article_set.all(), |
| 68 | | [ |
| 69 | | "<Article: John's second story>", |
| 70 | | "<Article: Paul's story>", |
| 71 | | "<Article: This is a test>", |
| 72 | | ]) |
| | 67 | self.assertQuerysetEqual( |
| | 68 | self.r.article_set.all(), |
| | 69 | ["<Article: John's second story>", "<Article: Paul's story>", "<Article: This is a test>"] |
| | 70 | ) |
| 73 | 71 | |
| 74 | 72 | # Add the same article to a different article set - check that it moves. |
| 75 | 73 | self.r2.article_set.add(new_article2) |
| … |
… |
class ManyToOneTests(TestCase):
|
| 81 | 79 | with six.assertRaisesRegex(self, TypeError, |
| 82 | 80 | "'Article' instance expected, got <Reporter.*"): |
| 83 | 81 | self.r.article_set.add(self.r2) |
| 84 | | self.assertQuerysetEqual(self.r.article_set.all(), |
| 85 | | [ |
| 86 | | "<Article: John's second story>", |
| 87 | | "<Article: This is a test>", |
| 88 | | ]) |
| | 82 | self.assertQuerysetEqual( |
| | 83 | self.r.article_set.all(), |
| | 84 | ["<Article: John's second story>", "<Article: This is a test>"] |
| | 85 | ) |
| 89 | 86 | |
| 90 | 87 | def test_set(self): |
| 91 | | new_article = self.r.article_set.create(headline="John's second story", |
| 92 | | pub_date=datetime.date(2005, 7, 29)) |
| 93 | | new_article2 = self.r2.article_set.create(headline="Paul's story", |
| 94 | | pub_date=datetime.date(2006, 1, 17)) |
| | 88 | new_article = self.r.article_set.create(headline="John's second story", pub_date=datetime.date(2005, 7, 29)) |
| | 89 | new_article2 = self.r2.article_set.create(headline="Paul's story", pub_date=datetime.date(2006, 1, 17)) |
| 95 | 90 | |
| 96 | 91 | # Assign the article to the reporter. |
| 97 | 92 | new_article2.reporter = self.r |
| … |
… |
class ManyToOneTests(TestCase):
|
| 108 | 103 | # Set the article back again. |
| 109 | 104 | self.r2.article_set.set([new_article, new_article2]) |
| 110 | 105 | self.assertQuerysetEqual(self.r.article_set.all(), ["<Article: This is a test>"]) |
| 111 | | self.assertQuerysetEqual(self.r2.article_set.all(), |
| 112 | | [ |
| 113 | | "<Article: John's second story>", |
| 114 | | "<Article: Paul's story>", |
| 115 | | ]) |
| | 106 | self.assertQuerysetEqual( |
| | 107 | self.r2.article_set.all(), |
| | 108 | ["<Article: John's second story>", "<Article: Paul's story>"] |
| | 109 | ) |
| 116 | 110 | |
| 117 | 111 | # Funny case - because the ForeignKey cannot be null, |
| 118 | 112 | # existing members of the set must remain. |
| 119 | 113 | self.r.article_set.set([new_article]) |
| 120 | | self.assertQuerysetEqual(self.r.article_set.all(), |
| 121 | | [ |
| 122 | | "<Article: John's second story>", |
| 123 | | "<Article: This is a test>", |
| 124 | | ]) |
| | 114 | self.assertQuerysetEqual( |
| | 115 | self.r.article_set.all(), |
| | 116 | ["<Article: John's second story>", "<Article: This is a test>"] |
| | 117 | ) |
| 125 | 118 | self.assertQuerysetEqual(self.r2.article_set.all(), ["<Article: Paul's story>"]) |
| 126 | 119 | |
| 127 | 120 | def test_reverse_assignment_deprecation(self): |
| … |
… |
class ManyToOneTests(TestCase):
|
| 134 | 127 | self.r2.article_set = [] |
| 135 | 128 | |
| 136 | 129 | def test_assign(self): |
| 137 | | new_article = self.r.article_set.create(headline="John's second story", |
| 138 | | pub_date=datetime.date(2005, 7, 29)) |
| 139 | | new_article2 = self.r2.article_set.create(headline="Paul's story", |
| 140 | | pub_date=datetime.date(2006, 1, 17)) |
| | 130 | new_article = self.r.article_set.create(headline="John's second story", pub_date=datetime.date(2005, 7, 29)) |
| | 131 | new_article2 = self.r2.article_set.create(headline="Paul's story", pub_date=datetime.date(2006, 1, 17)) |
| 141 | 132 | |
| 142 | 133 | # Assign the article to the reporter directly using the descriptor. |
| 143 | 134 | new_article2.reporter = self.r |
| … |
… |
class ManyToOneTests(TestCase):
|
| 154 | 145 | # Set the article back again using set() method. |
| 155 | 146 | self.r2.article_set.set([new_article, new_article2]) |
| 156 | 147 | self.assertQuerysetEqual(self.r.article_set.all(), ["<Article: This is a test>"]) |
| 157 | | self.assertQuerysetEqual(self.r2.article_set.all(), |
| 158 | | [ |
| 159 | | "<Article: John's second story>", |
| 160 | | "<Article: Paul's story>", |
| 161 | | ]) |
| | 148 | self.assertQuerysetEqual( |
| | 149 | self.r2.article_set.all(), |
| | 150 | ["<Article: John's second story>", "<Article: Paul's story>"] |
| | 151 | ) |
| 162 | 152 | |
| 163 | 153 | # Because the ForeignKey cannot be null, existing members of the set |
| 164 | 154 | # must remain. |
| 165 | 155 | self.r.article_set.set([new_article]) |
| 166 | | self.assertQuerysetEqual(self.r.article_set.all(), |
| 167 | | [ |
| 168 | | "<Article: John's second story>", |
| 169 | | "<Article: This is a test>", |
| 170 | | ]) |
| | 156 | self.assertQuerysetEqual( |
| | 157 | self.r.article_set.all(), |
| | 158 | ["<Article: John's second story>", "<Article: This is a test>"] |
| | 159 | ) |
| 171 | 160 | self.assertQuerysetEqual(self.r2.article_set.all(), ["<Article: Paul's story>"]) |
| 172 | 161 | # Reporter cannot be null - there should not be a clear or remove method |
| 173 | 162 | self.assertFalse(hasattr(self.r2.article_set, 'remove')) |
| 174 | 163 | self.assertFalse(hasattr(self.r2.article_set, 'clear')) |
| 175 | 164 | |
| 176 | 165 | def test_selects(self): |
| 177 | | self.r.article_set.create(headline="John's second story", |
| 178 | | pub_date=datetime.date(2005, 7, 29)) |
| 179 | | self.r2.article_set.create(headline="Paul's story", |
| 180 | | pub_date=datetime.date(2006, 1, 17)) |
| | 166 | self.r.article_set.create(headline="John's second story", pub_date=datetime.date(2005, 7, 29)) |
| | 167 | self.r2.article_set.create(headline="Paul's story", pub_date=datetime.date(2006, 1, 17)) |
| 181 | 168 | # Reporter objects have access to their related Article objects. |
| 182 | 169 | self.assertQuerysetEqual(self.r.article_set.all(), [ |
| 183 | 170 | "<Article: John's second story>", |
| … |
… |
class ManyToOneTests(TestCase):
|
| 199 | 186 | # Use double underscores to separate relationships. |
| 200 | 187 | # This works as many levels deep as you want. There's no limit. |
| 201 | 188 | # Find all Articles for any Reporter whose first name is "John". |
| 202 | | self.assertQuerysetEqual(Article.objects.filter(reporter__first_name__exact='John'), |
| 203 | | [ |
| 204 | | "<Article: John's second story>", |
| 205 | | "<Article: This is a test>", |
| 206 | | ]) |
| | 189 | self.assertQuerysetEqual( |
| | 190 | Article.objects.filter(reporter__first_name__exact='John'), |
| | 191 | ["<Article: John's second story>", "<Article: This is a test>"] |
| | 192 | ) |
| 207 | 193 | # Check that implied __exact also works |
| 208 | | self.assertQuerysetEqual(Article.objects.filter(reporter__first_name='John'), |
| 209 | | [ |
| 210 | | "<Article: John's second story>", |
| 211 | | "<Article: This is a test>", |
| 212 | | ]) |
| | 194 | self.assertQuerysetEqual( |
| | 195 | Article.objects.filter(reporter__first_name='John'), |
| | 196 | ["<Article: John's second story>", "<Article: This is a test>"] |
| | 197 | ) |
| 213 | 198 | # Query twice over the related field. |
| 214 | 199 | self.assertQuerysetEqual( |
| 215 | | Article.objects.filter(reporter__first_name__exact='John', |
| 216 | | reporter__last_name__exact='Smith'), |
| 217 | | [ |
| 218 | | "<Article: John's second story>", |
| 219 | | "<Article: This is a test>", |
| 220 | | ]) |
| | 200 | Article.objects.filter(reporter__first_name__exact='John', reporter__last_name__exact='Smith'), |
| | 201 | ["<Article: John's second story>", "<Article: This is a test>"] |
| | 202 | ) |
| 221 | 203 | # The underlying query only makes one join when a related table is referenced twice. |
| 222 | | queryset = Article.objects.filter(reporter__first_name__exact='John', |
| 223 | | reporter__last_name__exact='Smith') |
| | 204 | queryset = Article.objects.filter(reporter__first_name__exact='John', reporter__last_name__exact='Smith') |
| 224 | 205 | self.assertNumQueries(1, list, queryset) |
| 225 | 206 | self.assertEqual(queryset.query.get_compiler(queryset.db).as_sql()[0].count('INNER JOIN'), 1) |
| 226 | 207 | |
| … |
… |
class ManyToOneTests(TestCase):
|
| 228 | 209 | self.assertQuerysetEqual( |
| 229 | 210 | Article.objects.filter(reporter__first_name__exact='John').extra( |
| 230 | 211 | where=["many_to_one_reporter.last_name='Smith'"]), |
| 231 | | [ |
| 232 | | "<Article: John's second story>", |
| 233 | | "<Article: This is a test>", |
| 234 | | ]) |
| | 212 | ["<Article: John's second story>", "<Article: This is a test>"] |
| | 213 | ) |
| 235 | 214 | # ... and should work fine with the unicode that comes out of forms.Form.cleaned_data |
| 236 | 215 | self.assertQuerysetEqual( |
| 237 | 216 | (Article.objects |
| 238 | 217 | .filter(reporter__first_name__exact='John') |
| 239 | 218 | .extra(where=["many_to_one_reporter.last_name='%s'" % 'Smith'])), |
| 240 | | [ |
| 241 | | "<Article: John's second story>", |
| 242 | | "<Article: This is a test>", |
| 243 | | ]) |
| | 219 | ["<Article: John's second story>", "<Article: This is a test>"] |
| | 220 | ) |
| 244 | 221 | # Find all Articles for a Reporter. |
| 245 | 222 | # Use direct ID check, pk check, and object comparison |
| 246 | 223 | self.assertQuerysetEqual( |
| … |
… |
class ManyToOneTests(TestCase):
|
| 376 | 353 | r2 = Reporter.objects.create(first_name='John', last_name='Kass', email='jkass@tribune.com') |
| 377 | 354 | Article.objects.create(headline='First', pub_date=datetime.date(1980, 4, 23), reporter=r1) |
| 378 | 355 | Article.objects.create(headline='Second', pub_date=datetime.date(1980, 4, 23), reporter=r2) |
| 379 | | self.assertEqual(list(Article.objects.select_related().dates('pub_date', 'day')), |
| 380 | | [ |
| 381 | | datetime.date(1980, 4, 23), |
| 382 | | datetime.date(2005, 7, 27), |
| 383 | | ]) |
| | 356 | self.assertEqual( |
| | 357 | list(Article.objects.select_related().dates('pub_date', 'day')), |
| | 358 | [datetime.date(1980, 4, 23), datetime.date(2005, 7, 27)] |
| | 359 | ) |
| 384 | 360 | self.assertEqual(list(Article.objects.select_related().dates('pub_date', 'month')), |
| 385 | | [ |
| 386 | | datetime.date(1980, 4, 1), |
| 387 | | datetime.date(2005, 7, 1), |
| 388 | | ]) |
| | 361 | [datetime.date(1980, 4, 1), datetime.date(2005, 7, 1)] |
| | 362 | ) |
| 389 | 363 | self.assertEqual(list(Article.objects.select_related().dates('pub_date', 'year')), |
| 390 | | [ |
| 391 | | datetime.date(1980, 1, 1), |
| 392 | | datetime.date(2005, 1, 1), |
| 393 | | ]) |
| | 364 | [datetime.date(1980, 1, 1), datetime.date(2005, 1, 1)] |
| | 365 | ) |
| 394 | 366 | |
| 395 | 367 | def test_delete(self): |
| 396 | 368 | self.r.article_set.create(headline="John's second story", |
| … |
… |
class ManyToOneTests(TestCase):
|
| 402 | 374 | Article.objects.create(id=None, headline="Fourth article", |
| 403 | 375 | pub_date=datetime.date(2005, 7, 27), reporter_id=str(self.r.id)) |
| 404 | 376 | # If you delete a reporter, his articles will be deleted. |
| 405 | | self.assertQuerysetEqual(Article.objects.all(), |
| | 377 | self.assertQuerysetEqual( |
| | 378 | Article.objects.all(), |
| 406 | 379 | [ |
| 407 | 380 | "<Article: Fourth article>", |
| 408 | 381 | "<Article: John's second story>", |
| 409 | 382 | "<Article: Paul's story>", |
| 410 | 383 | "<Article: Third article>", |
| 411 | 384 | "<Article: This is a test>", |
| 412 | | ]) |
| 413 | | self.assertQuerysetEqual(Reporter.objects.order_by('first_name'), |
| 414 | | [ |
| 415 | | "<Reporter: John Smith>", |
| 416 | | "<Reporter: Paul Jones>", |
| 417 | | ]) |
| | 385 | ] |
| | 386 | ) |
| | 387 | self.assertQuerysetEqual( |
| | 388 | Reporter.objects.order_by('first_name'), |
| | 389 | ["<Reporter: John Smith>", "<Reporter: Paul Jones>"] |
| | 390 | ) |
| 418 | 391 | self.r2.delete() |
| 419 | | self.assertQuerysetEqual(Article.objects.all(), |
| | 392 | self.assertQuerysetEqual( |
| | 393 | Article.objects.all(), |
| 420 | 394 | [ |
| 421 | 395 | "<Article: Fourth article>", |
| 422 | 396 | "<Article: John's second story>", |
| 423 | 397 | "<Article: Third article>", |
| 424 | 398 | "<Article: This is a test>", |
| 425 | | ]) |
| | 399 | ] |
| | 400 | ) |
| 426 | 401 | self.assertQuerysetEqual(Reporter.objects.order_by('first_name'), |
| 427 | 402 | ["<Reporter: John Smith>"]) |
| 428 | 403 | # You can delete using a JOIN in the query. |
| … |
… |
class ManyToOneTests(TestCase):
|
| 443 | 418 | # You can specify filters containing the explicit FK value. |
| 444 | 419 | self.assertQuerysetEqual( |
| 445 | 420 | Article.objects.filter(reporter_id__exact=self.r.id), |
| 446 | | [ |
| 447 | | "<Article: John's second test>", |
| 448 | | "<Article: This is a test>", |
| 449 | | ]) |
| | 421 | ["<Article: John's second test>", "<Article: This is a test>"] |
| | 422 | ) |
| 450 | 423 | |
| 451 | 424 | # Create an Article by Paul for the same date. |
| 452 | 425 | a3 = Article.objects.create(id=None, headline="Paul's commentary", |