#31711: WeekArchiveView seens to be zero based for week, instead of one based
-------------------------------------+-------------------------------------
               Reporter:             |          Owner:  nobody
  RichardZimmerEschborn              |
                   Type:             |         Status:  new
  Uncategorized                      |
              Component:             |        Version:  2.2
  Uncategorized                      |       Keywords:  ArchiveView, Week,
               Severity:  Normal     |  bug
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 Django 2.2.6, Python 3.7.3, OS Debian 10.4


 {{{
 # urls.py
 urlpatterns = [
     path('Event/', EventWeekArchiveView.as_view(), name='event_list'),
 ]
 }}}


 {{{
 #models.py
 class Event(models.Model):
     title = models.CharField(max_length=100),
     start = models.DateTimeField()

     def __str__(self):
         return '{} {}'.format(self.title, self.start.strftime('%a %d. %b
 %Y'))
 }}}


 {{{
 # views.py
 class EventWeekArchiveView(WeekArchiveView):
     template_name = 'event_archive_week.html'
     model = Event
     date_field = 'start'
     ordering = 'start'
     year = 2020
     week = 0
     week_format = "%W"
     # week_format = "%U"

     def get_context_data(self, **kwargs):
         context = super().get_context_data(**kwargs)
         print(context)
         return context
 }}}

 {{{
 # event_archive_week.html
 <h1>WEEK {{ week|date:"W" }}</h1>
 <h2> object_list</h2>
 <ul>
    {% for event in object_list %}
       <li>{{ event }} </li>
    {% endfor %}
 </ul>
 <h2> event_list</h2>
 <ul>
    {% for event in event_list %}
       <li>{{ event }} </li>
    {% endfor %}
 </ul>
 }}}

 http://127.0.0.1:XXX/Event generates output for dates: Dec. 29. until Jan.
 4. or Dec. 30. until Jan. 5. depending on week_format setting.

 **Calling week = 0 should not generate any output, instead it should
 generate an error** (like it is done, when calling week = 54). The output
 generated should instead be for calling week = 1

 The reverse works correct: The templatetag <h1>WEEK {{ week|date:"W"
 }}</h1> translates to: WEEK 1.
 But only, when the week_format setting is as shown in class definition.
 This is OK, since the templatetag does support IsoWeek only.

 ----

 While debugging this I found that the resultset is twice in the context.
 Once under the name object_list and a second time under the name
 event_list. For large querysets this seems to be wasting recources.


 {{{
 #output of print(context)
 {'paginator': None, 'page_obj': None, 'is_paginated': False,
 'object_list': <QuerySet [<Event: Happening Wed 01. Jan 2020>]>,
 'event_list': <QuerySet [<Event: Happening Wed 01. Jan 2020>]>,
 'date_list': None, 'week': datetime.date(2019, 12, 29), 'next_week':
 datetime.date(2020, 6, 7), 'previous_week': None, 'view':
 <belegung.views.EventKwView object at 0x7fddaba967b8>}
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/31711>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/064.6cfb0389067dac5a7fac7463a19bb8db%40djangoproject.com.

Reply via email to