summaryrefslogtreecommitdiff
path: root/yaksh/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'yaksh/views.py')
-rw-r--r--yaksh/views.py48
1 files changed, 26 insertions, 22 deletions
diff --git a/yaksh/views.py b/yaksh/views.py
index 7ecf6aa..4be2fc1 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -105,18 +105,16 @@ def user_register(request):
@login_required
-def quizlist_user(request):
+def quizlist_user(request, enrolled=None):
"""Show All Quizzes that is available to logged-in user."""
user = request.user
- avail_quizzes = Quiz.objects.get_active_quizzes()
- user_answerpapers = AnswerPaper.objects.filter(user=user)
- courses = Course.objects.filter(active=True, is_trial=False)
-
- context = { 'quizzes': avail_quizzes,
- 'user': user,
- 'courses': courses,
- 'quizzes_taken': user_answerpapers,
- }
+ if enrolled is not None:
+ courses = user.students.all()
+ title = 'Enrolled Courses'
+ else:
+ courses = Course.objects.filter(active=True, is_trial=False)
+ title = 'All Courses'
+ context = {'user': user, 'courses': courses, 'title': title}
return my_render_to_response("yaksh/quizzes_user.html", context)
@@ -269,7 +267,7 @@ def show_all_questionpapers(request, questionpaper_id=None):
@login_required
-def prof_manage(request):
+def prof_manage(request, msg=None):
"""Take credentials of the user with professor/moderator
rights/permissions and log in."""
user = request.user
@@ -303,7 +301,7 @@ def prof_manage(request):
temp = paper, answer_papers, users_passed, users_failed
users_per_paper.append(temp)
context = {'user': user, 'users_per_paper': users_per_paper,
- 'trial_paper': trial_paper
+ 'trial_paper': trial_paper, 'msg': msg
}
return my_render_to_response('yaksh/moderator_dashboard.html', context, context_instance=ci)
return my_redirect('/exam/login/')
@@ -488,12 +486,12 @@ def check(request, q_id, attempt_num=None, questionpaper_id=None):
# safely in a separate process (the code_server.py) running as nobody.
json_data = current_question.consolidate_answer_data(user_answer) \
if current_question.type == 'code' else None
- correct, result = paper.validate_answer(user_answer, current_question, json_data)
- if correct or result.get('success'):
+ result = paper.validate_answer(user_answer, current_question, json_data)
+ if result.get('success'):
new_answer.marks = (current_question.points * result['weight'] /
current_question.get_maximum_test_case_weight()) \
if current_question.partial_grading and current_question.type == 'code' else current_question.points
- new_answer.correct = correct
+ new_answer.correct = result.get('success')
error_message = None
new_answer.error = json.dumps(result.get('error'))
next_question = paper.completed_question(current_question.id)
@@ -1065,10 +1063,14 @@ def view_profile(request):
""" view moderators and users profile """
user = request.user
ci = RequestContext(request)
-
- context = {}
+ if is_moderator(user):
+ template = 'manage.html'
+ else:
+ template = 'user.html'
+ context = {'template': template}
if has_profile(user):
- return my_render_to_response('yaksh/view_profile.html', {'user':user})
+ context['user'] = user
+ return my_render_to_response('yaksh/view_profile.html', context)
else:
form = ProfileForm(user=user)
msg = True
@@ -1082,10 +1084,13 @@ def view_profile(request):
def edit_profile(request):
""" edit profile details facility for moderator and students """
- context = {}
user = request.user
ci = RequestContext(request)
-
+ if is_moderator(user):
+ template = 'manage.html'
+ else:
+ template = 'user.html'
+ context = {'template': template}
if has_profile(user):
profile = Profile.objects.get(user_id=user.id)
else:
@@ -1241,8 +1246,7 @@ def create_demo_course(request):
msg = "Created Demo course successfully"
else:
msg = "Demo course already created"
- context = {'msg': msg}
- return my_render_to_response('manage.html', context, context_instance=ci)
+ return prof_manage(request, msg)
@login_required