Класс YearMixin (Django 3.2)
from django.views.generic.dates import YearMixin
Mixin for views manipulating year-based data.
Diagramm | Documentation | Source code
Attributes
Defined in | |
---|---|
year = None
|
YearMixin |
year_format = '%Y'
|
YearMixin |
Methods
Return the start date of the current interval.
def _get_current_year(self, date):
"""Return the start date of the current interval."""
return date.replace(month=1, day=1)
Return the start date of the next interval. The interval is defined by start date <= item date < next start date.
def _get_next_year(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.replace(year=date.year + 1, month=1, day=1)
except ValueError:
raise Http404(_("Date out of range"))
Get the next valid year.
def get_next_year(self, date):
"""Get the next valid year."""
return _get_next_prev(self, date, is_previous=False, period='year')
Get the previous valid year.
def get_previous_year(self, date):
"""Get the previous valid year."""
return _get_next_prev(self, date, is_previous=True, period='year')
Return the year for which this view should display data.
def get_year(self):
"""Return the year for which this view should display data."""
year = self.year
if year is None:
try:
year = self.kwargs['year']
except KeyError:
try:
year = self.request.GET['year']
except KeyError:
raise Http404(_("No year specified"))
return year
Get a year format string in strptime syntax to be used to parse the year from url variables.
def get_year_format(self):
"""
Get a year format string in strptime syntax to be used to parse the
year from url variables.
"""
return self.year_format