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

[1.5.x] Fixed #19378 -- Ensured get_success_url returns a non-lazy URL

Backport of 795ac7deda from master.
This commit is contained in:
Claude Paroz
2012-12-04 13:18:57 +01:00
parent 237a404d3e
commit 7fea7cf5d7
6 changed files with 32 additions and 5 deletions

View File

@@ -20,6 +20,15 @@ class FormMixinTests(TestCase):
initial_2 = FormMixin().get_initial()
self.assertNotEqual(initial_1, initial_2)
class BasicFormTests(TestCase):
urls = 'regressiontests.generic_views.urls'
def test_post_data(self):
res = self.client.post('/contact/', {'name': "Me", 'message': "Hello"})
self.assertRedirects(res, 'http://testserver/list/authors/')
class ModelFormMixinTests(TestCase):
def test_get_form(self):
form_class = views.AuthorGetQuerySetFormView().get_form_class()

View File

@@ -11,3 +11,8 @@ class AuthorForm(forms.ModelForm):
class Meta:
model = Author
class ContactForm(forms.Form):
name = forms.CharField()
message = forms.CharField(widget=forms.Textarea)

View File

@@ -6,6 +6,6 @@ from .dates import (ArchiveIndexViewTests, YearArchiveViewTests,
MonthArchiveViewTests, WeekArchiveViewTests, DayArchiveViewTests,
DateDetailViewTests)
from .detail import DetailViewTest
from .edit import (FormMixinTests, ModelFormMixinTests, CreateViewTests,
UpdateViewTests, DeleteViewTests)
from .edit import (FormMixinTests, BasicFormTests, ModelFormMixinTests,
CreateViewTests, UpdateViewTests, DeleteViewTests)
from .list import ListViewTests

View File

@@ -56,6 +56,10 @@ urlpatterns = patterns('',
(r'^detail/nonmodel/1/$',
views.NonModelDetail.as_view()),
# FormView
(r'^contact/$',
views.ContactView.as_view()),
# Create/UpdateView
(r'^edit/artists/create/$',
views.ArtistCreate.as_view()),

View File

@@ -2,11 +2,11 @@ from __future__ import absolute_import
from django.contrib.auth.decorators import login_required
from django.core.paginator import Paginator
from django.core.urlresolvers import reverse
from django.core.urlresolvers import reverse, reverse_lazy
from django.utils.decorators import method_decorator
from django.views import generic
from .forms import AuthorForm
from .forms import AuthorForm, ContactForm
from .models import Artist, Author, Book, Page, BookSigning
@@ -75,6 +75,13 @@ class AuthorListCustomPaginator(AuthorList):
orphans=2,
allow_empty_first_page=allow_empty_first_page)
class ContactView(generic.FormView):
form_class = ContactForm
success_url = reverse_lazy('authors_list')
template_name = 'generic_views/form.html'
class ArtistCreate(generic.CreateView):
model = Artist