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 @@