class DateMixin
from django.views.generic.dates import DateMixin
Mixin class for views manipulating date-based data.
Attributes
Defined in | |
---|---|
allow_future = False
|
DateMixin |
date_field = None
|
DateMixin |
uses_datetime_field = <django.utils.functional.cached_property object at 0x7f8299fbb3c8>
|
DateMixin |
Methods
def
_make_date_lookup_arg(self, value):
DateMixin
¶
def
_make_date_lookup_arg(self, value):
DateMixin
¶
Convert a date into a datetime when the date field is a DateTimeField. When time zone support is enabled, `date` is assumed to be in the current time zone, so that displayed items are consistent with the URL.
298 299 300 301 302 303 304 305 306 307 308 | def _make_date_lookup_arg(self, value):
"""
Convert a date into a datetime when the date field is a DateTimeField.
When time zone support is enabled, `date` is assumed to be in the
current time zone, so that displayed items are consistent with the URL.
"""
if self.uses_datetime_field:
value = datetime.datetime.combine(value, datetime.time.min)
if settings.USE_TZ:
value = timezone.make_aware(value, timezone.get_current_timezone())
return value
|
def
_make_single_date_lookup(self, date):
DateMixin
¶
def
_make_single_date_lookup(self, date):
DateMixin
¶
Get the lookup kwargs for filtering on a single date. If the date field is a DateTimeField, we can't just filter on date_field=date because that doesn't take the time into account.
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 | def _make_single_date_lookup(self, date):
"""
Get the lookup kwargs for filtering on a single date.
If the date field is a DateTimeField, we can't just filter on
date_field=date because that doesn't take the time into account.
"""
date_field = self.get_date_field()
if self.uses_datetime_field:
since = self._make_date_lookup_arg(date)
until = self._make_date_lookup_arg(date + datetime.timedelta(days=1))
return {
'%s__gte' % date_field: since,
'%s__lt' % date_field: until,
}
else:
# Skip self._make_date_lookup_arg, it's a no-op in this branch.
return {date_field: date}
|
def
get_allow_future(self):
DateMixin
¶
def
get_allow_future(self):
DateMixin
¶
Returns `True` if the view should be allowed to display objects from the future.
278 279 280 281 282 283 | def get_allow_future(self):
"""
Returns `True` if the view should be allowed to display objects from
the future.
"""
return self.allow_future
|
def
get_date_field(self):
DateMixin
¶
def
get_date_field(self):
DateMixin
¶
Get the name of the date field to be used to filter by.
270 271 272 273 274 275 276 | def get_date_field(self):
"""
Get the name of the date field to be used to filter by.
"""
if self.date_field is None:
raise ImproperlyConfigured("%s.date_field is required." % self.__class__.__name__)
return self.date_field
|