Ticket #7944: strptime_delimiters4.patch

File strptime_delimiters4.patch, 4.4 KB (added by Alex Gaynor, 16 years ago)

added a templae for the day view

  • AUTHORS

    diff --git a/AUTHORS b/AUTHORS
    index c173a20..83b56af 100644
    a b answer newbie questions, and generally made Django that much better:  
    247247    Christopher Lenz <http://www.cmlenz.net/>
    248248    lerouxb@gmail.com
    249249    Piotr Lewandowski <piotr.lewandowski@gmail.com>
     250    Justin Lilly <justinlilly@gmail.com>
    250251    Waylan Limberg <waylan@gmail.com>
    251252    limodou
    252253    Philip Lindborg <philip.lindborg@gmail.com>
  • django/views/generic/date_based.py

    diff --git a/django/views/generic/date_based.py b/django/views/generic/date_based.py
    index c5f1748..9150266 100644
    a b def archive_month(request, year, month, queryset, date_field,  
    116116    """
    117117    if extra_context is None: extra_context = {}
    118118    try:
    119         date = datetime.date(*time.strptime(year+month, '%Y'+month_format)[:3])
     119        date = datetime.date(*time.strptime("%s-%s" % (year, month), '%s-%s' % ('%Y', month_format))[:3])
    120120    except ValueError:
    121121        raise Http404
    122122
    def archive_day(request, year, month, day, queryset, date_field,  
    237237    """
    238238    if extra_context is None: extra_context = {}
    239239    try:
    240         date = datetime.date(*time.strptime(year+month+day, '%Y'+month_format+day_format)[:3])
     240        date = datetime.date(*time.strptime("%s-%s-%s" % (year, month, day), '%s-%s-%s' % ('%Y', month_format, day_format))[:3])
    241241    except ValueError:
    242242        raise Http404
    243243
    def object_detail(request, year, month, day, queryset, date_field,  
    307307    """
    308308    if extra_context is None: extra_context = {}
    309309    try:
    310         date = datetime.date(*time.strptime(year+month+day, '%Y'+month_format+day_format)[:3])
     310        date = datetime.date(*time.strptime('%s-%s-%s' % (year, month, day), '%s-%s-%s' % ('%Y', month_format, day_format))[:3])
    311311    except ValueError:
    312312        raise Http404
    313313
  • tests/regressiontests/views/tests/generic/date_based.py

    diff --git a/tests/regressiontests/views/tests/generic/date_based.py b/tests/regressiontests/views/tests/generic/date_based.py
    index 3cb7e1e..abbbba9 100644
    a b class MonthArchiveTest(TestCase):  
    9090        response = self.client.get('/views/date_based/datefield/archive_month/2004/02/')
    9191        self.assertEqual(response.status_code, 404)
    9292
     93class DayMonthYearArchiveTest(TestCase):
     94    " Fixes #7944 - Generic date based views get confused with numeric month format"
     95    def setUp(self):
     96        author = Author(name="John Smith")
     97        author.save()
     98
     99        jan_double_day = datetime(2004, 1, 21, 0, 0, 1)
     100
     101        article = Article(title="example", author=author)
     102
     103        article.date_created = jan_double_day
     104        article.save()
     105
     106    def tests_first_month(self):
     107        foo = Article.objects.filter(date_created__year=2004, date_created__month=1, date_created__day=21)
     108        self.assertEqual(len(foo), 1)
     109
     110        response = self.client.get('/views/date_based/archive_day/2004/1/21/')
     111        self.assertEqual(response.status_code, 200)
  • tests/regressiontests/views/urls.py

    diff --git a/tests/regressiontests/views/urls.py b/tests/regressiontests/views/urls.py
    index 6403ab3..a6283c1 100644
    a b date_based_info_dict = {  
    2020    'date_field': 'date_created',
    2121    'month_format': '%m',
    2222}
     23numeric_days_info_dict = dict(date_based_info_dict, day_format='%d')
     24
    2325date_based_datefield_info_dict = dict(date_based_info_dict, queryset=DateArticle.objects.all())
    2426
    2527urlpatterns = patterns('',
    urlpatterns += patterns('django.views.generic.date_based',  
    4648    (r'^date_based/object_detail/(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/(?P<slug>[-\w]+)/allow_future/$',
    4749        'object_detail',
    4850        dict(allow_future=True, slug_field='slug', **date_based_info_dict)),
     51    (r'^date_based/archive_day/(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/$',
     52        'archive_day',
     53        numeric_days_info_dict),
    4954    (r'^date_based/archive_month/(?P<year>\d{4})/(?P<month>\d{1,2})/$',
    5055        'archive_month',
    5156        date_based_info_dict),
  • new file tests/templates/views/article_archive_day.html

    diff --git a/tests/templates/views/article_archive_day.html b/tests/templates/views/article_archive_day.html
    new file mode 100644
    index 0000000..bd2d67f
    - +  
     1This template intentionally left blank
Back to Top