1
0
mirror of https://github.com/django/django.git synced 2025-10-24 14:16:09 +00:00

Fixed #23656 -- Made FormMixin.get_form's form_class argument optional.

Thanks Tim Graham for the review.
This commit is contained in:
Simon Charette
2014-10-14 14:56:39 -04:00
parent 19242c675f
commit f2ddc439b1
6 changed files with 93 additions and 11 deletions

View File

@@ -65,6 +65,9 @@ about each item can often be found in the release notes of two versions prior.
* The ``original_content_type_id`` attribute on
``django.contrib.admin.helpers.InlineAdminForm`` will be removed.
* The backwards compatibility shim to allow ``FormMixin.get_form()`` to be
defined with no default value for its ``form_class`` argument will be removed.
.. _deprecation-removed-in-1.9:
1.9

View File

@@ -49,10 +49,15 @@ FormMixin
Retrieve the form class to instantiate. By default
:attr:`.form_class`.
.. method:: get_form(form_class)
.. method:: get_form(form_class=None)
Instantiate an instance of ``form_class`` using
:meth:`~django.views.generic.edit.FormMixin.get_form_kwargs`.
If ``form_class`` isn't provided :meth:`get_form_class` will be used.
.. versionchanged:: 1.8
The ``form_class`` argument is not required anymore.
.. method:: get_form_kwargs()

View File

@@ -242,6 +242,10 @@ Generic Views
:meth:`~django.views.generic.detail.SingleObjectMixin.get_object()`
so that it'll perform its lookup using both the primary key and the slug.
* The :meth:`~django.views.generic.edit.FormMixin.get_form()` method doesn't
require a ``form_class`` to be provided anymore. If not provided ``form_class``
defaults to :meth:`~django.views.generic.edit.FormMixin.get_form_class()`.
Internationalization
^^^^^^^^^^^^^^^^^^^^
@@ -892,3 +896,10 @@ The ``original_content_type_id`` attribute on ``InlineAdminForm`` has been
deprecated and will be removed in Django 2.0. Historically, it was used
to construct the "view on site" URL. This URL is now accessible using the
``absolute_url`` attribute of the form.
``django.views.generic.edit.FormMixin.get_form()``s ``form_class`` argument
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
``FormMixin`` subclasses that override the ``get_form()`` method should make
sure to provide a default value for the ``form_class`` argument since it's
now optional.

View File

@@ -463,16 +463,14 @@ Our new ``AuthorDetail`` looks like this::
def get_context_data(self, **kwargs):
context = super(AuthorDetail, self).get_context_data(**kwargs)
form_class = self.get_form_class()
context['form'] = self.get_form(form_class)
context['form'] = self.get_form()
return context
def post(self, request, *args, **kwargs):
if not request.user.is_authenticated():
return HttpResponseForbidden()
self.object = self.get_object()
form_class = self.get_form_class()
form = self.get_form(form_class)
form = self.get_form()
if form.is_valid():
return self.form_valid(form)
else: