Ticket #15272: patch.diff
File patch.diff, 17.1 KB (added by , 14 years ago) |
---|
-
django/views/generic/date_based.py
34 34 queryset = queryset.filter(**{'%s__lte' % date_field: datetime.datetime.now()}) 35 35 date_list = queryset.dates(date_field, 'year')[::-1] 36 36 if not date_list and not allow_empty: 37 raise Http404("No %s available" % model._meta. verbose_name)37 raise Http404("No %s available" % model._meta.object_name) 38 38 39 39 if date_list and num_latest: 40 40 latest = queryset.order_by('-'+date_field)[:num_latest] … … 354 354 try: 355 355 obj = queryset.get(**lookup_kwargs) 356 356 except ObjectDoesNotExist: 357 raise Http404("No %s found for" % model._meta. verbose_name)357 raise Http404("No %s found for" % model._meta.object_name) 358 358 if not template_name: 359 359 template_name = "%s/%s_detail.html" % (model._meta.app_label, model._meta.object_name.lower()) 360 360 if template_name_field: -
django/views/generic/list.py
76 76 if self.context_object_name: 77 77 return self.context_object_name 78 78 elif hasattr(object_list, 'model'): 79 return smart_str(re.sub('[^a-zA-Z0-9]+', '_', 80 object_list.model._meta.verbose_name_plural.lower())) 79 return smart_str('%s_list' % object_list.model._meta.object_name.lower()) 81 80 else: 82 81 return None 83 82 -
django/views/generic/list_detail.py
131 131 try: 132 132 obj = queryset.get() 133 133 except ObjectDoesNotExist: 134 raise Http404("No %s found matching the query" % (model._meta. verbose_name))134 raise Http404("No %s found matching the query" % (model._meta.object_name)) 135 135 if not template_name: 136 136 template_name = "%s/%s_detail.html" % (model._meta.app_label, model._meta.object_name.lower()) 137 137 if template_name_field: -
django/views/generic/dates.py
194 194 qs = qs.filter(**{'%s__lte' % date_field: datetime.datetime.now()}) 195 195 196 196 if not allow_empty and not qs: 197 raise Http404(u"No %s available" % unicode(qs.model._meta.verbose_name_plural))197 raise Http404(u"No %s list available" % unicode(qs.model._meta.object_name)) 198 198 199 199 return qs 200 200 … … 208 208 209 209 date_list = queryset.dates(date_field, date_type)[::-1] 210 210 if date_list is not None and not date_list and not allow_empty: 211 raise Http404(u"No %s available" % unicode(qs.model._meta.verbose_name_plural))211 raise Http404(u"No %s list available" % unicode(qs.model._meta.object_name)) 212 212 213 213 return date_list 214 214 … … 458 458 qs = self.get_queryset() 459 459 460 460 if not self.get_allow_future() and date > datetime.date.today(): 461 raise Http404("Future %s not available because %s.allow_future is False." % (462 qs.model._meta. verbose_name_plural, self.__class__.__name__)461 raise Http404("Future %s list is not available because %s.allow_future is False." % ( 462 qs.model._meta.object_name, self.__class__.__name__) 463 463 ) 464 464 465 465 # Filter down a queryset from self.queryset using the date from the -
django/views/generic/detail.py
48 48 obj = queryset.get() 49 49 except ObjectDoesNotExist: 50 50 raise Http404(u"No %s found matching the query" % 51 (queryset.model._meta. verbose_name))51 (queryset.model._meta.object_name)) 52 52 return obj 53 53 54 54 def get_queryset(self): … … 80 80 if self.context_object_name: 81 81 return self.context_object_name 82 82 elif hasattr(obj, '_meta'): 83 return smart_str(re.sub('[^a-zA-Z0-9]+', '_', 84 obj._meta.verbose_name.lower())) 83 return smart_str(obj._meta.object_name.lower()) 85 84 else: 86 85 return None 87 86 -
django/views/generic/create_update.py
95 95 return model.objects.get(**lookup_kwargs) 96 96 except ObjectDoesNotExist: 97 97 raise Http404("No %s found for %s" 98 % (model._meta. verbose_name, lookup_kwargs))98 % (model._meta.object_name, lookup_kwargs)) 99 99 100 100 def create_object(request, model=None, template_name=None, 101 101 template_loader=loader, extra_context=None, post_save_redirect=None, -
tests/regressiontests/generic_views/list.py
19 19 self.assertEqual(res.status_code, 200) 20 20 self.assertTemplateUsed(res, 'generic_views/author_list.html') 21 21 self.assertEqual(list(res.context['object_list']), list(Author.objects.all())) 22 self.assertIs(res.context['author s'], res.context['object_list'])22 self.assertIs(res.context['author_list'], res.context['object_list']) 23 23 self.assertIsNone(res.context['paginator']) 24 24 self.assertIsNone(res.context['page_obj']) 25 25 self.assertFalse(res.context['is_paginated']) … … 30 30 self.assertEqual(res.status_code, 200) 31 31 self.assertTemplateUsed(res, 'generic_views/author_list.html') 32 32 self.assertEqual(len(res.context['object_list']), 30) 33 self.assertIs(res.context['author s'], res.context['object_list'])33 self.assertIs(res.context['author_list'], res.context['object_list']) 34 34 self.assertTrue(res.context['is_paginated']) 35 35 self.assertEqual(res.context['page_obj'].number, 1) 36 36 self.assertEqual(res.context['paginator'].num_pages, 4) 37 self.assertEqual(res.context['author s'][0].name, 'Author 00')38 self.assertEqual(list(res.context['author s'])[-1].name, 'Author 29')37 self.assertEqual(res.context['author_list'][0].name, 'Author 00') 38 self.assertEqual(list(res.context['author_list'])[-1].name, 'Author 29') 39 39 40 40 def test_paginated_queryset_shortdata(self): 41 41 # Test that short datasets ALSO result in a paginated view. … … 43 43 self.assertEqual(res.status_code, 200) 44 44 self.assertTemplateUsed(res, 'generic_views/author_list.html') 45 45 self.assertEqual(list(res.context['object_list']), list(Author.objects.all())) 46 self.assertIs(res.context['author s'], res.context['object_list'])46 self.assertIs(res.context['author_list'], res.context['object_list']) 47 47 self.assertEqual(res.context['page_obj'].number, 1) 48 48 self.assertEqual(res.context['paginator'].num_pages, 1) 49 49 self.assertTrue(res.context['is_paginated']) … … 54 54 self.assertEqual(res.status_code, 200) 55 55 self.assertTemplateUsed(res, 'generic_views/author_list.html') 56 56 self.assertEqual(len(res.context['object_list']), 30) 57 self.assertIs(res.context['author s'], res.context['object_list'])58 self.assertEqual(res.context['author s'][0].name, 'Author 30')57 self.assertIs(res.context['author_list'], res.context['object_list']) 58 self.assertEqual(res.context['author_list'][0].name, 'Author 30') 59 59 self.assertEqual(res.context['page_obj'].number, 2) 60 60 61 61 def test_paginated_get_last_page_by_query_string(self): … … 63 63 res = self.client.get('/list/authors/paginated/', {'page': 'last'}) 64 64 self.assertEqual(res.status_code, 200) 65 65 self.assertEqual(len(res.context['object_list']), 10) 66 self.assertIs(res.context['author s'], res.context['object_list'])67 self.assertEqual(res.context['author s'][0].name, 'Author 90')66 self.assertIs(res.context['author_list'], res.context['object_list']) 67 self.assertEqual(res.context['author_list'][0].name, 'Author 90') 68 68 self.assertEqual(res.context['page_obj'].number, 4) 69 69 70 70 def test_paginated_get_page_by_urlvar(self): … … 73 73 self.assertEqual(res.status_code, 200) 74 74 self.assertTemplateUsed(res, 'generic_views/author_list.html') 75 75 self.assertEqual(len(res.context['object_list']), 30) 76 self.assertIs(res.context['author s'], res.context['object_list'])77 self.assertEqual(res.context['author s'][0].name, 'Author 60')76 self.assertIs(res.context['author_list'], res.context['object_list']) 77 self.assertEqual(res.context['author_list'][0].name, 'Author 60') 78 78 self.assertEqual(res.context['page_obj'].number, 3) 79 79 80 80 def test_paginated_page_out_of_range(self): … … 112 112 self.assertEqual(res.status_code, 200) 113 113 self.assertTemplateUsed(res, 'generic_views/list.html') 114 114 self.assertEqual(list(res.context['object_list']), list(Artist.objects.all())) 115 self.assertIs(res.context[' professional_artists'], res.context['object_list'])115 self.assertIs(res.context['artist_list'], res.context['object_list']) 116 116 self.assertIsNone(res.context['paginator']) 117 117 self.assertIsNone(res.context['page_obj']) 118 118 self.assertFalse(res.context['is_paginated']) … … 128 128 res = self.client.get('/list/authors/template_name/') 129 129 self.assertEqual(res.status_code, 200) 130 130 self.assertEqual(list(res.context['object_list']), list(Author.objects.all())) 131 self.assertIs(res.context['author s'], res.context['object_list'])131 self.assertIs(res.context['author_list'], res.context['object_list']) 132 132 self.assertTemplateUsed(res, 'generic_views/list.html') 133 133 134 134 def test_template_name_suffix(self): 135 135 res = self.client.get('/list/authors/template_name_suffix/') 136 136 self.assertEqual(res.status_code, 200) 137 137 self.assertEqual(list(res.context['object_list']), list(Author.objects.all())) 138 self.assertIs(res.context['author s'], res.context['object_list'])138 self.assertIs(res.context['author_list'], res.context['object_list']) 139 139 self.assertTemplateUsed(res, 'generic_views/author_objects.html') 140 140 141 141 def test_context_object_name(self): -
tests/regressiontests/generic_views/dates.py
92 92 res = self.client.get('/dates/books/2006/make_object_list/') 93 93 self.assertEqual(res.status_code, 200) 94 94 self.assertEqual(list(res.context['date_list']), [datetime.datetime(2006, 5, 1)]) 95 self.assertEqual(list(res.context['book s']), list(Book.objects.filter(pubdate__year=2006)))95 self.assertEqual(list(res.context['book_list']), list(Book.objects.filter(pubdate__year=2006))) 96 96 self.assertEqual(list(res.context['object_list']), list(Book.objects.filter(pubdate__year=2006))) 97 97 self.assertTemplateUsed(res, 'generic_views/book_archive_year.html') 98 98 … … 102 102 res = self.client.get('/dates/books/1999/allow_empty/') 103 103 self.assertEqual(res.status_code, 200) 104 104 self.assertEqual(list(res.context['date_list']), []) 105 self.assertEqual(list(res.context['book s']), [])105 self.assertEqual(list(res.context['book_list']), []) 106 106 107 107 def test_year_view_allow_future(self): 108 108 # Create a new book in the future … … 113 113 114 114 res = self.client.get('/dates/books/%s/allow_empty/' % year) 115 115 self.assertEqual(res.status_code, 200) 116 self.assertEqual(list(res.context['book s']), [])116 self.assertEqual(list(res.context['book_list']), []) 117 117 118 118 res = self.client.get('/dates/books/%s/allow_future/' % year) 119 119 self.assertEqual(res.status_code, 200) … … 132 132 self.assertEqual(res.status_code, 200) 133 133 self.assertTemplateUsed(res, 'generic_views/book_archive_month.html') 134 134 self.assertEqual(list(res.context['date_list']), [datetime.datetime(2008, 10, 1)]) 135 self.assertEqual(list(res.context['book s']),135 self.assertEqual(list(res.context['book_list']), 136 136 list(Book.objects.filter(pubdate=datetime.date(2008, 10, 1)))) 137 137 self.assertEqual(res.context['month'], datetime.date(2008, 10, 1)) 138 138 … … 149 149 res = self.client.get('/dates/books/2000/jan/allow_empty/') 150 150 self.assertEqual(res.status_code, 200) 151 151 self.assertEqual(list(res.context['date_list']), []) 152 self.assertEqual(list(res.context['book s']), [])152 self.assertEqual(list(res.context['book_list']), []) 153 153 self.assertEqual(res.context['month'], datetime.date(2000, 1, 1)) 154 154 155 155 # Since it's allow empty, next/prev are allowed to be empty months (#7164) … … 175 175 res = self.client.get('/dates/books/%s/allow_future/' % urlbit) 176 176 self.assertEqual(res.status_code, 200) 177 177 self.assertEqual(res.context['date_list'][0].date(), b.pubdate) 178 self.assertEqual(list(res.context['book s']), [b])178 self.assertEqual(list(res.context['book_list']), [b]) 179 179 self.assertEqual(res.context['month'], future) 180 180 181 181 # Since it's allow_future but not allow_empty, next/prev are not … … 229 229 res = self.client.get('/dates/books/2008/week/39/') 230 230 self.assertEqual(res.status_code, 200) 231 231 self.assertTemplateUsed(res, 'generic_views/book_archive_week.html') 232 self.assertEqual(res.context['book s'][0], Book.objects.get(pubdate=datetime.date(2008, 10, 1)))232 self.assertEqual(res.context['book_list'][0], Book.objects.get(pubdate=datetime.date(2008, 10, 1))) 233 233 self.assertEqual(res.context['week'], datetime.date(2008, 9, 28)) 234 234 235 235 def test_week_view_allow_empty(self): … … 238 238 239 239 res = self.client.get('/dates/books/2008/week/12/allow_empty/') 240 240 self.assertEqual(res.status_code, 200) 241 self.assertEqual(list(res.context['book s']), [])241 self.assertEqual(list(res.context['book_list']), []) 242 242 243 243 def test_week_view_allow_future(self): 244 244 future = datetime.date(datetime.date.today().year + 1, 1, 1) … … 249 249 250 250 res = self.client.get('/dates/books/%s/week/1/allow_future/' % future.year) 251 251 self.assertEqual(res.status_code, 200) 252 self.assertEqual(list(res.context['book s']), [b])252 self.assertEqual(list(res.context['book_list']), [b]) 253 253 254 254 def test_week_view_invalid_pattern(self): 255 255 res = self.client.get('/dates/books/2007/week/no_week/') … … 273 273 res = self.client.get('/dates/books/2008/oct/01/') 274 274 self.assertEqual(res.status_code, 200) 275 275 self.assertTemplateUsed(res, 'generic_views/book_archive_day.html') 276 self.assertEqual(list(res.context['book s']),276 self.assertEqual(list(res.context['book_list']), 277 277 list(Book.objects.filter(pubdate=datetime.date(2008, 10, 1)))) 278 278 self.assertEqual(res.context['day'], datetime.date(2008, 10, 1)) 279 279 … … 289 289 # allow_empty = True, empty month 290 290 res = self.client.get('/dates/books/2000/jan/1/allow_empty/') 291 291 self.assertEqual(res.status_code, 200) 292 self.assertEqual(list(res.context['book s']), [])292 self.assertEqual(list(res.context['book_list']), []) 293 293 self.assertEqual(res.context['day'], datetime.date(2000, 1, 1)) 294 294 295 295 # Since it's allow empty, next/prev are allowed to be empty months (#7164) … … 314 314 # allow_future = True, valid future month 315 315 res = self.client.get('/dates/books/%s/allow_future/' % urlbit) 316 316 self.assertEqual(res.status_code, 200) 317 self.assertEqual(list(res.context['book s']), [b])317 self.assertEqual(list(res.context['book_list']), [b]) 318 318 self.assertEqual(res.context['day'], future) 319 319 320 320 # allow_future but not allow_empty, next/prev amust be valid -
tests/regressiontests/generic_views/detail.py
32 32 res = self.client.get('/detail/artist/1/') 33 33 self.assertEqual(res.status_code, 200) 34 34 self.assertEqual(res.context['object'], Artist.objects.get(pk=1)) 35 self.assertEqual(res.context[' professional_artist'], Artist.objects.get(pk=1))35 self.assertEqual(res.context['artist'], Artist.objects.get(pk=1)) 36 36 self.assertTemplateUsed(res, 'generic_views/artist_detail.html') 37 37 38 38 def test_template_name(self):