summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorprashantsinalkar2020-03-01 23:15:05 +0530
committerprashantsinalkar2020-03-01 23:15:05 +0530
commit79f1b9f4c7a4a988c6582488d1f33c06061bd114 (patch)
tree351da9bb3a6fb8354ff1800e4cce5320f8687f40
parent6f19057de04c6b13878c668692054240b0c9fb12 (diff)
downloadarduino_projects_website-79f1b9f4c7a4a988c6582488d1f33c06061bd114.tar.gz
arduino_projects_website-79f1b9f4c7a4a988c6582488d1f33c06061bd114.tar.bz2
arduino_projects_website-79f1b9f4c7a4a988c6582488d1f33c06061bd114.zip
added mail funtion ad decorator
-rw-r--r--arduino_blog/decorators.py45
-rw-r--r--arduino_blog/views.py26
2 files changed, 68 insertions, 3 deletions
diff --git a/arduino_blog/decorators.py b/arduino_blog/decorators.py
index ddb888c..2644256 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,47 @@ 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
+ _q = _q.filter(Q(user_id=user.id)&Q(proposal_status='0'))
+ _q = _q.values('proposal_status')
+ _q = _q.order_by('proposal_status');
+ is_sub = _q.all()[:1]
+ if is_sub == 0:
+ context['success'] = True
+ context['msg'] = "You have alredy submited a \
+ proposal"
+ 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
diff --git a/arduino_blog/views.py b/arduino_blog/views.py
index e1081fe..6cad284 100644
--- a/arduino_blog/views.py
+++ b/arduino_blog/views.py
@@ -16,8 +16,9 @@ from .send_emails import (send_user_mail,
generate_activation_key)
from django.utils import timezone
from arduino_projects_website.settings import URL_ROOT
-from .decorators import email_verified
-
+from .decorators import email_verified, is_proposal_submitted
+from django.core.mail import EmailMultiAlternatives
+import datetime
def my_redirect(url):
"""An overridden redirect to deal with URL_ROOT-ing. See settings.py
@@ -183,6 +184,7 @@ def new_activation(request, email=None):
@csrf_protect
@login_required
@email_verified
+@is_proposal_submitted
def submitabstract(request):
context = {}
if request.user.is_authenticated:
@@ -197,11 +199,17 @@ def submitabstract(request):
data.name_of_author = social_user.first_name + ' ' + social_user.last_name
data.email = social_user.email
data.attachment = request.FILES
+ data.proposal_status = 0
+ data.approval_date = datetime.date.today()
data.save()
context['proposal_submit'] = True
+ context['display_message'] = """Thank you for your submission! """
#mail function
+ #message = render_to_string('email/propodal_received.html', context)
+ #send_email(sender_email, to, subject, message, bcc_email)
return render_to_response('index.html', context)
else:
+ print(form.errors)
context['proposal_form'] = form
#context['proposals_a'] = proposals_a
template = loader.get_template('submit-cfp.html')
@@ -212,3 +220,17 @@ def submitabstract(request):
else:
context['login_required'] = True
return render_to_response('login.html', context)
+
+
+def send_email(sender_email, to, subject, message, bcc_email=None):
+ email = EmailMultiAlternatives(
+ subject, '',
+ sender_email, to,
+ bcc=[bcc_email],
+ headers={"Content-type": "text/html;charset=iso-8859-1"}
+ )
+ email.attach_alternative(message, "text/html")
+ email.content_subtype = 'html' # Main content is text/html
+ email.mixed_subtype = 'related'
+ email.send(fail_silently=True)
+