Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #19378 -- Ensured get_success_url returns a non-lazy URL

  • Loading branch information...
commit 795ac7deda64e67a059b489f8684bb440ca7f7ad 1 parent 501c7a2
@claudep claudep authored
View
4 django/views/generic/edit.py
@@ -1,6 +1,7 @@
from django.forms import models as model_forms
from django.core.exceptions import ImproperlyConfigured
from django.http import HttpResponseRedirect
+from django.utils.encoding import force_text
from django.views.generic.base import TemplateResponseMixin, ContextMixin, View
from django.views.generic.detail import (SingleObjectMixin,
SingleObjectTemplateResponseMixin, BaseDetailView)
@@ -50,7 +51,8 @@ def get_success_url(self):
Returns the supplied success URL.
"""
if self.success_url:
- url = self.success_url
+ # Forcing possible reverse_lazy evaluation
+ url = force_text(self.success_url)
else:
raise ImproperlyConfigured(
"No URL to redirect to. Provide a success_url.")
View
9 tests/regressiontests/generic_views/edit.py
@@ -20,6 +20,15 @@ def test_initial_data(self):
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
5 tests/regressiontests/generic_views/forms.py
@@ -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
4 tests/regressiontests/generic_views/tests.py
@@ -6,6 +6,6 @@
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
4 tests/regressiontests/generic_views/urls.py
@@ -56,6 +56,10 @@
(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
11 tests/regressiontests/generic_views/views.py
@@ -2,11 +2,11 @@
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 @@ def get_paginator(self, queryset, page_size, orphans=0, allow_empty_first_page=T
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

0 comments on commit 795ac7d

Please sign in to comment.
Something went wrong with that request. Please try again.