Ticket #6037: month_detail.2.diff

File month_detail.2.diff, 5.1 KB (added by jan2ary, 17 years ago)
  • django/views/generic/date_based.py

     
    123123    model = queryset.model
    124124    now = datetime.datetime.now()
    125125
     126    lookup_kwargs = {'%s__month' % date_field: date.month}
     127    date_list = queryset.filter(**lookup_kwargs).dates(date_field, 'day')
    126128    # Calculate first and last day of month, for use in a date-range lookup.
    127129    first_day = date.replace(day=1)
    128130    if first_day.month == 12:
     
    150152        template_name = "%s/%s_archive_month.html" % (model._meta.app_label, model._meta.object_name.lower())
    151153    t = template_loader.get_template(template_name)
    152154    c = RequestContext(request, {
     155        'date_list': date_list,
    153156        '%s_list' % template_object_name: object_list,
    154157        'month': date,
    155158        'next_month': next_month,
  • django/contrib/databrowse/templates/databrowse/calendar_month.html

     
    66
    77<div id="breadcrumbs"><a href="{{ root_url }}">Home</a> / <a href="{{ model.url }}">{{ model.verbose_name_plural|capfirst }}</a> / <a href="../../../">Calendars</a> / <a href="../../">By {{ field.verbose_name }}</a> / <a href="../">{{ month.year }}</a> / {{ month|date:"F" }}</div>
    88
    9 <h1>{{ object_list.count }} {% if object_list.count|pluralize %}{{ model.verbose_name_plural|escape }}{% else %}{{ model.verbose_name|escape }}{% endif %} with {{ field.verbose_name }} on {{ day|date:"F Y" }}</h1>
     9<h1>{{ object_list.count }} {% if object_list.count|pluralize %}{{ model.verbose_name_plural|escape }}{% else %}{{ model.verbose_name|escape }}{% endif %} with {{ field.verbose_name }} on {{ month|date:"F Y" }}</h1>
    1010
    1111<ul class="objectlist">
    12 {% for object in object_list %}
    13 <li class="{% cycle 'odd' 'even' %}"><a href="{{ object.url }}">{{ object|escape }}</a></li>
     12{% for day in date_list %}
     13<li class="{% cycle 'odd' 'even' %}"><a href="{{ day|date:"d"|lower }}/">{{ day|date }}</a></li>
    1414{% endfor %}
    1515</ul>
    1616
  • 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    def test_archive_month_contains_day(self):
     73        author = Author(name="Petryk Pyatochkin")
     74        author.save()
     75
     76        article = Article(title="example", author=author)
     77        article.date_created = datetime(2007, 11, 27, 0, 0, 1)
     78        article.save()
     79
     80        response = self.client.get('/views/date_based/archive_month/2007/11/')
     81        self.assertEqual(response.status_code, 200)
     82
     83        response = self.client.get('/views/date_based/archive_month/2007/12/')
     84        self.assertEqual(response.status_code, 404)
     85
     86    def test_if_day_available(self):
     87        author = Author(name="Mykola Salo")
     88        author.save()
     89
     90        article = Article(title="example", author=author)
     91        article.date_created = datetime(2007, 11, 27, 0, 0, 1)
     92        article.save()
     93
     94        response = self.client.get('/views/date_based/archive_day/2007/11/27/')
     95        self.assertEqual(response.status_code, 200)
     96
     97        response = self.client.get('/views/date_based/archive_day/2007/11/28/')
     98        self.assertEqual(response.status_code, 404)
     99       
     100
  • tests/regressiontests/views/urls.py

     
    3535    # Static views
    3636    (r'^site_media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': media_dir}),
    3737   
    38         # Date-based generic views
     38    # Date-based generic views
    3939    (r'^date_based/object_detail/(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/(?P<slug>[-\w]+)/$',
    4040        'django.views.generic.date_based.object_detail',
    4141        dict(slug_field='slug', **date_based_info_dict)),
     
    4545    (r'^date_based/archive_month/(?P<year>\d{4})/(?P<month>\d{1,2})/$',
    4646        'django.views.generic.date_based.archive_month',
    4747        date_based_info_dict),     
     48    (r'^date_based/archive_day/(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/$',
     49        'django.views.generic.date_based.archive_day',
     50        date_based_info_dict),
    4851)
  • tests/templates/views/article_archive_day.html

     
     1This template intentionally left blank
     2
Back to Top