Fixed #15061 -- Removed a redundant method implementation in the class-based ModelFormMixin, and did some PEP8 cleanup. Thanks to rasca for the report and patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15341 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
1f5309a99e
commit
461f01b7a6
|
@ -8,6 +8,7 @@ from django.utils.decorators import classonlymethod
|
||||||
|
|
||||||
logger = getLogger('django.request')
|
logger = getLogger('django.request')
|
||||||
|
|
||||||
|
|
||||||
class View(object):
|
class View(object):
|
||||||
"""
|
"""
|
||||||
Intentionally simple parent class for all views. Only implements
|
Intentionally simple parent class for all views. Only implements
|
||||||
|
|
|
@ -212,8 +212,6 @@ class BaseDateListView(MultipleObjectMixin, DateMixin, View):
|
||||||
|
|
||||||
return date_list
|
return date_list
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
"""
|
"""
|
||||||
Get the context. Must return a Context (or subclass) instance.
|
Get the context. Must return a Context (or subclass) instance.
|
||||||
|
@ -240,7 +238,7 @@ class BaseArchiveIndexView(BaseDateListView):
|
||||||
date_list = self.get_date_list(qs, 'year')
|
date_list = self.get_date_list(qs, 'year')
|
||||||
|
|
||||||
if date_list:
|
if date_list:
|
||||||
object_list = qs.order_by('-'+self.get_date_field())
|
object_list = qs.order_by('-' + self.get_date_field())
|
||||||
else:
|
else:
|
||||||
object_list = qs.none()
|
object_list = qs.none()
|
||||||
|
|
||||||
|
@ -327,7 +325,6 @@ class BaseMonthArchiveView(YearMixin, MonthMixin, BaseDateListView):
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class MonthArchiveView(MultipleObjectTemplateResponseMixin, BaseMonthArchiveView):
|
class MonthArchiveView(MultipleObjectTemplateResponseMixin, BaseMonthArchiveView):
|
||||||
"""
|
"""
|
||||||
List of objects published in a given year.
|
List of objects published in a given year.
|
||||||
|
@ -416,7 +413,6 @@ class BaseDayArchiveView(YearMixin, MonthMixin, DayMixin, BaseDateListView):
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class DayArchiveView(MultipleObjectTemplateResponseMixin, BaseDayArchiveView):
|
class DayArchiveView(MultipleObjectTemplateResponseMixin, BaseDayArchiveView):
|
||||||
"""
|
"""
|
||||||
List of objects published on a given day.
|
List of objects published on a given day.
|
||||||
|
@ -477,7 +473,6 @@ class BaseDateDetailView(YearMixin, MonthMixin, DayMixin, DateMixin, BaseDetailV
|
||||||
return super(BaseDetailView, self).get_object(queryset=qs)
|
return super(BaseDetailView, self).get_object(queryset=qs)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class DateDetailView(SingleObjectTemplateResponseMixin, BaseDateDetailView):
|
class DateDetailView(SingleObjectTemplateResponseMixin, BaseDateDetailView):
|
||||||
"""
|
"""
|
||||||
Detail view of a single object on a single date; this differs from the
|
Detail view of a single object on a single date; this differs from the
|
||||||
|
@ -498,6 +493,7 @@ def _date_from_string(year, year_format, month, month_format, day='', day_format
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise Http404(u"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):
|
def _month_bounds(date):
|
||||||
"""
|
"""
|
||||||
Helper: return the first and last days of the month for the given date.
|
Helper: return the first and last days of the month for the given date.
|
||||||
|
@ -510,6 +506,7 @@ def _month_bounds(date):
|
||||||
|
|
||||||
return first_day, last_day
|
return first_day, last_day
|
||||||
|
|
||||||
|
|
||||||
def _get_next_prev_month(generic_view, naive_result, is_previous, use_first_day):
|
def _get_next_prev_month(generic_view, naive_result, is_previous, use_first_day):
|
||||||
"""
|
"""
|
||||||
Helper: Get the next or the previous valid date. The idea is to allow
|
Helper: Get the next or the previous valid date. The idea is to allow
|
||||||
|
@ -582,6 +579,7 @@ def _get_next_prev_month(generic_view, naive_result, is_previous, use_first_day)
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def _date_lookup_for_field(field, date):
|
def _date_lookup_for_field(field, date):
|
||||||
"""
|
"""
|
||||||
Get the lookup kwargs for looking up a date against a given Field. If the
|
Get the lookup kwargs for looking up a date against a given Field. If the
|
||||||
|
@ -597,4 +595,3 @@ def _date_lookup_for_field(field, date):
|
||||||
return {'%s__range' % field.name: date_range}
|
return {'%s__range' % field.name: date_range}
|
||||||
else:
|
else:
|
||||||
return {field.name: date}
|
return {field.name: date}
|
||||||
|
|
||||||
|
|
|
@ -102,9 +102,6 @@ class ModelFormMixin(FormMixin, SingleObjectMixin):
|
||||||
self.object = form.save()
|
self.object = form.save()
|
||||||
return super(ModelFormMixin, self).form_valid(form)
|
return super(ModelFormMixin, self).form_valid(form)
|
||||||
|
|
||||||
def form_invalid(self, form):
|
|
||||||
return self.render_to_response(self.get_context_data(form=form))
|
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = kwargs
|
context = kwargs
|
||||||
if self.object:
|
if self.object:
|
||||||
|
@ -169,6 +166,7 @@ class BaseCreateView(ModelFormMixin, ProcessFormView):
|
||||||
def put(self, *args, **kwargs):
|
def put(self, *args, **kwargs):
|
||||||
return self.post(*args, **kwargs)
|
return self.post(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class CreateView(SingleObjectTemplateResponseMixin, BaseCreateView):
|
class CreateView(SingleObjectTemplateResponseMixin, BaseCreateView):
|
||||||
"""
|
"""
|
||||||
View for creating an new object instance,
|
View for creating an new object instance,
|
||||||
|
@ -227,6 +225,7 @@ class DeletionMixin(object):
|
||||||
raise ImproperlyConfigured(
|
raise ImproperlyConfigured(
|
||||||
"No URL to redirect to. Provide a success_url.")
|
"No URL to redirect to. Provide a success_url.")
|
||||||
|
|
||||||
|
|
||||||
class BaseDeleteView(DeletionMixin, BaseDetailView):
|
class BaseDeleteView(DeletionMixin, BaseDetailView):
|
||||||
"""
|
"""
|
||||||
Base view for deleting an object.
|
Base view for deleting an object.
|
||||||
|
@ -234,6 +233,7 @@ class BaseDeleteView(DeletionMixin, BaseDetailView):
|
||||||
Using this base class requires subclassing to provide a response mixin.
|
Using this base class requires subclassing to provide a response mixin.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
class DeleteView(SingleObjectTemplateResponseMixin, BaseDeleteView):
|
class DeleteView(SingleObjectTemplateResponseMixin, BaseDeleteView):
|
||||||
"""
|
"""
|
||||||
View for deleting an object retrieved with `self.get_object()`,
|
View for deleting an object retrieved with `self.get_object()`,
|
||||||
|
|
|
@ -119,6 +119,7 @@ class BaseListView(MultipleObjectMixin, View):
|
||||||
context = self.get_context_data(object_list=self.object_list)
|
context = self.get_context_data(object_list=self.object_list)
|
||||||
return self.render_to_response(context)
|
return self.render_to_response(context)
|
||||||
|
|
||||||
|
|
||||||
class MultipleObjectTemplateResponseMixin(TemplateResponseMixin):
|
class MultipleObjectTemplateResponseMixin(TemplateResponseMixin):
|
||||||
template_name_suffix = '_list'
|
template_name_suffix = '_list'
|
||||||
|
|
||||||
|
@ -139,6 +140,7 @@ class MultipleObjectTemplateResponseMixin(TemplateResponseMixin):
|
||||||
|
|
||||||
return names
|
return names
|
||||||
|
|
||||||
|
|
||||||
class ListView(MultipleObjectTemplateResponseMixin, BaseListView):
|
class ListView(MultipleObjectTemplateResponseMixin, BaseListView):
|
||||||
"""
|
"""
|
||||||
Render some list of objects, set by `self.model` or `self.queryset`.
|
Render some list of objects, set by `self.model` or `self.queryset`.
|
||||||
|
|
Loading…
Reference in New Issue