Ticket #1282: 1282.diff

File 1282.diff, 4.0 KB (added by Chris Beaven, 16 years ago)
  • django/views/generic/date_based.py

     
    274274            c[key] = value
    275275    return HttpResponse(t.render(c), mimetype=mimetype)
    276276
    277 def archive_today(request, **kwargs):
     277def archive_today(request, month_format='%b', **kwargs):
    278278    """
    279279    Generic daily archive view for today. Same as archive_day view.
    280280    """
    281281    today = datetime.date.today()
    282282    kwargs.update({
    283283        'year': str(today.year),
    284         'month': today.strftime('%b').lower(),
     284        'month': today.strftime(month_format).lower(),
    285285        'day': str(today.day),
    286286    })
    287     return archive_day(request, **kwargs)
     287    return archive_day(request, month_format=month_format, **kwargs)
    288288
    289289def object_detail(request, year, month, day, queryset, date_field,
    290290        month_format='%b', day_format='%d', object_id=None, slug=None,
  • tests/regressiontests/views/tests/generic/date_based.py

     
    6767        article.save()
    6868        response = self.client.get('/views/date_based/archive_month/2004/02/')
    6969        self.assertEqual(response.status_code, 404)
    70                  
    71          
    72  No newline at end of file
     70
     71class DayArchiveTest(TestCase):
     72    fixtures = ['testdata.json']
     73
     74    def setUp(self):
     75        # Correct the date for the current article
     76        current_article = Article.objects.get(title="Current Article")
     77        current_article.date_created = datetime.now()
     78        current_article.save()
     79
     80    def test_archive_today(self):
     81        response = self.client.get('/views/date_based/today/')
     82        self.assertEqual(response.status_code, 200)
     83        objects = response.context['object_list']
     84        self.assertEqual(len(objects), 1)
     85        self.assertEqual(objects[0].title, 'Current Article')
     86
     87    def test_archive_today_month_format(self):
     88        response = self.client.get('/views/date_based/today_month_format/')
     89        self.assertEqual(response.status_code, 200)
     90        objects = response.context['object_list']
     91        self.assertEqual(len(objects), 1)
     92        self.assertEqual(objects[0].title, 'Current Article')
     93
     94    def test_archive_day_abbrev_month(self):
     95        response = self.client.get('/views/date_based/archive_day/2001/jan/1/')
     96        self.assertEqual(response.status_code, 200)
     97        objects = response.context['object_list']
     98        self.assertEqual(len(objects), 1)
     99        self.assertEqual(objects[0].title, 'Old Article')
     100
     101    def test_archive_day_numeric_month(self):
     102        response = self.client.get('/views/date_based/archive_day/2001/1/1/')
     103        self.assertEqual(response.status_code, 200)
     104        objects = response.context['object_list']
     105        self.assertEqual(len(objects), 1)
     106        self.assertEqual(objects[0].title, 'Old Article')
  • tests/regressiontests/views/urls.py

     
    4848    (r'^date_based/archive_month/(?P<year>\d{4})/(?P<month>\d{1,2})/$',
    4949        'archive_month',
    5050        date_based_info_dict),
     51    (r'^date_based/today/$',
     52        'archive_today',
     53        date_based_info_dict),
     54    (r'^date_based/today_month_format/$',
     55        'archive_today',
     56        dict(date_based_info_dict, month_format='%m')),
     57    (r'^date_based/archive_day/(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{1,2})/$',
     58        'archive_day',
     59        dict(date_based_info_dict, month_format='%b')),
     60    (r'^date_based/archive_day/(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/$',
     61        'archive_day',
     62        dict(date_based_info_dict, month_format='%m')),
    5163)
    5264
    5365# crud generic views.
Back to Top