Commits

Anonymous committed 8801f05

[svn r28] Added ssl_required decorator

  • Participants
  • Parent commits 30f598d
  • Branches trunk

Comments (0)

Files changed (1)

File ssldecorator.py

+import urlparse
+from django.conf import settings
+from django.http import HttpResponseRedirect
+
+
+def ssl_required(view_func):
+    def _checkssl(request, *args, **kwargs):
+        if not settings.DEBUG and not request.is_secure():
+            if hasattr(settings, 'SSL_DOMAIN'):
+                url_str = urlparse.urljoin(
+                    settings.SSL_DOMAIN,
+                    request.get_full_path()
+                )
+            else:
+                url_str = request.build_absolute_uri()
+            url_str.replace('http://', 'https://')
+            return HttpResponseRedirect(url_str)
+
+        return view_func(request, *args, **kwargs)
+    return _checkssl