diff --git a/django/views/generic/edit.py b/django/views/generic/edit.py
index e51cdf5..97a6c0a 100644
a
|
b
|
|
1 | 1 | from django.forms import models as model_forms |
2 | 2 | from django.core.exceptions import ImproperlyConfigured |
3 | 3 | from django.http import HttpResponseRedirect |
| 4 | from django.utils.encoding import force_text |
4 | 5 | from django.views.generic.base import TemplateResponseMixin, ContextMixin, View |
5 | 6 | from django.views.generic.detail import (SingleObjectMixin, |
6 | 7 | SingleObjectTemplateResponseMixin, BaseDetailView) |
… |
… |
class FormMixin(ContextMixin):
|
50 | 51 | Returns the supplied success URL. |
51 | 52 | """ |
52 | 53 | if self.success_url: |
53 | | url = self.success_url |
| 54 | # Forcing possible reverse_lazy evaluation |
| 55 | url = force_text(self.success_url) |
54 | 56 | else: |
55 | 57 | raise ImproperlyConfigured( |
56 | 58 | "No URL to redirect to. Provide a success_url.") |
diff --git a/tests/regressiontests/generic_views/edit.py b/tests/regressiontests/generic_views/edit.py
index 16f4da8..0f1eb3c 100644
a
|
b
|
class FormMixinTests(TestCase):
|
20 | 20 | initial_2 = FormMixin().get_initial() |
21 | 21 | self.assertNotEqual(initial_1, initial_2) |
22 | 22 | |
| 23 | |
| 24 | class BasicFormTests(TestCase): |
| 25 | urls = 'regressiontests.generic_views.urls' |
| 26 | |
| 27 | def test_post_data(self): |
| 28 | res = self.client.post('/contact/', {'name': "Me", 'message': "Hello"}) |
| 29 | self.assertRedirects(res, 'http://testserver/list/authors/') |
| 30 | |
| 31 | |
23 | 32 | class ModelFormMixinTests(TestCase): |
24 | 33 | def test_get_form(self): |
25 | 34 | form_class = views.AuthorGetQuerySetFormView().get_form_class() |
diff --git a/tests/regressiontests/generic_views/forms.py b/tests/regressiontests/generic_views/forms.py
index a78242f..e036ad8 100644
a
|
b
|
class AuthorForm(forms.ModelForm):
|
11 | 11 | |
12 | 12 | class Meta: |
13 | 13 | model = Author |
| 14 | |
| 15 | |
| 16 | class ContactForm(forms.Form): |
| 17 | name = forms.CharField() |
| 18 | message = forms.CharField(widget=forms.Textarea) |
diff --git a/tests/regressiontests/generic_views/tests.py b/tests/regressiontests/generic_views/tests.py
index c985ad3..3f80600 100644
a
|
b
|
from .dates import (ArchiveIndexViewTests, YearArchiveViewTests,
|
6 | 6 | MonthArchiveViewTests, WeekArchiveViewTests, DayArchiveViewTests, |
7 | 7 | DateDetailViewTests) |
8 | 8 | from .detail import DetailViewTest |
9 | | from .edit import (FormMixinTests, ModelFormMixinTests, CreateViewTests, |
10 | | UpdateViewTests, DeleteViewTests) |
| 9 | from .edit import (FormMixinTests, BasicFormTests, ModelFormMixinTests, |
| 10 | CreateViewTests, UpdateViewTests, DeleteViewTests) |
11 | 11 | from .list import ListViewTests |
diff --git a/tests/regressiontests/generic_views/urls.py b/tests/regressiontests/generic_views/urls.py
index a212b83..9caf193 100644
a
|
b
|
urlpatterns = patterns('',
|
56 | 56 | (r'^detail/nonmodel/1/$', |
57 | 57 | views.NonModelDetail.as_view()), |
58 | 58 | |
| 59 | # FormView |
| 60 | (r'^contact/$', |
| 61 | views.ContactView.as_view()), |
| 62 | |
59 | 63 | # Create/UpdateView |
60 | 64 | (r'^edit/artists/create/$', |
61 | 65 | views.ArtistCreate.as_view()), |
diff --git a/tests/regressiontests/generic_views/views.py b/tests/regressiontests/generic_views/views.py
index f7fcf6f..71e78e8 100644
a
|
b
|
from __future__ import absolute_import
|
2 | 2 | |
3 | 3 | from django.contrib.auth.decorators import login_required |
4 | 4 | from django.core.paginator import Paginator |
5 | | from django.core.urlresolvers import reverse |
| 5 | from django.core.urlresolvers import reverse, reverse_lazy |
6 | 6 | from django.utils.decorators import method_decorator |
7 | 7 | from django.views import generic |
8 | 8 | |
9 | | from .forms import AuthorForm |
| 9 | from .forms import AuthorForm, ContactForm |
10 | 10 | from .models import Artist, Author, Book, Page, BookSigning |
11 | 11 | |
12 | 12 | |
… |
… |
class AuthorListCustomPaginator(AuthorList):
|
75 | 75 | orphans=2, |
76 | 76 | allow_empty_first_page=allow_empty_first_page) |
77 | 77 | |
| 78 | |
| 79 | class ContactView(generic.FormView): |
| 80 | form_class = ContactForm |
| 81 | success_url = reverse_lazy('authors_list') |
| 82 | template_name = 'generic_views/form.html' |
| 83 | |
| 84 | |
78 | 85 | class ArtistCreate(generic.CreateView): |
79 | 86 | model = Artist |
80 | 87 | |