diff options
author | adityacp | 2017-05-15 15:01:10 +0530 |
---|---|---|
committer | adityacp | 2017-05-15 15:01:10 +0530 |
commit | bd255f751dbff97d92e9c34652af37c67b62b2ff (patch) | |
tree | 62fe8255849adf064099c18fb50b7a9be87df988 /yaksh | |
parent | db8aa57e9a3caf9b2ed080b440703d634abd14a1 (diff) | |
download | online_test-bd255f751dbff97d92e9c34652af37c67b62b2ff.tar.gz online_test-bd255f751dbff97d92e9c34652af37c67b62b2ff.tar.bz2 online_test-bd255f751dbff97d92e9c34652af37c67b62b2ff.zip |
Change urls.py and views.py
- Change views to send mails to students enrolled in a course
- Add reverse resolution in urls.py
Diffstat (limited to 'yaksh')
-rw-r--r-- | yaksh/urls.py | 2 | ||||
-rw-r--r-- | yaksh/views.py | 31 |
2 files changed, 28 insertions, 5 deletions
diff --git a/yaksh/urls.py b/yaksh/urls.py index e4676d3..825e5f5 100644 --- a/yaksh/urls.py +++ b/yaksh/urls.py @@ -79,7 +79,7 @@ urlpatterns = [ url(r'manage/enroll/rejected/(?P<course_id>\d+)/$', views.enroll, {'was_rejected': True}), url(r'manage/enrolled/reject/(?P<course_id>\d+)/$', - views.reject, {'was_enrolled': True}), + views.reject, {'was_enrolled': True}, name="reject_users"), url(r'^manage/searchteacher/(?P<course_id>\d+)/$', views.search_teacher), url(r'^manage/addteacher/(?P<course_id>\d+)/$', views.add_teacher, name='add_teacher'), url(r'^manage/remove_teachers/(?P<course_id>\d+)/$', views.remove_teachers, name='remove_teacher'), 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) |