Commits

Anonymous committed 54a4886

Add support for TemplateView in Django 1.5.

The old django.views.generic.simple.direct_to_template seems not to
exist in Django 1.5, so if the import fails, try to import TemplateView
instead, and if that works then use it.

Comments (0)

Files changed (1)

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
 
+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/$',
-                           direct_to_template,
-                           {'template': 'registration/activation_complete.html'},
+                           template_view('registration/activation_complete.html'),
                            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;
                            {'backend': 'registration.backends.default.DefaultBackend'},
                            name='registration_register'),
                        url(r'^register/complete/$',
-                           direct_to_template,
-                           {'template': 'registration/registration_complete.html'},
+                           template_view('registration/registration_complete.html'),
                            name='registration_complete'),
                        url(r'^register/closed/$',
-                           direct_to_template,
-                           {'template': 'registration/registration_closed.html'},
+                           template_view('registration/registration_closed.html'),
                            name='registration_disallowed'),
                        (r'', include('registration.auth_urls')),
                        )