Loading AUTHORS +1 −0 Original line number Diff line number Diff line Loading @@ -249,6 +249,7 @@ answer newbie questions, and generally made Django that much better: martin.glueck@gmail.com Ben Godfrey <http://aftnn.org> GomoX <gomo@datafull.com> Gil Gonçalves <lursty@gmail.com> Guilherme Mesquita Gondim <semente@taurinus.org> Mario Gonzalez <gonzalemario@gmail.com> David Gouldin <dgouldin@gmail.com> Loading django/views/generic/edit.py +12 −1 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ class FormMixin(ContextMixin): initial = {} form_class = None success_url = None prefix = None def get_initial(self): """ Loading @@ -24,6 +25,12 @@ class FormMixin(ContextMixin): """ return self.initial.copy() def get_prefix(self): """ Returns the prefix to use for forms on this view """ return self.prefix def get_form_class(self): """ Returns the form class to use in this view Loading @@ -40,7 +47,11 @@ class FormMixin(ContextMixin): """ Returns the keyword arguments for instantiating the form. """ kwargs = {'initial': self.get_initial()} kwargs = { 'initial': self.get_initial(), 'prefix': self.get_prefix(), } if self.request.method in ('POST', 'PUT'): kwargs.update({ 'data': self.request.POST, Loading docs/ref/class-based-views/mixins-editing.txt +4 −0 Original line number Diff line number Diff line Loading @@ -35,6 +35,10 @@ FormMixin The URL to redirect to when the form is successfully processed. .. attribute:: prefix Sets the :attr:`~django.forms.Form.prefix` for the generated form. .. method:: get_initial() Retrieve initial data for the form. By default, returns a copy of Loading docs/releases/1.6.txt +3 −0 Original line number Diff line number Diff line Loading @@ -731,6 +731,9 @@ Miscellaneous of the admin views. You should update your custom templates if they use the previous parameter name. * Added :attr:`~django.views.generic.edit.FormMixin.prefix` to allow you to customize the prefix on the form. Features deprecated in 1.6 ========================== Loading tests/generic_views/test_edit.py +20 −1 Original line number Diff line number Diff line Loading @@ -7,8 +7,9 @@ from django.core.urlresolvers import reverse from django import forms from django.test import TestCase from django.utils.unittest import expectedFailure from django.test.client import RequestFactory from django.views.generic.base import View from django.views.generic.edit import FormMixin, CreateView, UpdateView from django.views.generic.edit import FormMixin, CreateView from . import views from .models import Artist, Author Loading @@ -22,6 +23,24 @@ class FormMixinTests(TestCase): initial_2 = FormMixin().get_initial() self.assertNotEqual(initial_1, initial_2) def test_get_prefix(self): """ Test prefix can be set (see #18872) """ test_string = 'test' rf = RequestFactory() get_request = rf.get('/') class TestFormMixin(FormMixin): request = get_request default_kwargs = TestFormMixin().get_form_kwargs() self.assertEqual(None, default_kwargs.get('prefix')) set_mixin = TestFormMixin() set_mixin.prefix = test_string set_kwargs = set_mixin.get_form_kwargs() self.assertEqual(test_string, set_kwargs.get('prefix')) class BasicFormTests(TestCase): urls = 'generic_views.urls' Loading Loading
AUTHORS +1 −0 Original line number Diff line number Diff line Loading @@ -249,6 +249,7 @@ answer newbie questions, and generally made Django that much better: martin.glueck@gmail.com Ben Godfrey <http://aftnn.org> GomoX <gomo@datafull.com> Gil Gonçalves <lursty@gmail.com> Guilherme Mesquita Gondim <semente@taurinus.org> Mario Gonzalez <gonzalemario@gmail.com> David Gouldin <dgouldin@gmail.com> Loading
django/views/generic/edit.py +12 −1 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ class FormMixin(ContextMixin): initial = {} form_class = None success_url = None prefix = None def get_initial(self): """ Loading @@ -24,6 +25,12 @@ class FormMixin(ContextMixin): """ return self.initial.copy() def get_prefix(self): """ Returns the prefix to use for forms on this view """ return self.prefix def get_form_class(self): """ Returns the form class to use in this view Loading @@ -40,7 +47,11 @@ class FormMixin(ContextMixin): """ Returns the keyword arguments for instantiating the form. """ kwargs = {'initial': self.get_initial()} kwargs = { 'initial': self.get_initial(), 'prefix': self.get_prefix(), } if self.request.method in ('POST', 'PUT'): kwargs.update({ 'data': self.request.POST, Loading
docs/ref/class-based-views/mixins-editing.txt +4 −0 Original line number Diff line number Diff line Loading @@ -35,6 +35,10 @@ FormMixin The URL to redirect to when the form is successfully processed. .. attribute:: prefix Sets the :attr:`~django.forms.Form.prefix` for the generated form. .. method:: get_initial() Retrieve initial data for the form. By default, returns a copy of Loading
docs/releases/1.6.txt +3 −0 Original line number Diff line number Diff line Loading @@ -731,6 +731,9 @@ Miscellaneous of the admin views. You should update your custom templates if they use the previous parameter name. * Added :attr:`~django.views.generic.edit.FormMixin.prefix` to allow you to customize the prefix on the form. Features deprecated in 1.6 ========================== Loading
tests/generic_views/test_edit.py +20 −1 Original line number Diff line number Diff line Loading @@ -7,8 +7,9 @@ from django.core.urlresolvers import reverse from django import forms from django.test import TestCase from django.utils.unittest import expectedFailure from django.test.client import RequestFactory from django.views.generic.base import View from django.views.generic.edit import FormMixin, CreateView, UpdateView from django.views.generic.edit import FormMixin, CreateView from . import views from .models import Artist, Author Loading @@ -22,6 +23,24 @@ class FormMixinTests(TestCase): initial_2 = FormMixin().get_initial() self.assertNotEqual(initial_1, initial_2) def test_get_prefix(self): """ Test prefix can be set (see #18872) """ test_string = 'test' rf = RequestFactory() get_request = rf.get('/') class TestFormMixin(FormMixin): request = get_request default_kwargs = TestFormMixin().get_form_kwargs() self.assertEqual(None, default_kwargs.get('prefix')) set_mixin = TestFormMixin() set_mixin.prefix = test_string set_kwargs = set_mixin.get_form_kwargs() self.assertEqual(test_string, set_kwargs.get('prefix')) class BasicFormTests(TestCase): urls = 'generic_views.urls' Loading