mirror of https://github.com/django/django.git
Fixed #19378 -- Ensured get_success_url returns a non-lazy URL
This commit is contained in:
parent
501c7a221c
commit
795ac7deda
|
@ -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 @@ class FormMixin(ContextMixin):
|
|||
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.")
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()),
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue