summaryrefslogtreecommitdiff
path: root/testapp/exam/views.py
diff options
context:
space:
mode:
authorankitjavalkar2015-04-24 14:25:26 +0530
committerankitjavalkar2015-04-26 21:11:52 +0530
commit8664a766406d6acf0d6a1688948153c407ea27f2 (patch)
tree7505ef02b5e36395fc7e92ff5cde7700f2025979 /testapp/exam/views.py
parent17752a69114e7dbad266337e768013920aec8c0c (diff)
downloadonline_test-8664a766406d6acf0d6a1688948153c407ea27f2.tar.gz
online_test-8664a766406d6acf0d6a1688948153c407ea27f2.tar.bz2
online_test-8664a766406d6acf0d6a1688948153c407ea27f2.zip
Code Review: Code refactoring
- Rename files - Create function for @classmethod call - Fix current, add new testcases - Fix views to fetch solution/ref_code_path fields in question post save - Fix errors
Diffstat (limited to 'testapp/exam/views.py')
-rw-r--r--testapp/exam/views.py19
1 files changed, 13 insertions, 6 deletions
diff --git a/testapp/exam/views.py b/testapp/exam/views.py
index 508b623..2542a28 100644
--- a/testapp/exam/views.py
+++ b/testapp/exam/views.py
@@ -286,7 +286,6 @@ def edit_question(request):
user = request.user
if not user.is_authenticated() or not is_moderator(user):
raise Http404('You are not allowed to view this page!')
-
question_list = request.POST.getlist('questions')
summary = request.POST.getlist('summary')
description = request.POST.getlist('description')
@@ -311,6 +310,8 @@ def edit_question(request):
question.active = active[j]
question.language = language[j]
question.snippet = snippet[j]
+ question.ref_code_path = ref_code_path[j]
+ question.solution = solution[j]
question.type = type[j]
question.save()
return my_redirect("/exam/manage/questions")
@@ -374,6 +375,8 @@ def add_question(request, question_id=None):
d.active = form['active'].data
d.language = form['language'].data
d.snippet = form['snippet'].data
+ d.ref_code_path = form['ref_code_path'].data
+ d.solution = form['solution'].data
d.save()
question = Question.objects.get(id=question_id)
for tag in question.tags.all():
@@ -428,6 +431,8 @@ def add_question(request, question_id=None):
form.initial['active'] = d.active
form.initial['language'] = d.language
form.initial['snippet'] = d.snippet
+ form.initial['ref_code_path'] = d.ref_code_path
+ form.initial['solution'] = d.solution
form_tags = d.tags.all()
form_tags_split = form_tags.values('name')
initial_tags = ""
@@ -953,9 +958,9 @@ def check(request, q_id, attempt_num=None, questionpaper_id=None):
# questions, we obtain the results via XML-RPC with the code executed
# safely in a separate process (the code_server.py) running as nobody.
if not question.type == 'upload':
- info_parameter = question.consolidate_answer_data(test, user_answer) \
- if question.type == 'code' else None
- correct, result = validate_answer(user, user_answer, question, info_parameter)
+ json_data = question.consolidate_answer_data(test, user_answer) \
+ if question.type == 'code' else None
+ correct, result = validate_answer(user, user_answer, question, json_data)
if correct:
new_answer.correct = correct
new_answer.marks = question.points
@@ -1000,7 +1005,7 @@ def check(request, q_id, attempt_num=None, questionpaper_id=None):
questionpaper_id, success_msg)
-def validate_answer(user, user_answer, question, info_parameter=None):
+def validate_answer(user, user_answer, question, json_data=None):
"""
Checks whether the answer submitted by the user is right or wrong.
If right then returns correct = True, success and
@@ -1025,7 +1030,7 @@ def validate_answer(user, user_answer, question, info_parameter=None):
message = 'Correct answer'
elif question.type == 'code':
user_dir = get_user_dir(user)
- json_result = code_server.run_code(info_parameter, question.language, user_dir)
+ json_result = code_server.run_code(question.language, json_data, user_dir)
result = json.loads(json_result)
if result.get('success'):
correct = True
@@ -1247,6 +1252,8 @@ def show_all_questions(request):
form.initial['active'] = d.active
form.initial['language'] = d.language
form.initial['snippet'] = d.snippet
+ form.initial['ref_code_path'] = d.ref_code_path
+ form.initial['solution'] = d.solution
form_tags = d.tags.all()
form_tags_split = form_tags.values('name')
initial_tags = ""