Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit 795ac7deda64e67a059b489f8684bb440ca7f7ad 1 parent 501c7a2
Claude Paroz authored December 04, 2012
4  django/views/generic/edit.py
... ...
@@ -1,6 +1,7 @@
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)
@@ -50,7 +51,8 @@ def get_success_url(self):
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.")
9  tests/regressiontests/generic_views/edit.py
@@ -20,6 +20,15 @@ def test_initial_data(self):
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()
5  tests/regressiontests/generic_views/forms.py
@@ -11,3 +11,8 @@ 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)
4  tests/regressiontests/generic_views/tests.py
@@ -6,6 +6,6 @@
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
4  tests/regressiontests/generic_views/urls.py
@@ -56,6 +56,10 @@
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()),
11  tests/regressiontests/generic_views/views.py
@@ -2,11 +2,11 @@
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
 
@@ -75,6 +75,13 @@ def get_paginator(self, queryset, page_size, orphans=0, allow_empty_first_page=T
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
 

0 notes on commit 795ac7d

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