summaryrefslogtreecommitdiff
path: root/arduino_blog/decorators.py
diff options
context:
space:
mode:
Diffstat (limited to 'arduino_blog/decorators.py')
-rw-r--r--arduino_blog/decorators.py43
1 files changed, 42 insertions, 1 deletions
diff --git a/arduino_blog/decorators.py b/arduino_blog/decorators.py
index ddb888c..6c185d5 100644
--- a/arduino_blog/decorators.py
+++ b/arduino_blog/decorators.py
@@ -1,5 +1,7 @@
from django.shortcuts import render, redirect
from django.conf import settings
+from arduino_blog.models import Proposal
+from django.db.models import Q
def email_verified(func):
"""
@@ -21,6 +23,45 @@ def email_verified(func):
request, 'activation-status.html', context
)
return func(request, *args, **kwargs)
- except:
+ except Exception as e:
+ print (e)
return redirect('/')
return is_email_verified
+
+
+def is_proposal_submitted(func):
+ def is_submitted(request, *args, **kwargs):
+ user = request.user
+ context = {}
+ try:
+ if user.is_authenticated:
+ if not user.profile.is_email_verified:
+ context['success'] = False
+ context['msg'] = "Your account is not verified. \
+ Please verify your account"
+ return render(
+ request, 'activation-status.html', context
+ )
+ else:
+ _q = Proposal.objects
+ is_sub = _q.get(Q(user_id=user.id)&Q(proposal_status='0'))
+ if is_sub.proposal_status == 0:
+ context['success'] = True
+ context['msg'] = "You have alredy submited a \
+ proposal. Your proposal is under \
+ review"
+ return render(
+ request, 'dashboard.html', context
+ )
+ else:
+ context['success'] = False
+ context['msg'] = "You can submit a new \
+ proposal"
+ return render(
+ request, 'dashboard.html', context
+ )
+ return func(request, *args, **kwargs)
+ except Exception as e:
+ print (e)
+ return redirect('/')
+ return is_submitted