summaryrefslogtreecommitdiff
path: root/yaksh/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'yaksh/views.py')
-rw-r--r--yaksh/views.py77
1 files changed, 43 insertions, 34 deletions
diff --git a/yaksh/views.py b/yaksh/views.py
index 8746a57..7f907aa 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
@@ -275,31 +275,6 @@ def add_quiz(request, course_id, quiz_id=None):
context,
context_instance=ci)
-
-@login_required
-@email_verified
-def show_all_questionpapers(request, questionpaper_id=None):
- user = request.user
- ci = RequestContext(request)
- if not user.is_authenticated() or not is_moderator(user):
- raise Http404('You are not allowed to view this page!')
-
- if questionpaper_id is None:
- qu_papers = QuestionPaper.objects.filter(is_trial=False)
- context = {'papers': qu_papers}
- return my_render_to_response('yaksh/showquestionpapers.html', context,
- context_instance=ci)
- else:
- qu_papers = QuestionPaper.objects.get(id=questionpaper_id)
- quiz = qu_papers.quiz
- fixed_questions = qu_papers.get_ordered_questions()
- random_questions = qu_papers.random_questions.all()
- context = {'quiz': quiz, 'fixed_questions': fixed_questions,
- 'random_questions': random_questions}
- return my_render_to_response('yaksh/editquestionpaper.html', context,
- context_instance=ci)
-
-
@login_required
@email_verified
def prof_manage(request, msg=None):
@@ -754,6 +729,39 @@ def enroll(request, course_id, user_id=None, was_rejected=False):
@login_required
@email_verified
+def send_mail(request, course_id, user_id=None):
+ 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')
+
+ message = None
+ if request.method == 'POST':
+ user_ids = request.POST.getlist('check')
+ if request.POST.get('send_mail') == 'send_mail':
+ users = User.objects.filter(id__in=user_ids)
+ 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
+ )
+ context = {
+ 'course': course, 'message': message,
+ 'state': 'mail'
+ }
+ return my_render_to_response(
+ 'yaksh/course_detail.html', context, context_instance=ci
+ )
+
+
+@login_required
+@email_verified
def reject(request, course_id, user_id=None, was_enrolled=False):
user = request.user
ci = RequestContext(request)
@@ -769,8 +777,10 @@ def reject(request, course_id, user_id=None, was_enrolled=False):
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)
@@ -887,7 +897,6 @@ def ajax_questions_filter(request):
if language != "select":
filter_dict['language'] = str(language)
-
questions = list(Question.objects.filter(**filter_dict))
return my_render_to_response('yaksh/ajax_question_filter.html',
@@ -1047,8 +1056,8 @@ def show_all_questions(request):
question = Question()
zip_file = question.dump_questions(question_ids, user)
response = HttpResponse(content_type='application/zip')
- response['Content-Disposition'] = '''attachment;\
- filename={0}_questions.zip'''.format(user)
+ response['Content-Disposition'] = dedent(\
+ '''attachment; filename={0}_questions.zip'''.format(user))
zip_file.seek(0)
response.write(zip_file.read())
return response
@@ -1090,7 +1099,6 @@ def user_data(request, user_id, questionpaper_id=None):
return my_render_to_response('yaksh/user_data.html', context,
context_instance=RequestContext(request))
-
@login_required
@email_verified
def download_csv(request, questionpaper_id):
@@ -1570,6 +1578,8 @@ def update_email(request):
@email_verified
def download_assignment_file(request, quiz_id, question_id=None, user_id=None):
user = request.user
+ if not is_moderator(user):
+ raise Http404("You are not allowed to view this page")
qp = QuestionPaper.objects.get(quiz_id=quiz_id)
assignment_files, file_name = AssignmentUpload.objects.get_assignments(qp,
question_id,
@@ -1588,8 +1598,7 @@ def download_assignment_file(request, quiz_id, question_id=None, user_id=None):
zip_file.close()
zipfile_name.seek(0)
response = HttpResponse(content_type='application/zip')
- response['Content-Disposition'] = '''attachment;\
- filename={0}.zip'''.format(
+ response['Content-Disposition'] = 'attachment; filename={0}.zip'.format(
file_name.replace(" ", "_")
)
response.write(zipfile_name.read())