From 68aab21a767de33e9a798ca847bc788d7429507d Mon Sep 17 00:00:00 2001 From: CruiseDevice Date: Mon, 6 Jan 2020 01:10:58 +0530 Subject: Improve UI in addquestion template --- yaksh/forms.py | 33 ++++++++++- yaksh/static/yaksh/js/add_question.js | 11 +++- yaksh/templates/yaksh/add_question.html | 98 +++++++++++++++++++-------------- 3 files changed, 98 insertions(+), 44 deletions(-) (limited to 'yaksh') diff --git a/yaksh/forms.py b/yaksh/forms.py index 951fcc1..def9c32 100644 --- a/yaksh/forms.py +++ b/yaksh/forms.py @@ -264,6 +264,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'] @@ -271,7 +298,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 692af48..96917da 100644 --- a/yaksh/templates/yaksh/add_question.html +++ b/yaksh/templates/yaksh/add_question.html @@ -1,5 +1,6 @@ {% extends "manage.html" %} +{% block title %} Add Question {% endblock title %} {% block pagetitle %} Add Question {% endblock pagetitle %} {% block css %} @@ -17,33 +18,45 @@
{% csrf_token %} -
-
Summary: {{ qform.summary }}{{ qform.summary.errors }} -
Language: {{qform.language}}{{qform.language.errors}} -
Type: {{ qform.type }}{{qform.type.errors}} -
Points:{{qform.points }}{{ qform.points.errors }} -
Rendered:

-
Description: {{ qform.description}} {{qform.description.errors}} -
Tags: {{ qform.tags }} -
Rendered Solution:

-
Solution: {{ qform.solution }} -
Snippet: {{ qform.snippet }} -
Minimum Time(in minutes): {{ qform.min_time }} -
Partial Grading: {{ qform.partial_grading }} -
Grade Assignment Upload: {{ qform.grade_assignment_upload }} -
File: {{ fileform.file_field }}{{ fileform.file_field.errors }} - {% if uploaded_files %}
Uploaded files:
Check on delete to delete files, - extract to extract files and hide to hide files from student(if required)
- {% for file in uploaded_files %} -  delete  - {% if file.extract %} dont extract{% else %} - extract{% endif %}   - {% if file.hide %} show{% else %} - hide{% endif %} - {{ file.file.name }} -
- {% endfor %}{% endif %} -
+
+ +
Summary: {{ qform.summary }}{{ qform.summary.errors }} +
Language: {{qform.language}}{{qform.language.errors}} +
Type: {{ qform.type }}{{qform.type.errors}} +
Points:{{qform.points }}{{ qform.points.errors }} +
Rendered:

+
Description: {{ qform.description}} {{qform.description.errors}} +
Tags: {{ qform.tags }} +
Rendered Solution:

+
Solution: {{ qform.solution }} +
Snippet: {{ qform.snippet }} +
Minimum Time(in minutes): {{ qform.min_time }} +
Partial Grading: {{ qform.partial_grading }} +
Grade Assignment Upload: {{ qform.grade_assignment_upload }} +
File: +
+
+ {{ fileform.file_field }}{{ fileform.file_field.errors }} + +
+
+ {% if uploaded_files %} +
+ Uploaded files:
+ Check on delete to delete files, + extract to extract files and hide to hide files from student(if required)
+ {% for file in uploaded_files %} +  delete  + {% if file.extract %} dont extract{% else %}extract{% endif %}   + {% if file.hide %} show{% else %}hide{% endif %} + {{ file.file.name }} +
+ {% endfor %} + {% endif %} +
+
{% for formset in formsets %}
{{ formset.management_form }} @@ -56,21 +69,24 @@
{% endfor %} -

