summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCruiseDevice2020-01-06 22:54:48 +0530
committerCruiseDevice2020-01-06 22:54:48 +0530
commit3995f0a05fe3e681a21116c158708598db0ada08 (patch)
treee0f56a299b4c351c7c417873dcb2b3be42078e1f
parentda4460ede9d857844f9ed8d6fe4ed877c34fab4c (diff)
downloadonline_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.
-rw-r--r--yaksh/templates/yaksh/add_question.html59
-rw-r--r--yaksh/views.py22
2 files changed, 52 insertions, 29 deletions
diff --git a/yaksh/templates/yaksh/add_question.html b/yaksh/templates/yaksh/add_question.html
index cd05516..665e86a 100644
--- a/yaksh/templates/yaksh/add_question.html
+++ b/yaksh/templates/yaksh/add_question.html
@@ -4,19 +4,19 @@
{% block pagetitle %} Add Question {% endblock pagetitle %}
{% block css %}
-<link rel="stylesheet" type="text/css" href="{% static 'yaksh/css/autotaggit.css' %}">
+ <link rel="stylesheet" type="text/css" href="{% static 'yaksh/css/autotaggit.css' %}">
{% endblock %}
{% block script %}
-<script type="text/javascript" src="{% static 'yaksh/js/add_question.js' %}"></script>
-<script type="text/javascript" src="{% static 'yaksh/js/mathjax/MathJax.js?config=TeX-MML-AM_CHTML' %}"></script>
+ <script type="text/javascript" src="{% static 'yaksh/js/add_question.js' %}"></script>
+ <script type="text/javascript" src="{% static 'yaksh/js/mathjax/MathJax.js' %}?config=TeX-MML-AM_CHTML"></script>
{% endblock %}
{% block onload %} onload='javascript:textareaformat();' {% endblock %}
{% block content %}
<div class="yakshwell container">
- <form action="{% url 'yaksh:add_question' question.id %}" method="post" name=frm onSubmit="return autosubmit();" enctype="multipart/form-data">
+ <form action="{% if question %}{% url 'yaksh:add_question' question.id %}{% endif %}" method="post" name=frm onSubmit="return autosubmit();" enctype="multipart/form-data">
{% csrf_token %}
<center>
{{qform.instance.language}}
@@ -71,18 +71,45 @@
</div>
{% endfor %}
<div class="form-group">
- <label for="case_type">Add Test Case:</label>
- <select id="case_type" class="form-control w-auto" name="case_type" onchange="frm.submit()">
- <option value="" selected="selected">---------</option>
- <option value="standardtestcase">Standard </option>
- <option value="stdiobasedtestcase">StdIO </option>
- <option value="mcqtestcase">MCQ/MCC </option>
- <option value="hooktestcase">Hook </option>
- <option value="integertestcase">Integer </option>
- <option value="stringtestcase"> String </option>
- <option value="floattestcase"> Float </option>
- <option value="arrangetestcase">Arrange options </option>
- </select>
+ {% if question %}
+ <label for="case_type">Add Test Case:</label>
+ {% if question.type == "code" %}
+ {% if qform.instance.language == "bash" %}
+ <select id="case_type" class="form-control w-auto" name="case_type" onchange="frm.submit()">
+ <option value="" selected="selected">---------</option>
+ <option value="standardtestcase">Standard </option>
+ <option value="stdiobasedtestcase">StdIO </option>
+ <option value="hooktestcase">Hook </option>
+ </select>
+ {% elif qform.instance.language == "scilab" %}
+ <select id="case_type" class="form-control w-auto" name="case_type" onchange="frm.submit()">
+ <option value="" selected="selected">---------</option>
+ <option value="standardtestcase">Standard </option>
+ <option value="hooktestcase">Hook </option>
+ </select>
+ {% else %}
+ <select id="case_type" class="form-control w-auto" name="case_type" onchange="frm.submit()">
+ <option value="" selected="selected">---------</option>
+ <option value="standardtestcase">Standard </option>
+ <option value="stdiobasedtestcase">StdIO </option>
+ <option value="hooktestcase">Hook </option>
+ <option value="easystandardtestcase">Easy Standard </option>
+ </select>
+ {% endif %}
+ {% else %}
+ <select id="case_type" class="form-control w-auto" name="case_type" onchange="frm.submit()">
+ <option value="" selected="selected">---------</option>
+ <option value="standardtestcase">Standard </option>
+ <option value="stdiobasedtestcase">StdIO </option>
+ <option value="mcqtestcase">MCQ/MCC </option>
+ <option value="hooktestcase">Hook </option>
+ <option value="integertestcase">Integer </option>
+ <option value="stringtestcase"> String </option>
+ <option value="floattestcase"> Float </option>
+ <option value="arrangetestcase">Arrange options </option>
+ </select>
+ {% endif %}
+ {% endif %}
</div>
<center>
<button class="btn btn-lg btn-success" type="submit" name="save_question">Save</button>
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