Ticket #1282: ticket1282-rev13294.diff

File ticket1282-rev13294.diff, 4.0 KB (added by Adam Nelson, 15 years ago)

Patch updated as of rev:13294

  • django/views/generic/date_based.py

     
    294294            c[key] = value
    295295    return HttpResponse(t.render(c), mimetype=mimetype)
    296296
    297 def archive_today(request, **kwargs):
     297def archive_today(request, month_format='%b', **kwargs):
    298298    """
    299299    Generic daily archive view for today. Same as archive_day view.
    300300    """
    301301    today = datetime.date.today()
    302302    kwargs.update({
    303303        'year': str(today.year),
    304         'month': today.strftime('%b').lower(),
     304        'month': today.strftime(month_format).lower(),
    305305        'day': str(today.day),
    306306    })
    307     return archive_day(request, **kwargs)
     307    return archive_day(request, month_format=month_format, **kwargs)
    308308
    309309def object_detail(request, year, month, day, queryset, date_field,
    310310        month_format='%b', day_format='%d', object_id=None, slug=None,
  • tests/regressiontests/views/tests/generic/date_based.py

     
    128128        self.assertEqual(len(response.context['date_list']), 2)
    129129
    130130class DayArchiveTests(TestCase):
    131 
     131    fixtures = ['testdata.json']
     132   
     133    def setUp(self):
     134        # Correct the date for the current article
     135        current_article = Article.objects.get(title="Current Article")
     136        current_article.date_created = datetime.now()
     137        current_article.save()
     138   
     139    def test_archive_today(self):
     140        response = self.client.get('/views/date_based/today/')
     141        self.assertEqual(response.status_code, 200)
     142        objects = response.context['object_list']
     143        self.assertEqual(len(objects), 1)
     144        self.assertEqual(objects[0].title, 'Current Article')
     145   
     146    def test_archive_today_month_format(self):
     147        response = self.client.get('/views/date_based/today_month_format/')
     148        self.assertEqual(response.status_code, 200)
     149        objects = response.context['object_list']
     150        self.assertEqual(len(objects), 1)
     151        self.assertEqual(objects[0].title, 'Current Article')
     152   
     153    def test_archive_day_abbrev_month(self):
     154        response = self.client.get('/views/date_based/archive_day/2001/jan/1/')
     155        self.assertEqual(response.status_code, 200)
     156        objects = response.context['object_list']
     157        self.assertEqual(len(objects), 1)
     158        self.assertEqual(objects[0].title, 'Old Article')
     159   
     160    def test_archive_day_numeric_month(self):
     161        response = self.client.get('/views/date_based/archive_day/2001/1/1/')
     162        self.assertEqual(response.status_code, 200)
     163        objects = response.context['object_list']
     164        self.assertEqual(len(objects), 1)
     165        self.assertEqual(objects[0].title, 'Old Article')
     166       
    132167    def test_year_month_day_format(self):
    133168        """
    134169        Make sure day views don't get confused with numeric month formats (#7944)
  • tests/regressiontests/views/urls.py

     
    7474    (r'^date_based/datefield/archive_month/(?P<year>\d{4})/(?P<month>\d{1,2})/$',
    7575        'archive_month',
    7676        date_based_datefield_info_dict),
     77    (r'^date_based/today/$',
     78        'archive_today',
     79        date_based_info_dict),
     80    (r'^date_based/today_month_format/$',
     81        'archive_today',
     82        dict(date_based_info_dict, month_format='%m')),
     83    (r'^date_based/archive_day/(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{1,2})/$',
     84        'archive_day',
     85        dict(date_based_info_dict, month_format='%b')),
     86    (r'^date_based/archive_day/(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/$',
     87        'archive_day',
     88        dict(date_based_info_dict, month_format='%m')),
    7789)
    7890
    7991# crud generic views.
Back to Top