+
+ + +
- - - + + +
-- cgit From da4460ede9d857844f9ed8d6fe4ed877c34fab4c Mon Sep 17 00:00:00 2001 From: CruiseDevice Date: Mon, 6 Jan 2020 14:35:29 +0530 Subject: Resolve comments - Use django URL tag - Fix Add Testcase dropdown width --- yaksh/templates/yaksh/add_question.html | 145 ++++++++++++++++---------------- 1 file changed, 73 insertions(+), 72 deletions(-) (limited to 'yaksh') diff --git a/yaksh/templates/yaksh/add_question.html b/yaksh/templates/yaksh/add_question.html index 96917da..cd05516 100644 --- a/yaksh/templates/yaksh/add_question.html +++ b/yaksh/templates/yaksh/add_question.html @@ -1,93 +1,94 @@ {% extends "manage.html" %} - +{% load staticfiles %} {% block title %} Add Question {% endblock title %} {% block pagetitle %} Add Question {% endblock pagetitle %} {% block css %} - + {% endblock %} {% block script %} - - + + {% endblock %} {% block onload %} onload='javascript:textareaformat();' {% endblock %} {% block content %}
-
- {% csrf_token %} -
- -
Summary: {{ qform.summary }}{{ qform.summary.errors }} -
Language: {{qform.language}}{{qform.language.errors}} -
Type: {{ qform.type }}{{qform.type.errors}} -
Points:{{qform.points }}{{ qform.points.errors }} -
Rendered:

-
Description: {{ qform.description}} {{qform.description.errors}} -
Tags: {{ qform.tags }} -
Rendered Solution:

-
Solution: {{ qform.solution }} -
Snippet: {{ qform.snippet }} -
Minimum Time(in minutes): {{ qform.min_time }} -
Partial Grading: {{ qform.partial_grading }} -
Grade Assignment Upload: {{ qform.grade_assignment_upload }} -
File: -
-
- {{ fileform.file_field }}{{ fileform.file_field.errors }} - + + {% csrf_token %} +
+ {{qform.instance.language}} + +
Summary: {{ qform.summary }}{{ qform.summary.errors }} +
Language: {{qform.language}}{{qform.language.errors}} +
Type: {{ qform.type }}{{qform.type.errors}} +
Points:{{qform.points }}{{ qform.points.errors }} +
Rendered:

+
Description: {{ qform.description}} {{qform.description.errors}} +
Tags: {{ qform.tags }} +
Rendered Solution:

+
Solution: {{ qform.solution }} +
Snippet: {{ qform.snippet }} +
Minimum Time(in minutes): {{ qform.min_time }} +
Partial Grading: {{ qform.partial_grading }} +
Grade Assignment Upload: {{ qform.grade_assignment_upload }} +
File: +
+
+ {{ fileform.file_field }}{{ fileform.file_field.errors }} + +
- - {% if uploaded_files %} -
- Uploaded files:
- Check on delete to delete files, - extract to extract files and hide to hide files from student(if required)
- {% for file in uploaded_files %} -  delete  - {% if file.extract %} dont extract{% else %}extract{% endif %}   - {% if file.hide %} show{% else %}hide{% endif %} - {{ file.file.name }} + {% if uploaded_files %}
- {% endfor %} - {% endif %} -
-
- {% for formset in formsets %} -
- {{ formset.management_form }} + Uploaded files:
+ Check on delete to delete files, + extract to extract files and hide to hide files from student(if required)
+ {% for file in uploaded_files %} +  delete  + {% if file.extract %} dont extract{% else %}extract{% endif %}   + {% if file.hide %} show{% else %}hide{% endif %} + {{ file.file.name }} +
+ {% endfor %} + {% endif %} +
+
+ {% for formset in formsets %} +
+ {{ formset.management_form }} - {% for form in formset %} - - {% endfor %} + {% for form in formset %} + + {% endfor %} -
- {% endfor %} -
- -
-
- - - -
-
+ {% endfor %} +
+ + +
+
+ + Back to Questions + +
+
{% endblock %} -- cgit From 3995f0a05fe3e681a21116c158708598db0ada08 Mon Sep 17 00:00:00 2001 From: CruiseDevice Date: Mon, 6 Jan 2020 22:54:48 +0530 Subject: 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. --- yaksh/templates/yaksh/add_question.html | 59 ++++++++++++++++++++++++--------- yaksh/views.py | 22 +++++------- 2 files changed, 52 insertions(+), 29 deletions(-) (limited to 'yaksh') 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 %} - + {% endblock %} {% block script %} - - + + {% endblock %} {% block onload %} onload='javascript:textareaformat();' {% endblock %} {% block content %}
-
+ {% csrf_token %}
{{qform.instance.language}} @@ -71,18 +71,45 @@
{% endfor %}
- - + {% if question %} + + {% if question.type == "code" %} + {% if qform.instance.language == "bash" %} + + {% elif qform.instance.language == "scilab" %} + + {% else %} + + {% endif %} + {% else %} + + {% endif %} + {% endif %}
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 -- cgit