class WeekMixin
from django.views.generic.dates import WeekMixin
Mixin for views manipulating week-based data.
Descendants
Attributes
Defined in | |
---|---|
week = None
|
WeekMixin |
week_format = '%U'
|
WeekMixin |
Methods
def
_get_current_week(self, date):
WeekMixin
¶
def
_get_current_week(self, date):
WeekMixin
¶
Return the start date of the current interval.
251 252 253 254 255 | def _get_current_week(self, date):
"""
Return the start date of the current interval.
"""
return date - datetime.timedelta(self._get_weekday(date))
|
def
_get_next_week(self, date):
WeekMixin
¶
def
_get_next_week(self, date):
WeekMixin
¶
Return the start date of the next interval. The interval is defined by start date <= item date < next start date.
240 241 242 243 244 245 246 247 248 | 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:
return date + datetime.timedelta(days=7 - self._get_weekday(date))
except OverflowError:
raise Http404(_("Date out of range"))
|
def
_get_weekday(self, date):
WeekMixin
¶
def
_get_weekday(self, date):
WeekMixin
¶
Return the weekday for a given date. The first day according to the week format is 0 and the last day is 6.
257 258 259 260 261 262 263 264 265 266 267 268 | 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()
if week_format == '%W': # week starts on Monday
return date.weekday()
elif week_format == '%U': # week starts on Sunday
return (date.weekday() + 1) % 7
else:
raise ValueError("unknown week format: %s" % week_format)
|
def
get_next_week(self, date):
WeekMixin
¶
def
get_next_week(self, date):
WeekMixin
¶
Get the next valid week.
228 229 230 231 232 | def get_next_week(self, date):
"""
Get the next valid week.
"""
return _get_next_prev(self, date, is_previous=False, period='week')
|
def
get_previous_week(self, date):
WeekMixin
¶
def
get_previous_week(self, date):
WeekMixin
¶
Get the previous valid week.
234 235 236 237 238 | def get_previous_week(self, date):
"""
Get the previous valid week.
"""
return _get_next_prev(self, date, is_previous=True, period='week')
|
def
get_week(self):
WeekMixin
¶
def
get_week(self):
WeekMixin
¶
Return the week for which this view should display data
213 214 215 216 217 218 219 220 221 222 223 224 225 226 | def get_week(self):
"""
Return the week for which this view should display data
"""
week = self.week
if week is None:
try:
week = self.kwargs['week']
except KeyError:
try:
week = self.request.GET['week']
except KeyError:
raise Http404(_("No week specified"))
return week
|
def
get_week_format(self):
WeekMixin
¶
def
get_week_format(self):
WeekMixin
¶
Get a week format string in strptime syntax to be used to parse the week from url variables.
206 207 208 209 210 211 | def get_week_format(self):
"""
Get a week format string in strptime syntax to be used to parse the
week from url variables.
"""
return self.week_format
|