Ticket #1282: patch-1282.diff

File patch-1282.diff, 4.1 KB (added by nickefford, 7 years ago)

Updated patch

  • 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),
     286        'month_format': month_format,
    286287    })
    287288    return archive_day(request, **kwargs)
    288289
  • 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

     
    2121    'month_format': '%m',
    2222}
    2323
     24# For testing of archive_day
     25archive_day_info_dict = {
     26    'queryset': Article.objects.all(),
     27    'date_field': 'date_created',
     28}
     29
    2430urlpatterns = patterns('',
    2531    (r'^$', views.index_page),
    2632
     
    4854    (r'^date_based/archive_month/(?P<year>\d{4})/(?P<month>\d{1,2})/$',
    4955        'archive_month',
    5056        date_based_info_dict),
     57    (r'^date_based/today/$',
     58        'archive_today',
     59        archive_day_info_dict),
     60    (r'^date_based/today_month_format/$',
     61        'archive_today',
     62        dict(archive_day_info_dict, month_format='%m')),
     63    (r'^date_based/archive_day/(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{1,2})/$',
     64        'archive_day',
     65        dict(archive_day_info_dict, month_format='%b')),
     66    (r'^date_based/archive_day/(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/$',
     67        'archive_day',
     68        dict(archive_day_info_dict, month_format='%m')),
    5169)
    5270
    5371# crud generic views.
Back to Top