From 716fb091d3472d5d696d4994aa4f9f4d99a0626e Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Thu, 9 Nov 2017 17:45:16 +0530 Subject: Prepopulate the test case type field when adding test cases to questions --- yaksh/views.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'yaksh') diff --git a/yaksh/views.py b/yaksh/views.py index 0ba3270..df002a4 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -254,12 +254,19 @@ def add_question(request, question_id=None): formsets = [] for testcase in TestCase.__subclasses__(): if test_case_type == testcase.__name__.lower(): - formset = inlineformset_factory(Question, testcase, extra=1, - fields='__all__') + formset = inlineformset_factory( + Question, testcase, extra=1, fields='__all__' + ) else: - formset = inlineformset_factory(Question, testcase, extra=0, - fields='__all__') - formsets.append(formset(instance=question)) + formset = inlineformset_factory( + Question, testcase, extra=0, fields='__all__' + ) + formsets.append( + formset( + instance=question, + initial=[{'type': test_case_type}] + ) + ) context = {'qform': qform, 'fileform': fileform, 'question': question, 'formsets': formsets, 'uploaded_files': uploaded_files} return my_render_to_response( -- cgit