diff options
-rw-r--r-- | yaksh/forms.py | 4 | ||||
-rw-r--r-- | yaksh/templates/yaksh/add_question.html | 3 | ||||
-rw-r--r-- | yaksh/views.py | 47 |
3 files changed, 20 insertions, 34 deletions
diff --git a/yaksh/forms.py b/yaksh/forms.py index c5bec4c..0eed8eb 100644 --- a/yaksh/forms.py +++ b/yaksh/forms.py @@ -180,10 +180,6 @@ class QuestionFilterForm(forms.Form): (choices=question_types)) -TestCaseFormSet = inlineformset_factory(Question, TestCase, fields='__all__', - can_order=False, can_delete=False, extra=1) - - class CourseForm(forms.ModelForm): class Meta: model = Course diff --git a/yaksh/templates/yaksh/add_question.html b/yaksh/templates/yaksh/add_question.html index 61b146c..1b1d28d 100644 --- a/yaksh/templates/yaksh/add_question.html +++ b/yaksh/templates/yaksh/add_question.html @@ -40,9 +40,6 @@ {% endif %} </form> </table></center> - <center><button class="btn" type="submit" name="add_test">Add Test Case</button> - <button class="btn" type="submit" name="delete_test">Remove Test Case</button> - </center><br> <center><button class="btn" type="submit" name="save_question">Save</button> <button class="btn" type="button" name="button" onClick='location.replace("{{URL_ROOT}}/exam/manage/questions/");'>Cancel</button> </center> </form> diff --git a/yaksh/views.py b/yaksh/views.py index a986d4c..f540351 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -146,14 +146,14 @@ def add_question(request, question_id=None): """To add a new question in the database. Create a new question and store it.""" - def add_or_delete_test_form(post_request, instance): - request_copy = post_request.copy() - if 'add_test' in post_request: - request_copy['test-TOTAL_FORMS'] = int(request_copy['test-TOTAL_FORMS']) + 1 - elif 'delete_test' in post_request: - request_copy['test-TOTAL_FORMS'] = int(request_copy['test-TOTAL_FORMS']) - 1 - test_case_formset = TestCaseFormSet(request_copy, prefix='test', instance=instance) - return test_case_formset + # def add_or_delete_test_form(post_request, instance): + # request_copy = post_request.copy() + # if 'add_test' in post_request: + # request_copy['test-TOTAL_FORMS'] = int(request_copy['test-TOTAL_FORMS']) + 1 + # elif 'delete_test' in post_request: + # request_copy['test-TOTAL_FORMS'] = int(request_copy['test-TOTAL_FORMS']) - 1 + # test_case_formset = TestCaseFormSet(request_copy, prefix='test', instance=instance) + # return test_case_formset user = request.user ci = RequestContext(request) @@ -163,7 +163,7 @@ def add_question(request, question_id=None): form = QuestionForm(request.POST) if form.is_valid(): if question_id is None: - test_case_formset = add_or_delete_test_form(request.POST, form.save(commit=False)) + # test_case_formset = add_or_delete_test_form(request.POST, form.save(commit=False)) if 'save_question' in request.POST: qtn = form.save(commit=False) qtn.user = user @@ -178,52 +178,45 @@ def add_question(request, question_id=None): {'form': form, 'formset': test_case_formset}, context_instance=ci) - return my_redirect("/exam/manage/questions") return my_render_to_response('yaksh/add_question.html', - {'form': form, - 'formset': test_case_formset}, + {'form': form}, + # 'formset': test_case_formset}, context_instance=ci) else: d = Question.objects.get(id=question_id) - form = QuestionForm(request.POST, instance=d) - test_case_formset = add_or_delete_test_form(request.POST, d) if 'save_question' in request.POST: qtn = form.save(commit=False) test_case_formset = TestCaseFormSet(request.POST, prefix='test', instance=qtn) form.save() question = Question.objects.get(id=question_id) - if test_case_formset.is_valid(): - test_case_formset.save() return my_redirect("/exam/manage/questions") return my_render_to_response('yaksh/add_question.html', - {'form': form, - 'formset': test_case_formset}, + {'form': form}, + # 'formset': test_case_formset}, context_instance=ci) else: - test_case_formset = TestCaseFormSet(prefix='test', instance=Question()) return my_render_to_response('yaksh/add_question.html', - {'form': form, - 'formset': test_case_formset}, + {'form': form}, + # 'formset': test_case_formset}, context_instance=ci) else: if question_id is None: form = QuestionForm() - test_case_formset = TestCaseFormSet(prefix='test', instance=Question()) + # test_case_formset = TestCaseFormSet(prefix='test', instance=Question()) return my_render_to_response('yaksh/add_question.html', - {'form': form, - 'formset': test_case_formset}, + {'form': form}, + # 'formset': test_case_formset}, context_instance=ci) else: d = Question.objects.get(id=question_id) form = QuestionForm(instance=d) - test_case_formset = TestCaseFormSet(prefix='test', instance=d) return my_render_to_response('yaksh/add_question.html', - {'form': form, - 'formset': test_case_formset}, + {'form': form}, + # 'formset': test_case_formset}, context_instance=ci) |