From bd255f751dbff97d92e9c34652af37c67b62b2ff Mon Sep 17 00:00:00 2001 From: adityacp Date: Mon, 15 May 2017 15:01:10 +0530 Subject: Change urls.py and views.py - Change views to send mails to students enrolled in a course - Add reverse resolution in urls.py --- yaksh/views.py | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'yaksh/views.py') diff --git a/yaksh/views.py b/yaksh/views.py index c7af5cc..41db80e 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -42,7 +42,7 @@ from yaksh.forms import UserRegisterForm, UserLoginForm, QuizForm,\ from .settings import URL_ROOT from yaksh.models import AssignmentUpload from .file_utils import extract_files -from .send_emails import send_user_mail, generate_activation_key +from .send_emails import send_user_mail, generate_activation_key, send_bulk_mail from .decorators import email_verified @@ -771,12 +771,35 @@ def reject(request, course_id, user_id=None, was_enrolled=False): raise Http404('This course does not belong to you') if request.method == 'POST': - reject_ids = request.POST.getlist('check') + user_ids = request.POST.getlist('check') + if not user_ids: + message = "Please select atleast one User" + return my_render_to_response('yaksh/course_detail.html', + {'course': course, "message": message}, + context_instance=ci) + + if request.POST.get('send_mail') == 'send_mail': + users = User.objects.filter(id__in=user_ids) + recipients = [user.email for user in users] + email_body = request.POST.get('body') + subject = request.POST.get('subject') + attachments = request.FILES.getlist('email_attach') + message = send_bulk_mail(subject, email_body, recipients, + attachments) + + return my_render_to_response('yaksh/course_detail.html', + {'course': course, "message": message}, + context_instance=ci) + + if request.POST.get('reject') == 'reject': + reject_ids = user_ids else: reject_ids = [user_id] if not reject_ids: - return my_render_to_response('yaksh/course_detail.html', {'course': course}, - context_instance=ci) + message = "Please select atleast one User" + return my_render_to_response('yaksh/course_detail.html', + {'course': course, "message": message}, + context_instance=ci) users = User.objects.filter(id__in=reject_ids) course.reject(was_enrolled, *users) return course_detail(request, course_id) -- cgit From 928ebb23f8b2926240fc220791655614cc4192d2 Mon Sep 17 00:00:00 2001 From: Date: Mon, 12 Jun 2017 18:19:21 +0530 Subject: Change views.py and urls.py - Add new url for sending email - Add new view function to send email to students --- yaksh/views.py | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'yaksh/views.py') diff --git a/yaksh/views.py b/yaksh/views.py index 41db80e..3319773 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -757,10 +757,9 @@ def enroll(request, course_id, user_id=None, was_rejected=False): course.enroll(was_rejected, *users) return course_detail(request, course_id) - @login_required @email_verified -def reject(request, course_id, user_id=None, was_enrolled=False): +def send_mail(request, course_id, user_id=None): user = request.user ci = RequestContext(request) if not is_moderator(user): @@ -770,6 +769,7 @@ def reject(request, course_id, user_id=None, was_enrolled=False): if not course.is_creator(user) and not course.is_teacher(user): raise Http404('This course does not belong to you') + message = None if request.method == 'POST': user_ids = request.POST.getlist('check') if not user_ids: @@ -787,12 +787,25 @@ def reject(request, course_id, user_id=None, was_enrolled=False): message = send_bulk_mail(subject, email_body, recipients, attachments) - return my_render_to_response('yaksh/course_detail.html', - {'course': course, "message": message}, - context_instance=ci) + return my_render_to_response('yaksh/course_detail.html', + {'course': course, "message": message, + 'msg': 'mail'}, + context_instance=ci) - if request.POST.get('reject') == 'reject': - reject_ids = user_ids +@login_required +@email_verified +def reject(request, course_id, user_id=None, was_enrolled=False): + user = request.user + ci = RequestContext(request) + if not is_moderator(user): + raise Http404('You are not allowed to view this page') + + course = get_object_or_404(Course, pk=course_id) + if not course.is_creator(user) and not course.is_teacher(user): + raise Http404('This course does not belong to you') + + if request.method == 'POST': + reject_ids = request.POST.getlist('check') else: reject_ids = [user_id] if not reject_ids: -- cgit From 4f305d1e2ccce8b2250624838a29d2000d0d9230 Mon Sep 17 00:00:00 2001 From: adityacp Date: Thu, 17 Aug 2017 10:47:50 +0530 Subject: Change views.py - Pep8 changes - Remove redundant check from send mail function - Move validation send mail validation to js --- yaksh/views.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'yaksh/views.py') diff --git a/yaksh/views.py b/yaksh/views.py index ffdcf98..b4ab9bb 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -732,6 +732,7 @@ def enroll(request, course_id, user_id=None, was_rejected=False): course.enroll(was_rejected, *users) return course_detail(request, course_id) + @login_required @email_verified def send_mail(request, course_id, user_id=None): @@ -747,25 +748,23 @@ def send_mail(request, course_id, user_id=None): message = None if request.method == 'POST': user_ids = request.POST.getlist('check') - if not user_ids: - message = "Please select atleast one User" - return my_render_to_response('yaksh/course_detail.html', - {'course': course, "message": message}, - context_instance=ci) - if request.POST.get('send_mail') == 'send_mail': users = User.objects.filter(id__in=user_ids) - recipients = [user.email for user in users] + recipients = [student.email for student in users] email_body = request.POST.get('body') subject = request.POST.get('subject') attachments = request.FILES.getlist('email_attach') - message = send_bulk_mail(subject, email_body, recipients, - attachments) + message = send_bulk_mail( + subject, email_body, recipients, attachments + ) + context = { + 'course': course, 'message': message, + 'status': 'mail' + } + return my_render_to_response( + 'yaksh/course_detail.html', context, context_instance=ci + ) - return my_render_to_response('yaksh/course_detail.html', - {'course': course, "message": message, - 'msg': 'mail'}, - context_instance=ci) @login_required @email_verified -- cgit From dade8a89e3e3f882aa05f974feed1b7248fd6de8 Mon Sep 17 00:00:00 2001 From: adityacp Date: Tue, 22 Aug 2017 12:22:32 +0530 Subject: Change course.js, course_detail.html and views.py - Change form submission for send email in js - Change template and view variable for mail status --- yaksh/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'yaksh/views.py') diff --git a/yaksh/views.py b/yaksh/views.py index b4ab9bb..db45a89 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -759,7 +759,7 @@ def send_mail(request, course_id, user_id=None): ) context = { 'course': course, 'message': message, - 'status': 'mail' + 'state': 'mail' } return my_render_to_response( 'yaksh/course_detail.html', context, context_instance=ci -- cgit