summaryrefslogtreecommitdiff
path: root/yaksh
diff options
context:
space:
mode:
Diffstat (limited to 'yaksh')
-rw-r--r--yaksh/templates/yaksh/add_question.html36
-rw-r--r--yaksh/views.py69
2 files changed, 21 insertions, 84 deletions
diff --git a/yaksh/templates/yaksh/add_question.html b/yaksh/templates/yaksh/add_question.html
index 91c7de4..57e5e78 100644
--- a/yaksh/templates/yaksh/add_question.html
+++ b/yaksh/templates/yaksh/add_question.html
@@ -38,44 +38,18 @@
<a href="{{file.file.url}}">{{ file.file.name }}</a>
{% endfor %}{% endif %}
</table></center>
+ {% for formset in formsets %}
<div class="form-group">
- {{ standardformset.management_form }}
+ {{ formset.management_form }}
- {% for stdform in standardformset %}
+ {% for form in formset %}
<div class="link-formset well">
- {{ stdform.as_p }}
+ {{ form.as_p }}
</div>
{% endfor %}
</div>
- <br \>
- <div class="form-group">
- {{ stdioformset.management_form }}
- {% for ioform in stdioformset %}
- <div class="link-formset well">
- {{ ioform.as_p }}
- </div>
- {% endfor %}
-
- </div>
- <div class="form-group">
- {{ mcqformset.management_form }}
-
- {% for mcqform in mcqformset %}
- <div class="link-formset well">
- {{ mcqform.as_p }}
- </div>
- {% endfor %}
- </div>
- <div class="form-group">
- {{ hookformset.management_form }}
-
- {% for hookform in hookformset %}
- <div class="link-formset well">
- {{ hookform.as_p }}
- </div>
- {% endfor %}
- </div>
+ {% endfor %}
<p><label for="case_type">Add Test Case:</label> <select id="case_type" name="case_type" onchange="frm.submit()">
<option value="" selected="selected">---------</option>
<option value="standardtestcase">Standard </option>
diff --git a/yaksh/views.py b/yaksh/views.py
index 5adddb8..98ec0fe 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -171,72 +171,35 @@ def add_question(request, question_id=None):
question.save()
files = request.FILES.getlist('file_field')
uploaded_files = FileUpload.objects.filter(question_id=question.id)
- StandardFormSet = inlineformset_factory(Question, StandardTestCase,
- extra=0, fields='__all__')
- standardformset = StandardFormSet(request.POST, request.FILES,
- instance=question)
- StdioFormSet = inlineformset_factory(Question, StdioBasedTestCase,
- extra=0, fields='__all__')
- stdioformset = StdioFormSet(request.POST, request.FILES,
- instance=question)
- McqFormSet = inlineformset_factory(Question, McqTestCase, extra=0,
- fields='__all__')
- mcqformset = McqFormSet(request.POST, request.FILES, instance=question)
- HookFormSet = inlineformset_factory(Question, HookTestCase, extra=0,
+ formsets = []
+ for testcase in TestCase.__subclasses__():
+ formset = inlineformset_factory(Question, testcase, extra=0,
fields='__all__')
- hookformset = HookFormSet(request.POST, request.FILES, instance=question)
- if standardformset.is_valid():
- standardformset.save()
- if mcqformset.is_valid():
- mcqformset.save()
- if stdioformset.is_valid():
- stdioformset.save()
- if hookformset.is_valid():
- hookformset.save()
+ formsets.append(formset(request.POST, request.FILES, instance=question))
+ for formset in formsets:
+ if formset.is_valid():
+ formset.save()
test_case_type = request.POST.get('case_type', None)
else:
context = {'qform': qform, 'fileform': fileform, 'question': question,
- 'mcqformset': mcqformset, 'stdioformset': stdioformset,
- 'standardformset': standardformset, 'hookformset': hookformset,
- 'uploaded_files': uploaded_files}
+ 'formsets': formsets, 'uploaded_files': uploaded_files}
return my_render_to_response("yaksh/add_question.html", context,
context_instance=ci)
qform = QuestionForm(instance=question)
fileform = FileForm()
uploaded_files = FileUpload.objects.filter(question_id=question.id)
- StandardFormSet = inlineformset_factory(Question, StandardTestCase, extra=0,
+ formsets = []
+ for testcase in TestCase.__subclasses__():
+ if test_case_type == testcase.__name__.lower():
+ formset = inlineformset_factory(Question, testcase, extra=1,
fields='__all__')
- standardformset = StandardFormSet(instance=question)
- StdioFormSet = inlineformset_factory(Question, StdioBasedTestCase, extra=0,
- fields='__all__')
- stdioformset = StdioFormSet(instance=question)
- McqFormSet = inlineformset_factory(Question, McqTestCase, extra=0,
- fields='__all__')
- mcqformset = McqFormSet(instance=question)
- HookFormSet = inlineformset_factory(Question, HookTestCase, extra=0,
- fields='__all__')
- hookformset = HookFormSet(instance=question)
- if test_case_type == 'standardtestcase':
- StandardFormSet = inlineformset_factory(Question, StandardTestCase,
- extra=1, fields='__all__')
- standardformset = StandardFormSet(instance=question)
- elif test_case_type == 'stdiobasedtestcase':
- StdioFormSet = inlineformset_factory(Question, StdioBasedTestCase,
- extra=1, fields='__all__')
- stdioformset = StdioFormSet(instance=question)
- elif test_case_type == 'mcqtestcase':
- McqFormSet = inlineformset_factory(Question, McqTestCase, extra=1,
- fields='__all__')
- mcqformset = McqFormSet(instance=question)
- elif test_case_type == 'hooktestcase':
- HookFormSet = inlineformset_factory(Question, HookTestCase, extra=1,
+ else:
+ formset = inlineformset_factory(Question, testcase, extra=0,
fields='__all__')
- hookformset = HookFormSet(instance=question)
+ formsets.append(formset(instance=question))
context = {'qform': qform, 'fileform': fileform, 'question': question,
- 'mcqformset': mcqformset, 'stdioformset': stdioformset,
- 'standardformset': standardformset, 'hookformset': hookformset,
- 'uploaded_files': uploaded_files}
+ 'formsets': formsets, 'uploaded_files': uploaded_files}
return my_render_to_response("yaksh/add_question.html", context, context_instance=ci)