From 461f01b7a66a1d12cebf786892baccb6cee2e6c1 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Thu, 27 Jan 2011 03:14:20 +0000 Subject: [PATCH] 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 --- django/views/generic/base.py | 1 + django/views/generic/dates.py | 11 ++++------- django/views/generic/edit.py | 6 +++--- django/views/generic/list.py | 2 ++ 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/django/views/generic/base.py b/django/views/generic/base.py index 5e69a8dd30..7f60ff0773 100644 --- a/django/views/generic/base.py +++ b/django/views/generic/base.py @@ -8,6 +8,7 @@ from django.utils.decorators import classonlymethod logger = getLogger('django.request') + class View(object): """ Intentionally simple parent class for all views. Only implements diff --git a/django/views/generic/dates.py b/django/views/generic/dates.py index c9e486b8cf..2dd8883fa0 100644 --- a/django/views/generic/dates.py +++ b/django/views/generic/dates.py @@ -212,8 +212,6 @@ class BaseDateListView(MultipleObjectMixin, DateMixin, View): return date_list - - def get_context_data(self, **kwargs): """ 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') if date_list: - object_list = qs.order_by('-'+self.get_date_field()) + object_list = qs.order_by('-' + self.get_date_field()) else: object_list = qs.none() @@ -327,7 +325,6 @@ class BaseMonthArchiveView(YearMixin, MonthMixin, BaseDateListView): }) - class MonthArchiveView(MultipleObjectTemplateResponseMixin, BaseMonthArchiveView): """ List of objects published in a given year. @@ -416,7 +413,6 @@ class BaseDayArchiveView(YearMixin, MonthMixin, DayMixin, BaseDateListView): }) - class DayArchiveView(MultipleObjectTemplateResponseMixin, BaseDayArchiveView): """ 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) - class DateDetailView(SingleObjectTemplateResponseMixin, BaseDateDetailView): """ 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: raise Http404(u"Invalid date string '%s' given format '%s'" % (datestr, format)) + def _month_bounds(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 + 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 @@ -582,6 +579,7 @@ def _get_next_prev_month(generic_view, naive_result, is_previous, use_first_day) else: return None + def _date_lookup_for_field(field, date): """ 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} else: return {field.name: date} - diff --git a/django/views/generic/edit.py b/django/views/generic/edit.py index 931a2d3fe2..33a312709d 100644 --- a/django/views/generic/edit.py +++ b/django/views/generic/edit.py @@ -102,9 +102,6 @@ class ModelFormMixin(FormMixin, SingleObjectMixin): self.object = form.save() 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): context = kwargs if self.object: @@ -169,6 +166,7 @@ class BaseCreateView(ModelFormMixin, ProcessFormView): def put(self, *args, **kwargs): return self.post(*args, **kwargs) + class CreateView(SingleObjectTemplateResponseMixin, BaseCreateView): """ View for creating an new object instance, @@ -227,6 +225,7 @@ class DeletionMixin(object): raise ImproperlyConfigured( "No URL to redirect to. Provide a success_url.") + class BaseDeleteView(DeletionMixin, BaseDetailView): """ 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. """ + class DeleteView(SingleObjectTemplateResponseMixin, BaseDeleteView): """ View for deleting an object retrieved with `self.get_object()`, diff --git a/django/views/generic/list.py b/django/views/generic/list.py index 7b817a5f02..9f1c8aab29 100644 --- a/django/views/generic/list.py +++ b/django/views/generic/list.py @@ -119,6 +119,7 @@ class BaseListView(MultipleObjectMixin, View): context = self.get_context_data(object_list=self.object_list) return self.render_to_response(context) + class MultipleObjectTemplateResponseMixin(TemplateResponseMixin): template_name_suffix = '_list' @@ -139,6 +140,7 @@ class MultipleObjectTemplateResponseMixin(TemplateResponseMixin): return names + class ListView(MultipleObjectTemplateResponseMixin, BaseListView): """ Render some list of objects, set by `self.model` or `self.queryset`.