defget_next_week(self,date):"""Get the next valid week."""return_get_next_prev(self,date,is_previous=False,period='week')
Get the previous valid week.
195
196
197
defget_previous_week(self,date):"""Get the previous valid week."""return_get_next_prev(self,date,is_previous=True,period='week')
Возвращает неделю, для которой в этом представлении должны отображаться данные.
178
179
180
181
182
183
184
185
186
187
188
189
defget_week(self):"""Return the week for which this view should display data."""week=self.weekifweekisNone:try:week=self.kwargs['week']exceptKeyError:try:week=self.request.GET['week']exceptKeyError:raiseHttp404(_("No week specified"))returnweek
Получает строку формата недели в синтаксисе strptime, которая будет использоваться для анализа недели по переменным URL.
171
172
173
174
175
176
defget_week_format(self):""" Get a week format string in strptime syntax to be used to parse the week from url variables. """returnself.week_format
Возвращает дату начала текущего интервала.
210
211
212
def_get_current_week(self,date):"""Return the start date of the current interval."""returndate-datetime.timedelta(self._get_weekday(date))
Возвращает дату начала следующего интервала.
Интервал определяется датой начала <= дата элемента < следующая дата начала.
199
200
201
202
203
204
205
206
207
def_get_next_week(self,date):""" Return the start date of the next interval. The interval is defined by start date <= item date < next start date. """try:returndate+datetime.timedelta(days=7-self._get_weekday(date))exceptOverflowError:raiseHttp404(_("Date out of range"))
Return the weekday for a given date.
The first day according to the week format is 0 and the last day is 6.
214
215
216
217
218
219
220
221
222
223
224
225
def_get_weekday(self,date):""" Return the weekday for a given date. The first day according to the week format is 0 and the last day is 6. """week_format=self.get_week_format()ifweek_format=='%W':# week starts on Mondayreturndate.weekday()elifweek_format=='%U':# week starts on Sundayreturn(date.weekday()+1)%7else:raiseValueError("unknown week format: %s"%week_format)