Upgraded the date based generic views to avoid warnings when time zone support is enabled.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17127 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
37b7f00fd0
commit
98b08bd4d4
|
@ -6,6 +6,7 @@ from django.core.exceptions import ObjectDoesNotExist
|
|||
from django.core.xheaders import populate_xheaders
|
||||
from django.db.models.fields import DateTimeField
|
||||
from django.http import Http404, HttpResponse
|
||||
from django.utils import timezone
|
||||
|
||||
import warnings
|
||||
warnings.warn(
|
||||
|
@ -31,7 +32,7 @@ def archive_index(request, queryset, date_field, num_latest=15,
|
|||
if extra_context is None: extra_context = {}
|
||||
model = queryset.model
|
||||
if not allow_future:
|
||||
queryset = queryset.filter(**{'%s__lte' % date_field: datetime.datetime.now()})
|
||||
queryset = queryset.filter(**{'%s__lte' % date_field: timezone.now()})
|
||||
date_list = queryset.dates(date_field, 'year')[::-1]
|
||||
if not date_list and not allow_empty:
|
||||
raise Http404("No %s available" % model._meta.verbose_name)
|
||||
|
@ -74,7 +75,7 @@ def archive_year(request, year, queryset, date_field, template_name=None,
|
|||
"""
|
||||
if extra_context is None: extra_context = {}
|
||||
model = queryset.model
|
||||
now = datetime.datetime.now()
|
||||
now = timezone.now()
|
||||
|
||||
lookup_kwargs = {'%s__year' % date_field: year}
|
||||
|
||||
|
@ -131,7 +132,7 @@ def archive_month(request, year, month, queryset, date_field,
|
|||
raise Http404
|
||||
|
||||
model = queryset.model
|
||||
now = datetime.datetime.now()
|
||||
now = timezone.now()
|
||||
|
||||
# Calculate first and last day of month, for use in a date-range lookup.
|
||||
first_day = date.replace(day=1)
|
||||
|
@ -205,7 +206,7 @@ def archive_week(request, year, week, queryset, date_field,
|
|||
raise Http404
|
||||
|
||||
model = queryset.model
|
||||
now = datetime.datetime.now()
|
||||
now = timezone.now()
|
||||
|
||||
# Calculate first and last day of week, for use in a date-range lookup.
|
||||
first_day = date
|
||||
|
@ -263,7 +264,7 @@ def archive_day(request, year, month, day, queryset, date_field,
|
|||
raise Http404
|
||||
|
||||
model = queryset.model
|
||||
now = datetime.datetime.now()
|
||||
now = timezone.now()
|
||||
|
||||
if isinstance(model._meta.get_field(date_field), DateTimeField):
|
||||
lookup_kwargs = {'%s__range' % date_field: (datetime.datetime.combine(date, datetime.time.min), datetime.datetime.combine(date, datetime.time.max))}
|
||||
|
@ -335,7 +336,7 @@ def object_detail(request, year, month, day, queryset, date_field,
|
|||
raise Http404
|
||||
|
||||
model = queryset.model
|
||||
now = datetime.datetime.now()
|
||||
now = timezone.now()
|
||||
|
||||
if isinstance(model._meta.get_field(date_field), DateTimeField):
|
||||
lookup_kwargs = {'%s__range' % date_field: (datetime.datetime.combine(date, datetime.time.min), datetime.datetime.combine(date, datetime.time.max))}
|
||||
|
|
|
@ -4,6 +4,7 @@ from django.core.exceptions import ImproperlyConfigured
|
|||
from django.http import Http404
|
||||
from django.utils.encoding import force_unicode
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.utils import timezone
|
||||
from django.views.generic.base import View
|
||||
from django.views.generic.detail import BaseDetailView, SingleObjectTemplateResponseMixin
|
||||
from django.views.generic.list import MultipleObjectMixin, MultipleObjectTemplateResponseMixin
|
||||
|
@ -191,7 +192,7 @@ class BaseDateListView(MultipleObjectMixin, DateMixin, View):
|
|||
allow_empty = self.get_allow_empty()
|
||||
|
||||
if not allow_future:
|
||||
qs = qs.filter(**{'%s__lte' % date_field: datetime.datetime.now()})
|
||||
qs = qs.filter(**{'%s__lte' % date_field: timezone.now()})
|
||||
|
||||
if not allow_empty and not qs:
|
||||
raise Http404(_(u"No %(verbose_name_plural)s available") % {
|
||||
|
|
Loading…
Reference in New Issue