diff options
| author | Hasan Ramezani <hasan.r67@gmail.com> | 2020-06-25 23:00:51 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-06-26 11:12:57 +0200 |
| commit | 8984cab8a80af8555b1ccfa5b552d411b47f9bca (patch) | |
| tree | 0951ce3e3396d696a2a28595d4019e1becd0abc9 /django | |
| parent | d2c135da4c75079e45661ec609bd72f27dddf2a9 (diff) | |
Fixed #31620 -- Added support for %V format to WeekMixin/WeekArchiveView.
Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
Diffstat (limited to 'django')
| -rw-r--r-- | django/views/generic/dates.py | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/django/views/generic/dates.py b/django/views/generic/dates.py index b870301222..63151dd5a5 100644 --- a/django/views/generic/dates.py +++ b/django/views/generic/dates.py @@ -218,7 +218,7 @@ class WeekMixin: The first day according to the week format is 0 and the last day is 6. """ week_format = self.get_week_format() - if week_format == '%W': # week starts on Monday + if week_format in {'%W', '%V'}: # week starts on Monday return date.weekday() elif week_format == '%U': # week starts on Sunday return (date.weekday() + 1) % 7 @@ -485,7 +485,7 @@ class BaseWeekArchiveView(YearMixin, WeekMixin, BaseDateListView): date_field = self.get_date_field() week_format = self.get_week_format() - week_choices = {'%W': '1', '%U': '0'} + week_choices = {'%W': '1', '%U': '0', '%V': '1'} try: week_start = week_choices[week_format] except KeyError: @@ -493,10 +493,15 @@ class BaseWeekArchiveView(YearMixin, WeekMixin, BaseDateListView): week_format, ', '.join(sorted(week_choices)), )) - date = _date_from_string(year, self.get_year_format(), - week_start, '%w', - week, week_format) - + year_format = self.get_year_format() + if week_format == '%V' and year_format != '%G': + raise ValueError( + "ISO week directive '%s' is incompatible with the year " + "directive '%s'. Use the ISO year '%%G' instead." % ( + week_format, year_format, + ) + ) + date = _date_from_string(year, year_format, week_start, '%w', week, week_format) since = self._make_date_lookup_arg(date) until = self._make_date_lookup_arg(self._get_next_week(date)) lookup_kwargs = { |
