Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #15287 -- Added translation markers to user-facing error messag…

…es in class-based generic views. Thanks to szczav for the report and draft patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@15533 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 72e4a6865d36f8885e7a35ca8de8fe6d1ec3ff18 1 parent bb26c32
@freakboy3742 freakboy3742 authored
View
31 django/views/generic/dates.py
@@ -3,11 +3,12 @@
from django.db import models
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.views.generic.base import View
from django.views.generic.detail import BaseDetailView, SingleObjectTemplateResponseMixin
from django.views.generic.list import MultipleObjectMixin, MultipleObjectTemplateResponseMixin
-
class YearMixin(object):
year_format = '%Y'
year = None
@@ -29,7 +30,7 @@ def get_year(self):
try:
year = self.request.GET['year']
except KeyError:
- raise Http404("No year specified")
+ raise Http404(_(u"No year specified"))
return year
@@ -54,7 +55,7 @@ def get_month(self):
try:
month = self.request.GET['month']
except KeyError:
- raise Http404("No month specified")
+ raise Http404(_(u"No month specified"))
return month
def get_next_month(self, date):
@@ -95,7 +96,7 @@ def get_day(self):
try:
day = self.request.GET['day']
except KeyError:
- raise Http404("No day specified")
+ raise Http404(_(u"No day specified"))
return day
def get_next_day(self, date):
@@ -134,7 +135,7 @@ def get_week(self):
try:
week = self.request.GET['week']
except KeyError:
- raise Http404("No week specified")
+ raise Http404(_(u"No week specified"))
return week
@@ -194,7 +195,9 @@ def get_dated_queryset(self, **lookup):
qs = qs.filter(**{'%s__lte' % date_field: datetime.datetime.now()})
if not allow_empty and not qs:
- raise Http404(u"No %s available" % unicode(qs.model._meta.verbose_name_plural))
+ raise Http404(_(u"No %(verbose_name_plural)s available") % {
+ 'verbose_name_plural': force_unicode(qs.model._meta.verbose_name_plural)
+ })
return qs
@@ -208,7 +211,9 @@ def get_date_list(self, queryset, date_type):
date_list = queryset.dates(date_field, date_type)[::-1]
if date_list is not None and not date_list and not allow_empty:
- raise Http404(u"No %s available" % unicode(qs.model._meta.verbose_name_plural))
+ raise Http404(_(u"No %(verbose_name_plural)s available") % {
+ 'verbose_name_plural': force_unicode(qs.model._meta.verbose_name_plural)
+ })
return date_list
@@ -458,9 +463,10 @@ def get_object(self, queryset=None):
qs = self.get_queryset()
if not self.get_allow_future() and date > datetime.date.today():
- raise Http404("Future %s not available because %s.allow_future is False." % (
- qs.model._meta.verbose_name_plural, self.__class__.__name__)
- )
+ raise Http404(_(u"Future %(verbose_name_plural)s not available because %(class_name)s.allow_future is False.") % {
+ 'verbose_name_plural': qs.model._meta.verbose_name_plural,
+ 'class_name': self.__class__.__name__,
+ })
# Filter down a queryset from self.queryset using the date from the
# URL. This'll get passed as the queryset to DetailView.get_object,
@@ -491,7 +497,10 @@ def _date_from_string(year, year_format, month, month_format, day='', day_format
try:
return datetime.date(*time.strptime(datestr, format)[:3])
except ValueError:
- raise Http404(u"Invalid date string '%s' given format '%s'" % (datestr, format))
+ raise Http404(_(u"Invalid date string '%(datestr)s' given format '%(format)s'") % {
+ 'datestr': datestr,
+ 'format': format,
+ })
def _month_bounds(date):
View
5 django/views/generic/detail.py
@@ -3,6 +3,7 @@
from django.core.exceptions import ImproperlyConfigured, ObjectDoesNotExist
from django.http import Http404
from django.utils.encoding import smart_str
+from django.utils.translation import ugettext as _
from django.views.generic.base import TemplateResponseMixin, View
@@ -47,8 +48,8 @@ def get_object(self, queryset=None):
try:
obj = queryset.get()
except ObjectDoesNotExist:
- raise Http404(u"No %s found matching the query" %
- (queryset.model._meta.verbose_name))
+ raise Http404(_(u"No %(verbose_name)s found matching the query") %
+ {'verbose_name': queryset.model._meta.verbose_name})
return obj
def get_queryset(self):
View
11 django/views/generic/list.py
@@ -4,6 +4,7 @@
from django.core.exceptions import ImproperlyConfigured
from django.http import Http404
from django.utils.encoding import smart_str
+from django.utils.translation import ugettext as _
from django.views.generic.base import TemplateResponseMixin, View
@@ -43,12 +44,14 @@ def paginate_queryset(self, queryset, page_size):
if page == 'last':
page_number = paginator.num_pages
else:
- raise Http404("Page is not 'last', nor can it be converted to an int.")
+ raise Http404(_(u"Page is not 'last', nor can it be converted to an int."))
try:
page = paginator.page(page_number)
return (paginator, page, page.object_list, True)
except InvalidPage:
- raise Http404(u'Invalid page (%s)' % page_number)
+ raise Http404(_(u'Invalid page (%(page_number)s)') % {
+ 'page_number': page_number
+ })
def get_paginate_by(self, queryset):
"""
@@ -113,8 +116,8 @@ def get(self, request, *args, **kwargs):
self.object_list = self.get_queryset()
allow_empty = self.get_allow_empty()
if not allow_empty and len(self.object_list) == 0:
- raise Http404(u"Empty list and '%s.allow_empty' is False."
- % self.__class__.__name__)
+ raise Http404(_(u"Empty list and '%(class_name)s.allow_empty' is False.")
+ % {'class_name': self.__class__.__name__})
context = self.get_context_data(object_list=self.object_list)
return self.render_to_response(context)
Please sign in to comment.
Something went wrong with that request. Please try again.