diff options
author | adityacp | 2020-02-18 13:29:24 +0530 |
---|---|---|
committer | adityacp | 2020-02-18 13:29:24 +0530 |
commit | 2db246f7abb2b8781e60673edec9912166621f4c (patch) | |
tree | e5b8ed04dc4c8fd28c401216313d1968d0d59edb /yaksh/views.py | |
parent | 8b0fb468fd94565b359f3c5bf2f2b694e7a9c97a (diff) | |
download | online_test-2db246f7abb2b8781e60673edec9912166621f4c.tar.gz online_test-2db246f7abb2b8781e60673edec9912166621f4c.tar.bz2 online_test-2db246f7abb2b8781e60673edec9912166621f4c.zip |
Change forms, views, models, templates
- Fix UI in add question page
- Add test case form for question formset with custom attributes
- Add a model method in question class to get question test cases
based on type and language of the question
- Retain the state of the list view and grid view in courses page
- Requested students list will be shown on top in the course detail page
Diffstat (limited to 'yaksh/views.py')
-rw-r--r-- | yaksh/views.py | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/yaksh/views.py b/yaksh/views.py index d1e8b7b..59efc59 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -44,7 +44,7 @@ from yaksh.forms import ( UserRegisterForm, UserLoginForm, QuizForm, QuestionForm, QuestionFilterForm, CourseForm, ProfileForm, UploadFileForm, FileForm, QuestionPaperForm, LessonForm, - LessonFileForm, LearningModuleForm, ExerciseForm + LessonFileForm, LearningModuleForm, ExerciseForm, TestcaseForm ) from yaksh.settings import SERVER_POOL_PORT, SERVER_HOST_NAME from .settings import URL_ROOT @@ -230,22 +230,21 @@ def add_question(request, question_id=None): 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: - files = FileUpload.objects.filter(id__in=remove_files_id) - for file in files: - file.remove() if request.method == 'POST': qform = QuestionForm(request.POST, instance=question) fileform = FileForm(request.POST, request.FILES) + remove_files_id = request.POST.getlist('clear') files = request.FILES.getlist('file_field') extract_files_id = request.POST.getlist('extract') hide_files_id = request.POST.getlist('hide') if files: for file in files: FileUpload.objects.get_or_create(question=question, file=file) + if remove_files_id: + files = FileUpload.objects.filter(id__in=remove_files_id) + for file in files: + file.remove() if extract_files_id: files = FileUpload.objects.filter(id__in=extract_files_id) for file in files: @@ -256,10 +255,10 @@ def add_question(request, question_id=None): file.toggle_hide_status() formsets = [] for testcase in TestCase.__subclasses__(): - formset = inlineformset_factory( Question, testcase, extra=0, fields='__all__', + form=TestcaseForm, formfield_callback=formfield_callback ) formsets.append(formset( @@ -278,6 +277,7 @@ def add_question(request, question_id=None): formset.save() test_case_type = request.POST.get('case_type', None) uploaded_files = FileUpload.objects.filter(question_id=question.id) + messages.success(request, "Question saved successfully") else: context = { 'qform': qform, @@ -286,6 +286,7 @@ def add_question(request, question_id=None): 'formsets': formsets, 'uploaded_files': uploaded_files } + messages.warning(request, "Unable to save the question") return render(request, "yaksh/add_question.html", context) qform = QuestionForm(instance=question) @@ -294,11 +295,13 @@ def add_question(request, question_id=None): for testcase in TestCase.__subclasses__(): if test_case_type == testcase.__name__.lower(): formset = inlineformset_factory( - Question, testcase, extra=1, fields='__all__' + Question, testcase, extra=1, fields='__all__', + form=TestcaseForm ) else: formset = inlineformset_factory( - Question, testcase, extra=0, fields='__all__' + Question, testcase, extra=0, fields='__all__', + form=TestcaseForm ) formsets.append( formset( @@ -308,6 +311,8 @@ def add_question(request, question_id=None): ) context = {'qform': qform, 'fileform': fileform, 'question': question, 'formsets': formsets, 'uploaded_files': uploaded_files} + if question is not None: + context["testcase_options"] = question.get_test_case_options() return render(request, "yaksh/add_question.html", context) |