Ticket #15272: patch.diff

File patch.diff, 17.1 KB (added by szczav, 14 years ago)

Patch and tests

  • django/views/generic/date_based.py

     
    3434        queryset = queryset.filter(**{'%s__lte' % date_field: datetime.datetime.now()})
    3535    date_list = queryset.dates(date_field, 'year')[::-1]
    3636    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)
    3838
    3939    if date_list and num_latest:
    4040        latest = queryset.order_by('-'+date_field)[:num_latest]
     
    354354    try:
    355355        obj = queryset.get(**lookup_kwargs)
    356356    except ObjectDoesNotExist:
    357         raise Http404("No %s found for" % model._meta.verbose_name)
     357        raise Http404("No %s found for" % model._meta.object_name)
    358358    if not template_name:
    359359        template_name = "%s/%s_detail.html" % (model._meta.app_label, model._meta.object_name.lower())
    360360    if template_name_field:
  • django/views/generic/list.py

     
    7676        if self.context_object_name:
    7777            return self.context_object_name
    7878        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())
    8180        else:
    8281            return None
    8382
  • django/views/generic/list_detail.py

     
    131131    try:
    132132        obj = queryset.get()
    133133    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))
    135135    if not template_name:
    136136        template_name = "%s/%s_detail.html" % (model._meta.app_label, model._meta.object_name.lower())
    137137    if template_name_field:
  • django/views/generic/dates.py

     
    194194            qs = qs.filter(**{'%s__lte' % date_field: datetime.datetime.now()})
    195195
    196196        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))
    198198
    199199        return qs
    200200
     
    208208
    209209        date_list = queryset.dates(date_field, date_type)[::-1]
    210210        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))
    212212
    213213        return date_list
    214214
     
    458458        qs = self.get_queryset()
    459459
    460460        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__)
    463463            )
    464464
    465465        # Filter down a queryset from self.queryset using the date from the
  • django/views/generic/detail.py

     
    4848            obj = queryset.get()
    4949        except ObjectDoesNotExist:
    5050            raise Http404(u"No %s found matching the query" %
    51                           (queryset.model._meta.verbose_name))
     51                          (queryset.model._meta.object_name))
    5252        return obj
    5353
    5454    def get_queryset(self):
     
    8080        if self.context_object_name:
    8181            return self.context_object_name
    8282        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())
    8584        else:
    8685            return None
    8786
  • django/views/generic/create_update.py

     
    9595        return model.objects.get(**lookup_kwargs)
    9696    except ObjectDoesNotExist:
    9797        raise Http404("No %s found for %s"
    98                       % (model._meta.verbose_name, lookup_kwargs))
     98                      % (model._meta.object_name, lookup_kwargs))
    9999
    100100def create_object(request, model=None, template_name=None,
    101101        template_loader=loader, extra_context=None, post_save_redirect=None,
  • tests/regressiontests/generic_views/list.py

     
    1919        self.assertEqual(res.status_code, 200)
    2020        self.assertTemplateUsed(res, 'generic_views/author_list.html')
    2121        self.assertEqual(list(res.context['object_list']), list(Author.objects.all()))
    22         self.assertIs(res.context['authors'], res.context['object_list'])
     22        self.assertIs(res.context['author_list'], res.context['object_list'])
    2323        self.assertIsNone(res.context['paginator'])
    2424        self.assertIsNone(res.context['page_obj'])
    2525        self.assertFalse(res.context['is_paginated'])
     
    3030        self.assertEqual(res.status_code, 200)
    3131        self.assertTemplateUsed(res, 'generic_views/author_list.html')
    3232        self.assertEqual(len(res.context['object_list']), 30)
    33         self.assertIs(res.context['authors'], res.context['object_list'])
     33        self.assertIs(res.context['author_list'], res.context['object_list'])
    3434        self.assertTrue(res.context['is_paginated'])
    3535        self.assertEqual(res.context['page_obj'].number, 1)
    3636        self.assertEqual(res.context['paginator'].num_pages, 4)
    37         self.assertEqual(res.context['authors'][0].name, 'Author 00')
    38         self.assertEqual(list(res.context['authors'])[-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')
    3939
    4040    def test_paginated_queryset_shortdata(self):
    4141        # Test that short datasets ALSO result in a paginated view.
     
    4343        self.assertEqual(res.status_code, 200)
    4444        self.assertTemplateUsed(res, 'generic_views/author_list.html')
    4545        self.assertEqual(list(res.context['object_list']), list(Author.objects.all()))
    46         self.assertIs(res.context['authors'], res.context['object_list'])
     46        self.assertIs(res.context['author_list'], res.context['object_list'])
    4747        self.assertEqual(res.context['page_obj'].number, 1)
    4848        self.assertEqual(res.context['paginator'].num_pages, 1)
    4949        self.assertTrue(res.context['is_paginated'])
     
    5454        self.assertEqual(res.status_code, 200)
    5555        self.assertTemplateUsed(res, 'generic_views/author_list.html')
    5656        self.assertEqual(len(res.context['object_list']), 30)
    57         self.assertIs(res.context['authors'], res.context['object_list'])
    58         self.assertEqual(res.context['authors'][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')
    5959        self.assertEqual(res.context['page_obj'].number, 2)
    6060
    6161    def test_paginated_get_last_page_by_query_string(self):
     
    6363        res = self.client.get('/list/authors/paginated/', {'page': 'last'})
    6464        self.assertEqual(res.status_code, 200)
    6565        self.assertEqual(len(res.context['object_list']), 10)
    66         self.assertIs(res.context['authors'], res.context['object_list'])
    67         self.assertEqual(res.context['authors'][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')
    6868        self.assertEqual(res.context['page_obj'].number, 4)
    6969
    7070    def test_paginated_get_page_by_urlvar(self):
     
    7373        self.assertEqual(res.status_code, 200)
    7474        self.assertTemplateUsed(res, 'generic_views/author_list.html')
    7575        self.assertEqual(len(res.context['object_list']), 30)
    76         self.assertIs(res.context['authors'], res.context['object_list'])
    77         self.assertEqual(res.context['authors'][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')
    7878        self.assertEqual(res.context['page_obj'].number, 3)
    7979
    8080    def test_paginated_page_out_of_range(self):
     
    112112        self.assertEqual(res.status_code, 200)
    113113        self.assertTemplateUsed(res, 'generic_views/list.html')
    114114        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'])
    116116        self.assertIsNone(res.context['paginator'])
    117117        self.assertIsNone(res.context['page_obj'])
    118118        self.assertFalse(res.context['is_paginated'])
     
    128128        res = self.client.get('/list/authors/template_name/')
    129129        self.assertEqual(res.status_code, 200)
    130130        self.assertEqual(list(res.context['object_list']), list(Author.objects.all()))
    131         self.assertIs(res.context['authors'], res.context['object_list'])
     131        self.assertIs(res.context['author_list'], res.context['object_list'])
    132132        self.assertTemplateUsed(res, 'generic_views/list.html')
    133133
    134134    def test_template_name_suffix(self):
    135135        res = self.client.get('/list/authors/template_name_suffix/')
    136136        self.assertEqual(res.status_code, 200)
    137137        self.assertEqual(list(res.context['object_list']), list(Author.objects.all()))
    138         self.assertIs(res.context['authors'], res.context['object_list'])
     138        self.assertIs(res.context['author_list'], res.context['object_list'])
    139139        self.assertTemplateUsed(res, 'generic_views/author_objects.html')
    140140
    141141    def test_context_object_name(self):
  • tests/regressiontests/generic_views/dates.py

     
    9292        res = self.client.get('/dates/books/2006/make_object_list/')
    9393        self.assertEqual(res.status_code, 200)
    9494        self.assertEqual(list(res.context['date_list']), [datetime.datetime(2006, 5, 1)])
    95         self.assertEqual(list(res.context['books']), list(Book.objects.filter(pubdate__year=2006)))
     95        self.assertEqual(list(res.context['book_list']), list(Book.objects.filter(pubdate__year=2006)))
    9696        self.assertEqual(list(res.context['object_list']), list(Book.objects.filter(pubdate__year=2006)))
    9797        self.assertTemplateUsed(res, 'generic_views/book_archive_year.html')
    9898
     
    102102        res = self.client.get('/dates/books/1999/allow_empty/')
    103103        self.assertEqual(res.status_code, 200)
    104104        self.assertEqual(list(res.context['date_list']), [])
    105         self.assertEqual(list(res.context['books']), [])
     105        self.assertEqual(list(res.context['book_list']), [])
    106106
    107107    def test_year_view_allow_future(self):
    108108        # Create a new book in the future
     
    113113
    114114        res = self.client.get('/dates/books/%s/allow_empty/' % year)
    115115        self.assertEqual(res.status_code, 200)
    116         self.assertEqual(list(res.context['books']), [])
     116        self.assertEqual(list(res.context['book_list']), [])
    117117
    118118        res = self.client.get('/dates/books/%s/allow_future/' % year)
    119119        self.assertEqual(res.status_code, 200)
     
    132132        self.assertEqual(res.status_code, 200)
    133133        self.assertTemplateUsed(res, 'generic_views/book_archive_month.html')
    134134        self.assertEqual(list(res.context['date_list']), [datetime.datetime(2008, 10, 1)])
    135         self.assertEqual(list(res.context['books']),
     135        self.assertEqual(list(res.context['book_list']),
    136136                         list(Book.objects.filter(pubdate=datetime.date(2008, 10, 1))))
    137137        self.assertEqual(res.context['month'], datetime.date(2008, 10, 1))
    138138
     
    149149        res = self.client.get('/dates/books/2000/jan/allow_empty/')
    150150        self.assertEqual(res.status_code, 200)
    151151        self.assertEqual(list(res.context['date_list']), [])
    152         self.assertEqual(list(res.context['books']), [])
     152        self.assertEqual(list(res.context['book_list']), [])
    153153        self.assertEqual(res.context['month'], datetime.date(2000, 1, 1))
    154154
    155155        # Since it's allow empty, next/prev are allowed to be empty months (#7164)
     
    175175        res = self.client.get('/dates/books/%s/allow_future/' % urlbit)
    176176        self.assertEqual(res.status_code, 200)
    177177        self.assertEqual(res.context['date_list'][0].date(), b.pubdate)
    178         self.assertEqual(list(res.context['books']), [b])
     178        self.assertEqual(list(res.context['book_list']), [b])
    179179        self.assertEqual(res.context['month'], future)
    180180
    181181        # Since it's allow_future but not allow_empty, next/prev are not
     
    229229        res = self.client.get('/dates/books/2008/week/39/')
    230230        self.assertEqual(res.status_code, 200)
    231231        self.assertTemplateUsed(res, 'generic_views/book_archive_week.html')
    232         self.assertEqual(res.context['books'][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)))
    233233        self.assertEqual(res.context['week'], datetime.date(2008, 9, 28))
    234234
    235235    def test_week_view_allow_empty(self):
     
    238238
    239239        res = self.client.get('/dates/books/2008/week/12/allow_empty/')
    240240        self.assertEqual(res.status_code, 200)
    241         self.assertEqual(list(res.context['books']), [])
     241        self.assertEqual(list(res.context['book_list']), [])
    242242
    243243    def test_week_view_allow_future(self):
    244244        future = datetime.date(datetime.date.today().year + 1, 1, 1)
     
    249249
    250250        res = self.client.get('/dates/books/%s/week/1/allow_future/' % future.year)
    251251        self.assertEqual(res.status_code, 200)
    252         self.assertEqual(list(res.context['books']), [b])
     252        self.assertEqual(list(res.context['book_list']), [b])
    253253
    254254    def test_week_view_invalid_pattern(self):
    255255        res = self.client.get('/dates/books/2007/week/no_week/')
     
    273273        res = self.client.get('/dates/books/2008/oct/01/')
    274274        self.assertEqual(res.status_code, 200)
    275275        self.assertTemplateUsed(res, 'generic_views/book_archive_day.html')
    276         self.assertEqual(list(res.context['books']),
     276        self.assertEqual(list(res.context['book_list']),
    277277                         list(Book.objects.filter(pubdate=datetime.date(2008, 10, 1))))
    278278        self.assertEqual(res.context['day'], datetime.date(2008, 10, 1))
    279279
     
    289289        # allow_empty = True, empty month
    290290        res = self.client.get('/dates/books/2000/jan/1/allow_empty/')
    291291        self.assertEqual(res.status_code, 200)
    292         self.assertEqual(list(res.context['books']), [])
     292        self.assertEqual(list(res.context['book_list']), [])
    293293        self.assertEqual(res.context['day'], datetime.date(2000, 1, 1))
    294294
    295295        # Since it's allow empty, next/prev are allowed to be empty months (#7164)
     
    314314        # allow_future = True, valid future month
    315315        res = self.client.get('/dates/books/%s/allow_future/' % urlbit)
    316316        self.assertEqual(res.status_code, 200)
    317         self.assertEqual(list(res.context['books']), [b])
     317        self.assertEqual(list(res.context['book_list']), [b])
    318318        self.assertEqual(res.context['day'], future)
    319319
    320320        # allow_future but not allow_empty, next/prev amust be valid
  • tests/regressiontests/generic_views/detail.py

     
    3232        res = self.client.get('/detail/artist/1/')
    3333        self.assertEqual(res.status_code, 200)
    3434        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))
    3636        self.assertTemplateUsed(res, 'generic_views/artist_detail.html')
    3737
    3838    def test_template_name(self):
Back to Top