Commits

Thom Linton committed 91a631b

The 'direct_to_template' shortcut has been removed in Django 1.5: refactor URLconf to use 'TemplateView'.

Comments (0)

Files changed (4)

registration/backends/default/urls.py

 
 
 from django.conf.urls.defaults import *
-from django.views.generic.simple import direct_to_template
 
-from registration.views import activate
-from registration.views import register
+from registration import views
 
 
 urlpatterns = patterns('',
                        url(r'^activate/complete/$',
-                           direct_to_template,
-                           {'template': 'registration/activation_complete.html'},
+                           views.ActivationCompleteView.as_view(),
                            name='registration_activation_complete'),
                        # Activation keys get matched by \w+ instead of the more specific
                        # [a-fA-F0-9]{40} because a bad activation key should still get to the view;
                        # that way it can return a sensible "invalid key" message instead of a
                        # confusing 404.
                        url(r'^activate/(?P<activation_key>\w+)/$',
-                           activate,
+                           views.activate,
                            {'backend': 'registration.backends.default.DefaultBackend'},
                            name='registration_activate'),
                        url(r'^register/$',
-                           register,
+                           views.register,
                            {'backend': 'registration.backends.default.DefaultBackend'},
                            name='registration_register'),
                        url(r'^register/complete/$',
-                           direct_to_template,
-                           {'template': 'registration/registration_complete.html'},
+                           views.RegistrationCompleteView.as_view(),
                            name='registration_complete'),
                        url(r'^register/closed/$',
-                           direct_to_template,
-                           {'template': 'registration/registration_closed.html'},
+                           views.RegistrationClosedView.as_view(),
                            name='registration_disallowed'),
                        (r'', include('registration.auth_urls')),
                        )

registration/backends/simple/urls.py

 
 
 from django.conf.urls.defaults import *
-from django.views.generic.simple import direct_to_template
 
-from registration.views import activate
-from registration.views import register
+from registration import views
 
 
 urlpatterns = patterns('',
                        url(r'^register/$',
-                           register,
+                           views.register,
                            {'backend': 'registration.backends.simple.SimpleBackend'},
                            name='registration_register'),
                        url(r'^register/closed/$',
-                           direct_to_template,
-                           {'template': 'registration/registration_closed.html'},
+                           views.RegistrationClosedView.as_view(),
                            name='registration_disallowed'),
                        (r'', include('registration.auth_urls')),
                        )

registration/tests/urls.py

 """
 
 from django.conf.urls.defaults import *
-from django.views.generic.simple import direct_to_template
+from django.views.generic import TemplateView
 
-from registration.views import activate
-from registration.views import register
+from registration import views.
 
 
+class RegistrationTestCustomDisallowedView(TemplateView):
+    template_name = 'registration/registration_closed.html'
+
+class RegistrationTestCustomSuccessView(TemplateView):
+    template_name = 'registration/test_template_name.html'
+
 urlpatterns = patterns('',
                        # Test the 'activate' view with custom template
                        # name.
                        url(r'^activate-with-template-name/(?P<activation_key>\w+)/$',
-                           activate,
+                           views.activate,
                            {'template_name': 'registration/test_template_name.html',
                             'backend': 'registration.backends.default.DefaultBackend'},
                            name='registration_test_activate_template_name'),
                        # Test the 'activate' view with
                        # extra_context_argument.
                        url(r'^activate-extra-context/(?P<activation_key>\w+)/$',
-                           activate,
+                           views.activate,
                            {'extra_context': {'foo': 'bar', 'callable': lambda: 'called'},
                             'backend': 'registration.backends.default.DefaultBackend'},
                            name='registration_test_activate_extra_context'),
                        # Test the 'activate' view with success_url argument.
                        url(r'^activate-with-success-url/(?P<activation_key>\w+)/$',
-                           activate,
+                           views.activate,
                            {'success_url': 'registration_test_custom_success_url',
                             'backend': 'registration.backends.default.DefaultBackend'},
                            name='registration_test_activate_success_url'),
                        # Test the 'register' view with custom template
                        # name.
                        url(r'^register-with-template-name/$',
-                           register,
+                           views.register,
                            {'template_name': 'registration/test_template_name.html',
                             'backend': 'registration.backends.default.DefaultBackend'},
                            name='registration_test_register_template_name'),
                        # Test the'register' view with extra_context
                        # argument.
                        url(r'^register-extra-context/$',
-                           register,
+                           views.register,
                            {'extra_context': {'foo': 'bar', 'callable': lambda: 'called'},
                             'backend': 'registration.backends.default.DefaultBackend'},
                            name='registration_test_register_extra_context'),
                        # Test the 'register' view with custom URL for
                        # closed registration.
                        url(r'^register-with-disallowed-url/$',
-                           register,
+                           views.register,
                            {'disallowed_url': 'registration_test_custom_disallowed',
                             'backend': 'registration.backends.default.DefaultBackend'},
                            name='registration_test_register_disallowed_url'),
                        # Set up a pattern which will correspond to the
                        # custom 'disallowed_url' above.
                        url(r'^custom-disallowed/$',
-                           direct_to_template,
-                           {'template': 'registration/registration_closed.html'},
+                           RegistrationTestCustomDisallowedView.as_view(),
                            name='registration_test_custom_disallowed'),
                        # Test the 'register' view with custom redirect
                        # on successful registration.
                        url(r'^register-with-success_url/$',
-                           register,
+                           views.register,
                            {'success_url': 'registration_test_custom_success_url',
                             'backend': 'registration.backends.default.DefaultBackend'},
                            name='registration_test_register_success_url'
                            ),
                        # Pattern for custom redirect set above.
                        url(r'^custom-success/$',
-                           direct_to_template,
-                           {'template': 'registration/test_template_name.html'},
+                           RegistrationTestCustomSuccessView.as_view(),
                            name='registration_test_custom_success_url'),
                        (r'', include('registration.backends.default.urls')),
                        )

registration/views.py

 
 from django.shortcuts import redirect
 from django.shortcuts import render_to_response
+from django.views.generic import TemplateView
 from django.template import RequestContext
 
 from registration.backends import get_backend
 
 
+class ActivationCompleteView(TemplateView):
+    template_name = 'registration/activation_complete.html'
+
+class RegistrationCompleteView(TemplateView):
+    template_name = 'registration/registration_complete.html'
+
+class RegistrationClosedView(TemplateView):
+    template_name = 'registration/registration_closed.html'
+
 def activate(request, backend,
              template_name='registration/activate.html',
              success_url=None, extra_context=None, **kwargs):