From 9dd5d2ad16734ff63e694f4bf1ed82155362a620 Mon Sep 17 00:00:00 2001 From: Martin Green Date: Mon, 2 May 2011 02:13:27 +0100 Subject: [PATCH] decorator to check if user is logged in if settings.PUBLIC_SITE --- helper/__init__.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 helper/__init__.py diff --git a/helper/__init__.py b/helper/__init__.py new file mode 100644 index 0000000..120be20 --- /dev/null +++ b/helper/__init__.py @@ -0,0 +1,14 @@ +from django.contrib.auth.decorators import login_required +from django.conf import settings + + +class login_required_if_public(object): + + def __init__(self, f): + if settings.PUBLIC_SITE: + self.f = login_required(f) + else: + self.f = f + + def __call__(self, *args, **kwargs): + return self.f(*args, **kwargs)