Commits

Matías Pizarro  committed 00b0267

Use plain vanilla TemplateView class-based views

  • Participants
  • Parent commits e599bbe

Comments (0)

Files changed (3)

File registration/backends/default/urls.py

 
 from registration.views import activate
 from registration.views import register
+from registration.views import ActivationComplete, RegistrationComplete, RegistrationDisallowed
 
-def template_view(template_name):
-    try:
-        from django.views.generic.simple import direct_to_template
-        def curried_template_view(request, extra_context=None, mimetype=None, **kwargs):
-            return direct_to_template(request, template_name, extra_context,
-                mimetype, **kwargs)
-        return curried_template_view
-    except ImportError:
-        from django.views.generic import TemplateView
-        return TemplateView.as_view(template_name=template_name)
 
 urlpatterns = patterns('',
-                       url(r'^activate/complete/$',
-                           template_view('registration/activation_complete.html'),
-                           name='registration_activation_complete'),
+                       url(r'^activate/complete/$', ActivationComplete.as_view()),
                        # 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
                            register,
                            {'backend': 'registration.backends.default.DefaultBackend'},
                            name='registration_register'),
-                       url(r'^register/complete/$',
-                           template_view('registration/registration_complete.html'),
-                           name='registration_complete'),
-                       url(r'^register/closed/$',
-                           template_view('registration/registration_closed.html'),
-                           name='registration_disallowed'),
+                       url(r'^register/complete/$', RegistrationComplete.as_view()),
+                       url(r'^register/closed/$', RegistrationDisallowed.as_view()),
                        (r'', include('registration.auth_urls')),
                        )

File registration/backends/simple/urls.py

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

File registration/views.py

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