summaryrefslogtreecommitdiff
path: root/yaksh/decorators.py
diff options
context:
space:
mode:
authormahesh2017-08-24 23:26:46 +0530
committermahesh2017-08-24 23:26:46 +0530
commit751dc83729e5bf57b2dd1a2798bb7b527a2e3584 (patch)
treefa1d11bd00ac9060cfa36056f62d1321455a4916 /yaksh/decorators.py
parent6ab383c02085936ecc20ffeb4b9f41ca642256c3 (diff)
parent9d5c4a01fd7856f1ef8793b75a9734324c254344 (diff)
downloadonline_test-751dc83729e5bf57b2dd1a2798bb7b527a2e3584.tar.gz
online_test-751dc83729e5bf57b2dd1a2798bb7b527a2e3584.tar.bz2
online_test-751dc83729e5bf57b2dd1a2798bb7b527a2e3584.zip
Merge branch 'master' of https://github.com/fossee/online_test into yaml_questions
Diffstat (limited to 'yaksh/decorators.py')
-rw-r--r--yaksh/decorators.py40
1 files changed, 35 insertions, 5 deletions
diff --git a/yaksh/decorators.py b/yaksh/decorators.py
index f0d354c..9e9bc6d 100644
--- a/yaksh/decorators.py
+++ b/yaksh/decorators.py
@@ -1,12 +1,42 @@
-from django.shortcuts import render_to_response
+from django.shortcuts import render_to_response, redirect
from django.conf import settings
from django.template import RequestContext
+# Local imports
+from yaksh.forms import ProfileForm
+
+
+def user_has_profile(user):
+ return hasattr(user, 'profile')
+
+
+def has_profile(func):
+ """
+ This decorator is used to check if the user account has a profile.
+ If the user does not have a profile then redirect the user to
+ profile edit page.
+ """
+
+ def _wrapped_view(request, *args, **kwargs):
+ if user_has_profile(request.user):
+ return func(request, *args, **kwargs)
+ ci = RequestContext(request)
+ if request.user.groups.filter(name='moderator').exists():
+ template = 'manage.html'
+ else:
+ template = 'user.html'
+ form = ProfileForm(user=request.user, instance=None)
+ context = {'template': template, 'form': form}
+ return render_to_response('yaksh/editprofile.html', context,
+ context_instance=ci)
+ return _wrapped_view
+
def email_verified(func):
- """ This decorator is used to check if email is verified.
- If email is not verified then redirect user for email
- verification
+ """
+ This decorator is used to check if email is verified.
+ If email is not verified then redirect user for email
+ verification.
"""
def is_email_verified(request, *args, **kwargs):
@@ -14,7 +44,7 @@ def email_verified(func):
user = request.user
context = {}
if not settings.IS_DEVELOPMENT:
- if user.is_authenticated() and hasattr(user, 'profile'):
+ if user.is_authenticated() and user_has_profile(user):
if not user.profile.is_email_verified:
context['success'] = False
context['msg'] = "Your account is not verified. \