Fixed #26217 -- Added a warning about format strings to WeekArchiveView docs.

This commit is contained in:
Michal Petrucha 2016-02-20 18:04:50 +01:00 committed by Tim Graham
parent a1b1688c7d
commit fe8ea3ba3b
1 changed files with 20 additions and 12 deletions

View File

@ -333,6 +333,15 @@ views for displaying drilldown pages for date-based data.
* Uses a default ``template_name_suffix`` of ``_archive_week``. * Uses a default ``template_name_suffix`` of ``_archive_week``.
* The ``week_format`` attribute is a :func:`~time.strptime` format string
used to parse the week number. The following values are supported:
* ``'%U'``: Based on the United States week system where the week
begins on Sunday. This is the default value.
* ``'%V'``: Similar to ``'%U'``, except it assumes that the week
begins on Monday. This is not the same as the ISO 8601 week number.
**Example myapp/views.py**:: **Example myapp/views.py**::
from django.views.generic.dates import WeekArchiveView from django.views.generic.dates import WeekArchiveView
@ -372,24 +381,23 @@ views for displaying drilldown pages for date-based data.
<p> <p>
{% if previous_week %} {% if previous_week %}
Previous Week: {{ previous_week|date:"F Y" }} Previous Week: {{ previous_week|date:"W" }} of year {{ previous_week|date:"Y" }}
{% endif %} {% endif %}
{% if previous_week and next_week %}--{% endif %} {% if previous_week and next_week %}--{% endif %}
{% if next_week %} {% if next_week %}
Next week: {{ next_week|date:"F Y" }} Next week: {{ next_week|date:"W" }} of year {{ next_week|date:"Y" }}
{% endif %} {% endif %}
</p> </p>
In this example, you are outputting the week number. The default In this example, you are outputting the week number. Keep in mind that week
``week_format`` in the ``WeekArchiveView`` uses week format ``'%U'`` numbers computed by the :tfilter:`date` template filter with the ``'W'``
which is based on the United States week system where the week begins on a format character are not always the same as those computed by
Sunday. The ``'%W'`` format uses the ISO week format and its week :func:`~time.strftime` and :func:`~time.strptime` with the ``'%W'`` format
begins on a Monday. The ``'%W'`` format is the same in both the string. For year 2015, for example, week numbers output by :tfilter:`date`
:func:`~time.strftime` and the :tfilter:`date`. are higher by one compared to those output by :func:`~time.strftime`. There
isn't an equivalent for the ``'%U'`` :func:`~time.strftime` format string
However, the :tfilter:`date` template filter does not have an equivalent in :tfilter:`date`. Therefore, you should avoid using :tfilter:`date` to
output format that supports the US based week system. The :tfilter:`date` generate URLs for ``WeekArchiveView``.
filter ``'%U'`` outputs the number of seconds since the Unix epoch.
``DayArchiveView`` ``DayArchiveView``
================== ==================