diff options
author | ankitjavalkar | 2016-04-01 11:18:04 +0530 |
---|---|---|
committer | ankitjavalkar | 2016-05-05 19:16:26 +0530 |
commit | f120f5763904589d3c18b6cc0f4e227bcaef9a0a (patch) | |
tree | f129657e1b767c9f5cc6a61d583d5aec46e8334b /yaksh | |
parent | 0b5a48f0ba4c4510c0026101ab84e19099691635 (diff) | |
download | online_test-f120f5763904589d3c18b6cc0f4e227bcaef9a0a.tar.gz online_test-f120f5763904589d3c18b6cc0f4e227bcaef9a0a.tar.bz2 online_test-f120f5763904589d3c18b6cc0f4e227bcaef9a0a.zip |
Add testcase addition templates, views and forms
Diffstat (limited to 'yaksh')
-rw-r--r-- | yaksh/forms.py | 11 | ||||
-rw-r--r-- | yaksh/templates/yaksh/add_testcase.html | 21 | ||||
-rw-r--r-- | yaksh/views.py | 44 |
3 files changed, 57 insertions, 19 deletions
diff --git a/yaksh/forms.py b/yaksh/forms.py index 94498a1..1375d10 100644 --- a/yaksh/forms.py +++ b/yaksh/forms.py @@ -214,3 +214,14 @@ class ProfileForm(forms.ModelForm): class UploadFileForm(forms.Form): file = forms.FileField() + +class StandardTestCaseForm(forms.ModelForm): + class Meta: + model = StandardTestCase + fields = ['test_case'] + + +class StdoutBasedTestCaseForm(forms.ModelForm): + class Meta: + model = StdoutBasedTestCase + fields = ['output'] diff --git a/yaksh/templates/yaksh/add_testcase.html b/yaksh/templates/yaksh/add_testcase.html new file mode 100644 index 0000000..298bd50 --- /dev/null +++ b/yaksh/templates/yaksh/add_testcase.html @@ -0,0 +1,21 @@ +{% extends "manage.html" %} + + +{% block subtitle %}Add Question{% endblock %} + +{% block css %} +<link rel="stylesheet" href="{{ URL_ROOT }}/static/yaksh/css/question_quiz.css" type="text/css" /> +<link rel="stylesheet" media="all" type="text/css" href="{{ URL_ROOT }}/static/yaksh/css/autotaggit.css" /> +{% endblock %} + +{% block script %} +<script type="text/javascript" src="{{ URL_ROOT }}/static/yaksh/js/jquery-1.4.2.min.js"></script> +<script src="{{ URL_ROOT }}/static/yaksh/js/add_question.js"></script> +{% endblock %} + +{% block onload %} onload='javascript:textareaformat();' {% endblock %} + +{% block manage %} +<form action="" method="post" name=frm> +<tr><td>Test Case: <td>{{ form.test_case }}{{ form.test_case.errors }} +</form>
\ No newline at end of file diff --git a/yaksh/views.py b/yaksh/views.py index 2faf127..c7fdc7f 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -217,26 +217,32 @@ def add_question(request, question_id=None): # 'formset': test_case_formset}, context_instance=ci) -# @login_required -# def add_testcase(request, question_id=None): -# """To add new test case for a question""" - -# ci = RequestContext(request) -# if not question_id: -# raise Http404('No Question Found') -# question = Question.objects.get(id=question_id) -# initial = {'question': question} - -# # if question.test - -# if request.method == "POST": -# pass -# else: -# form = TestCaseForm(user=user) -# return my_render_to_response('yaksh/add_testcase.html', -# {'form': form}, -# context_instance=ci) +@login_required +def add_testcase(request, question_id=None): + """To add new test case for a question""" + + ci = RequestContext(request) + if not question_id: + raise Http404('No Question Found') + question = Question.objects.get(id=question_id) + initial = {'question': question} + + test_case_type = question.test_case_type + + if test_case_type == "standardtestcase": + from yaksh.forms import StandardTestCaseForm + if request.method == "POST": + form = StandardTestCaseForm(request.POST) + initial = {'question': question} + form = StandardTestCaseForm(initial) + if request.method == "POST": + if form.is_valid(): + form.save() + else: + return my_render_to_response('yaksh/add_testcase.html', + {'form': form}, + context_instance=ci) @login_required def add_quiz(request, quiz_id=None): |