From f120f5763904589d3c18b6cc0f4e227bcaef9a0a Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Fri, 1 Apr 2016 11:18:04 +0530 Subject: Add testcase addition templates, views and forms --- yaksh/forms.py | 11 +++++++++ yaksh/templates/yaksh/add_testcase.html | 21 ++++++++++++++++ yaksh/views.py | 44 +++++++++++++++++++-------------- 3 files changed, 57 insertions(+), 19 deletions(-) create mode 100644 yaksh/templates/yaksh/add_testcase.html (limited to 'yaksh') 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 %} + + +{% endblock %} + +{% block script %} + + +{% endblock %} + +{% block onload %} onload='javascript:textareaformat();' {% endblock %} + +{% block manage %} +
+Test Case: {{ form.test_case }}{{ form.test_case.errors }} +
\ 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): -- cgit