Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Coerced all exception messages to unicode (thanks josesoa!)

  • Loading branch information...
commit 74908348adddf25badaee4cb3824d5e4c8daf33c 1 parent 127612d
@bfirsh authored
View
8 class_based_views/base.py
@@ -31,13 +31,13 @@ def __init__(self, *args, **kwargs):
# instance, or raise an error.
for key, value in kwargs.items():
if key in self.method_names:
- raise TypeError("You tried to pass in the %s method name as a "
- "keyword argument to %s(). Don't do that."
+ raise TypeError(u"You tried to pass in the %s method name as a "
+ u"keyword argument to %s(). Don't do that."
% (key, self.__class__.__name__))
if hasattr(self, key):
setattr(self, key, value)
else:
- raise TypeError("%s() received an invalid keyword %r" % (
+ raise TypeError(u"%s() received an invalid keyword %r" % (
self.__class__.__name__,
key,
))
@@ -107,7 +107,7 @@ def get_template(self, names=None):
if names is None:
names = self.get_template_names()
if not names:
- raise ImproperlyConfigured("'%s' must provide template_name."
+ raise ImproperlyConfigured(u"'%s' must provide template_name."
% self.__class__.__name__)
if isinstance(names, basestring):
names = [names]
View
30 class_based_views/dates.py
@@ -25,9 +25,9 @@ def get_queryset(self):
`get_dated_items` is overridden.
"""
if self.queryset is None:
- raise ImproperlyConfigured("%(cls)s is missing a queryset. Define "\
- "%(cls)s.queryset, or override "\
- "%(cls)s.get_dated_items()." \
+ raise ImproperlyConfigured(u"%(cls)s is missing a queryset. Define "
+ u"%(cls)s.queryset, or override "
+ u"%(cls)s.get_dated_items()."
% {'cls': self.__class__.__name__})
return self.queryset._clone()
@@ -45,8 +45,8 @@ def get_dated_queryset(self, allow_future=False, **lookup):
qs = qs.filter(**{'%s__lte' % date_field: datetime.datetime.now()})
if not allow_empty and not qs:
- raise Http404("No %s available" % qs.model._meta.verbose_name_plural)
-
+ raise Http404(u"No %s available"
+ % qs.model._meta.verbose_name_plural)
return qs
def get_date_list(self, queryset, date_type):
@@ -59,7 +59,8 @@ 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("No %s available" % queryset.model._meta.verbose_name_plural)
+ raise Http404(u"No %s available"
+ % queryset.model._meta.verbose_name_plural)
return date_list
@@ -68,7 +69,8 @@ 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__)
+ raise ImproperlyConfigured(u"%s.date_field is required."
+ % self.__class__.__name__)
return self.date_field
def get_allow_future(self):
@@ -91,7 +93,10 @@ def get_template_names(self, items):
Return a list of template names to be used for the request. Must return
a list. May not be called if get_template is overridden.
"""
- return super(DateView, self).get_template_names(items, suffix=self._template_name_suffix)
+ return super(DateView, self).get_template_names(
+ items,
+ suffix=self._template_name_suffix
+ )
def get_dated_items(self, *args, **kwargs):
"""
@@ -355,8 +360,8 @@ def get_object(self, year, month, day, pk=None, slug=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."
+ raise Http404(u"Future %s not available because %s.allow_future is "
+ u"False."
% (qs.model._meta.verbose_name_plural, self.__class__.__name__))
# Filter down a queryset from self.queryset using the date from the
@@ -374,7 +379,7 @@ 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."
+ raise ImproperlyConfigured(u"%s.date_field is required."
% self.__class__.__name__)
return self.date_field
@@ -409,7 +414,8 @@ 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("Invalid date string '%s' given format '%s'" % (datestr, format))
+ raise Http404(u"Invalid date string '%s' given format '%s'"
+ % (datestr, format))
def _month_bounds(date):
"""
View
14 class_based_views/detail.py
@@ -34,15 +34,15 @@ def get_object(self, pk=None, slug=None, queryset=None):
# If none of those are defined, it's an error.
else:
- raise AttributeError("Generic detail view %s must be called with "\
- "either an object id or a slug." \
+ raise AttributeError(u"Generic detail view %s must be called with "
+ u"either an object id or a slug."
% self.__class__.__name__)
try:
obj = queryset.get()
except ObjectDoesNotExist:
- raise Http404("No %s found matching the query" % \
- (queryset.model._meta.verbose_name))
+ raise Http404(u"No %s found matching the query"
+ % (queryset.model._meta.verbose_name))
return obj
def get_queryset(self):
@@ -51,9 +51,9 @@ def get_queryset(self):
`get_object` is overridden.
"""
if self.queryset is None:
- raise ImproperlyConfigured("%(cls)s is missing a queryset. Define "\
- "%(cls)s.queryset, or override "\
- "%(cls)s.get_object()." % {
+ raise ImproperlyConfigured(u"%(cls)s is missing a queryset. Define "
+ u"%(cls)s.queryset, or override "\
+ u"%(cls)s.get_object()." % {
'cls': self.__class__.__name__
})
return self.queryset._clone()
View
6 class_based_views/list.py
@@ -17,7 +17,7 @@ def GET(self, request, *args, **kwargs):
queryset = self.get_queryset()
allow_empty = self.get_allow_empty()
if not allow_empty and len(queryset) == 0:
- raise Http404("Empty list and '%s.allow_empty' is False."
+ raise Http404(u"Empty list and '%s.allow_empty' is False."
% self.__class__.__name__)
context = self.get_context(queryset)
return self.render_to_response(self.get_template_names(queryset), context)
@@ -42,12 +42,12 @@ def get_queryset(self):
if hasattr(self, 'queryset') and self.queryset is not None:
queryset = self.queryset
else:
- raise ImproperlyConfigured("'%s' must define 'queryset'"
+ raise ImproperlyConfigured(u"'%s' must define 'queryset'"
% self.__class__.__name__)
if hasattr(queryset, '_clone'):
queryset = queryset._clone()
return queryset
-
+
def get_allow_empty(self):
"""
Returns ``True`` if the view should display empty lists, and ``False``

0 comments on commit 7490834

Please sign in to comment.
Something went wrong with that request. Please try again.