diff options
author | CruiseDevice | 2020-01-06 22:54:48 +0530 |
---|---|---|
committer | CruiseDevice | 2020-01-06 22:54:48 +0530 |
commit | 3995f0a05fe3e681a21116c158708598db0ada08 (patch) | |
tree | e0f56a299b4c351c7c417873dcb2b3be42078e1f /yaksh/views.py | |
parent | da4460ede9d857844f9ed8d6fe4ed877c34fab4c (diff) | |
download | online_test-3995f0a05fe3e681a21116c158708598db0ada08.tar.gz online_test-3995f0a05fe3e681a21116c158708598db0ada08.tar.bz2 online_test-3995f0a05fe3e681a21116c158708598db0ada08.zip |
Fix issue in add_question.html template
- Test case select dropdown now shows only testcase
type based on the question type.
- Fix blank question created issue in add_question template.
Diffstat (limited to 'yaksh/views.py')
-rw-r--r-- | yaksh/views.py | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/yaksh/views.py b/yaksh/views.py index b826c81..98fde00 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -213,12 +213,12 @@ def add_question(request, question_id=None): user = request.user test_case_type = None - if question_id is None: - question = Question(user=user) - question.save() - else: + if question_id is not None: question = Question.objects.get(id=question_id) - + uploaded_files = FileUpload.objects.filter(question_id=question.id) + else: + question = None + uploaded_files = [] if request.method == "POST" and 'delete_files' in request.POST: remove_files_id = request.POST.getlist('clear') if remove_files_id: @@ -252,7 +252,6 @@ def add_question(request, question_id=None): ) ) files = request.FILES.getlist('file_field') - uploaded_files = FileUpload.objects.filter(question_id=question.id) if qform.is_valid(): question = qform.save(commit=False) question.user = user @@ -263,6 +262,7 @@ def add_question(request, question_id=None): if formset.is_valid(): formset.save() test_case_type = request.POST.get('case_type', None) + uploaded_files = FileUpload.objects.filter(question_id=question.id) else: context = { 'qform': qform, @@ -271,13 +271,10 @@ def add_question(request, question_id=None): 'formsets': formsets, 'uploaded_files': uploaded_files } - return my_render_to_response( - request, "yaksh/add_question.html", context - ) + return render(request, "yaksh/add_question.html", context) qform = QuestionForm(instance=question) fileform = FileForm() - uploaded_files = FileUpload.objects.filter(question_id=question.id) formsets = [] for testcase in TestCase.__subclasses__(): if test_case_type == testcase.__name__.lower(): @@ -296,9 +293,8 @@ def add_question(request, question_id=None): ) context = {'qform': qform, 'fileform': fileform, 'question': question, 'formsets': formsets, 'uploaded_files': uploaded_files} - return my_render_to_response( - request, "yaksh/add_question.html", context - ) + + return render(request, "yaksh/add_question.html", context) @login_required |