Ticket #16918: 16918.diff

File 16918.diff, 2.8 KB (added by Koen Biermans, 13 years ago)

patch with test for #16918

  • tests/regressiontests/generic_views/views.py

     
    177177class AuthorGetQuerySetFormView(generic.edit.ModelFormMixin):
    178178    def get_queryset(self):
    179179        return Author.objects.all()
     180
     181class BookDetail16918(BookDetail):
     182    # testing for #16918
     183    def get_object(self, queryset=None):
     184        return super(BookDetail16918,self).get_object(queryset=Book.objects.filter(pk=2))
     185
  • tests/regressiontests/generic_views/dates.py

     
    412412    def test_invalid_url(self):
    413413        self.assertRaises(AttributeError, self.client.get, "/dates/books/2008/oct/01/nopk/")
    414414
     415    def test_16918(self):
     416    # testing for #16918
     417        res = self.client.get('/dates/books/16918/2006/may/01/2/')
     418        self.assertEqual(res.status_code, 200)
     419        self.assertEqual(res.context['object'], Book.objects.get(pk=2))
     420        self.assertEqual(res.context['book'], Book.objects.get(pk=2))
     421        self.assertTemplateUsed(res, 'generic_views/book_detail.html')
     422
     423        res = self.client.get('/dates/books/16918/2008/oct/01/1/')
     424        self.assertEqual(res.status_code, 404)
     425   
  • tests/regressiontests/generic_views/urls.py

     
    216216    (r'^dates/books/(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\d{1,2})/byslug/(?P<slug>[\w-]+)/$',
    217217        views.BookDetail.as_view()),
    218218
     219    # testing for #16918
     220    (r'^dates/books/16918/(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\d{1,2})/(?P<pk>\d+)/$',
     221        views.BookDetail16918.as_view()),
     222
    219223    # Useful for testing redirects
    220224    (r'^accounts/login/$',  'django.contrib.auth.views.login')
    221225)
  • django/views/generic/dates.py

     
    459459                                 month, self.get_month_format(),
    460460                                 day, self.get_day_format())
    461461
    462         qs = self.get_queryset()
     462        if queryset is None:
     463            qs = self.get_queryset()
     464        else:
     465            qs = queryset
    463466
    464467        if not self.get_allow_future() and date > datetime.date.today():
    465468            raise Http404(_(u"Future %(verbose_name_plural)s not available because %(class_name)s.allow_future is False.") % {
Back to Top