summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--yaksh/forms.py33
-rw-r--r--yaksh/static/yaksh/js/add_question.js11
-rw-r--r--yaksh/templates/yaksh/add_question.html154
-rw-r--r--yaksh/views.py22
4 files changed, 149 insertions, 71 deletions
diff --git a/yaksh/forms.py b/yaksh/forms.py
index 4229598..73d4b54 100644
--- a/yaksh/forms.py
+++ b/yaksh/forms.py
@@ -300,6 +300,33 @@ class QuestionForm(forms.ModelForm):
"""Creates a form to add or edit a Question.
It has the related fields and functions required."""
+ def __init__(self, *args, **kwargs):
+ super(QuestionForm, self).__init__(*args, **kwargs)
+ self.fields['summary'].widget.attrs.update(
+ {'class': form_input_class, 'placeholder': 'Summary'}
+ )
+ self.fields['language'].widget.attrs.update(
+ {'class': 'custom-select'}
+ )
+ self.fields['type'].widget.attrs.update(
+ {'class': 'custom-select'}
+ )
+ self.fields['description'].widget.attrs.update(
+ {'class': form_input_class, 'placeholder': 'Description'}
+ )
+ self.fields['tags'].widget.attrs.update(
+ {'class': form_input_class, 'placeholder': 'Tags'}
+ )
+ self.fields['solution'].widget.attrs.update(
+ {'class': form_input_class, 'placeholder': 'Solution'}
+ )
+ self.fields['snippet'].widget.attrs.update(
+ {'class': form_input_class, 'placeholder': 'Snippet'}
+ )
+ self.fields['min_time'].widget.attrs.update(
+ {'class': form_input_class}
+ )
+
class Meta:
model = Question
exclude = ['user', 'active']
@@ -307,7 +334,11 @@ class QuestionForm(forms.ModelForm):
class FileForm(forms.Form):
file_field = forms.FileField(widget=forms.ClearableFileInput(
- attrs={'multiple': True}),
+ attrs={
+ 'multiple': True,
+ 'class': 'custom-file-input'
+ }
+ ),
required=False)
diff --git a/yaksh/static/yaksh/js/add_question.js b/yaksh/static/yaksh/js/add_question.js
index 0f02aab..2db5301 100644
--- a/yaksh/static/yaksh/js/add_question.js
+++ b/yaksh/static/yaksh/js/add_question.js
@@ -73,9 +73,9 @@ function replaceSelection (input, replaceString)
function textareaformat()
{
- document.getElementById('id_type').setAttribute('class','select-type');
+ document.getElementById('id_type').setAttribute('class','custom-select');
document.getElementById('id_points').setAttribute('class','mini-text');
- document.getElementById('id_tags').setAttribute('class','tag-text');
+ document.getElementById('id_tags').setAttribute('class','form-control');
$("[id*="+'test_case_args'+"]").attr('placeholder',
'Command Line arguments for bash only');
@@ -143,6 +143,13 @@ function textareaformat()
$("#id_grade_assignment_upload").prop("disabled", true);
}
});
+
+ $('#id_file_field').on('change',function(){
+ //get the file name
+ var fileName = $(this).val();
+ //replace the "Choose a file" label
+ $(this).next('.custom-file-label').html(fileName);
+ })
}
function autosubmit()
diff --git a/yaksh/templates/yaksh/add_question.html b/yaksh/templates/yaksh/add_question.html
index c4cd8a7..a400e35 100644
--- a/yaksh/templates/yaksh/add_question.html
+++ b/yaksh/templates/yaksh/add_question.html
@@ -1,52 +1,66 @@
{% extends "manage.html" %}
-
+{% load staticfiles %}
+{% block title %} Add Question {% endblock title %}
{% block pagetitle %} Add Question {% endblock pagetitle %}
{% block css %}
-<link rel="stylesheet" media="all" type="text/css" href="{{ URL_ROOT }}/static/yaksh/css/autotaggit.css" />
+ <link rel="stylesheet" type="text/css" href="{% static 'yaksh/css/autotaggit.css' %}">
{% endblock %}
{% block script %}
-<script src="{{ URL_ROOT }}/static/yaksh/js/add_question.js"></script>
-<script src="{{ URL_ROOT }}/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_ROOT }}/exam/manage/addquestion/{{ question.id }}/" method="post" name=frm onSubmit="return autosubmit();" enctype="multipart/form-data">
- {% csrf_token %}
- <center><table class="table table-responsive-sm">
- <tr><td>Summary: <td>{{ qform.summary }}{{ qform.summary.errors }}
- <tr><td> Language: <td> {{qform.language}}{{qform.language.errors}}
- <tr><td> Type: <td> {{ qform.type }}{{qform.type.errors}}
- <tr><td>Points:<td><button class="btn-mini" type="button" onClick="increase(frm);">+</button>{{qform.points }}<button class="btn-mini" type="button" onClick="decrease(frm);">-</button>{{ qform.points.errors }}
- <tr><td><strong>Rendered: </strong><td><p id='my'></p>
- <tr><td>Description: <td>{{ qform.description}} {{qform.description.errors}}
- <tr><td>Tags: <td>{{ qform.tags }}
- <tr><td><strong>Rendered Solution: </strong><td><p id='rend_solution'></p>
- <tr><td>Solution: <td>{{ qform.solution }}
- <tr><td>Snippet: <td>{{ qform.snippet }}
- <tr><td>Minimum Time(in minutes):<td> {{ qform.min_time }}
- <tr><td>Partial Grading: <td>{{ qform.partial_grading }}
- <tr><td>Grade Assignment Upload:<td> {{ qform.grade_assignment_upload }}
- <tr><td> File: <td> {{ fileform.file_field }}{{ fileform.file_field.errors }}
- {% if uploaded_files %}<br><b>Uploaded files:</b><br>Check on delete to delete files,
- extract to extract files and hide to hide files from student(if required)<br>
- {% for file in uploaded_files %}
- <input type="checkbox" name="clear" value="{{file.id}}">&nbsp;delete</input>&nbsp;
- <input type="checkbox" name="extract" value="{{file.id}}" >{% if file.extract %} dont extract{% else %}
- extract{% endif %}</input>&nbsp;&nbsp;
- <input type="checkbox" name="hide" value="{{file.id}}" >{% if file.hide %} show{% else %}
- hide{% endif %}</input>
- <a href="{{file.file.url}}">{{ file.file.name }}</a>
- <br>
- {% endfor %}{% endif %}
- </table></center>
- {% for formset in formsets %}
- <div class="form-group">
- {{ formset.management_form }}
+ <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}}
+ <table class="table table-responsive-sm">
+ <tr><td>Summary: <td>{{ qform.summary }}{{ qform.summary.errors }}
+ <tr><td> Language: <td> {{qform.language}}{{qform.language.errors}}
+ <tr><td> Type: <td> {{ qform.type }}{{qform.type.errors}}
+ <tr><td>Points:<td><button class="btn-mini" type="button" onClick="increase(frm);">+</button>{{qform.points }}<button class="btn-mini" type="button" onClick="decrease(frm);">-</button>{{ qform.points.errors }}
+ <tr><td><strong>Rendered: </strong><td><p id='my'></p>
+ <tr><td>Description: <td>{{ qform.description}} {{qform.description.errors}}
+ <tr><td>Tags: <td>{{ qform.tags }}
+ <tr><td><strong>Rendered Solution: </strong><td><p id='rend_solution'></p>
+ <tr><td>Solution: <td>{{ qform.solution }}
+ <tr><td>Snippet: <td>{{ qform.snippet }}
+ <tr><td>Minimum Time(in minutes):<td> {{ qform.min_time }}
+ <tr><td>Partial Grading: <td>{{ qform.partial_grading }}
+ <tr><td>Grade Assignment Upload:<td> {{ qform.grade_assignment_upload }}
+ <tr><td> File: <td>
+ <div class="input-group mb-3">
+ <div class="custom-file">
+ {{ fileform.file_field }}{{ fileform.file_field.errors }}
+ <label class="custom-file-label" for="id_file">
+ Choose file
+ </label>
+ </div>
+ </div>
+ {% if uploaded_files %}
+ <br>
+ <b>Uploaded files:</b><br>
+ Check on delete to delete files,
+ extract to extract files and hide to hide files from student(if required)<br>
+ {% for file in uploaded_files %}
+ <input type="checkbox" name="clear" value="{{file.id}}">&nbsp;delete</input>&nbsp;
+ <input type="checkbox" name="extract" value="{{file.id}}" >{% if file.extract %} dont extract{% else %}extract{% endif %}</input>&nbsp;&nbsp;
+ <input type="checkbox" name="hide" value="{{file.id}}" >{% if file.hide %} show{% else %}hide{% endif %}</input>
+ <a href="{{file.file.url}}">{{ file.file.name }}</a>
+ <br>
+ {% endfor %}
+ {% endif %}
+ </table>
+ </center>
+ {% for formset in formsets %}
+ <div class="form-group">
+ {{ formset.management_form }}
{% for form in formset %}
<div class="link-formset well">
@@ -56,24 +70,54 @@
</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>
- <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></p>
- <center>
- <button class="btn btn-success" type="submit" name="save_question">Save</button>
- <button class="btn btn-info" type="button" name="button" onClick='location.replace("{{URL_ROOT}}/exam/manage/questions/");'>Back to Questions</button>
- <button class="btn btn-danger" type="submit" name="delete_files">Delete Selected Files</button>
- </center>
-</form>
+ </div>
+ {% endfor %}
+ <div class="form-group">
+ {% 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>
+ <a class="btn btn-lg btn-info" href="{% url 'yaksh:show_questions' %}">Back to Questions</a>
+ <button class="btn btn-lg btn-danger" type="submit" name="delete_files">Delete Selected Files</button>
+ </center>
+ </form>
</div>
{% endblock %}
diff --git a/yaksh/views.py b/yaksh/views.py
index 6a0794f..d1e8b7b 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -224,12 +224,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:
@@ -267,7 +267,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
@@ -278,6 +277,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,
@@ -286,13 +286,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():
@@ -311,9 +308,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