1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #29903 -- Added error message for invalid WeekArchiveView week_format.

This commit is contained in:
Hasan Ramezani
2018-10-29 15:56:04 +01:00
committed by Tim Graham
parent 7f2b27e95c
commit 4f8f1b2f24
3 changed files with 16 additions and 4 deletions

View File

@@ -485,10 +485,14 @@ class BaseWeekArchiveView(YearMixin, WeekMixin, BaseDateListView):
date_field = self.get_date_field()
week_format = self.get_week_format()
week_start = {
'%W': '1',
'%U': '0',
}[week_format]
week_choices = {'%W': '1', '%U': '0'}
try:
week_start = week_choices[week_format]
except KeyError:
raise ValueError('Unknown week format %r. Choices are: %s' % (
week_format,
', '.join(sorted(week_choices)),
))
date = _date_from_string(year, self.get_year_format(),
week_start, '%w',
week, week_format)