From 29f93bce956af26e1b3ffe5ffc04e02c9f32de59 Mon Sep 17 00:00:00 2001 From: adityacp Date: Thu, 2 Jan 2020 15:34:18 +0530 Subject: Change UI in add grades template --- grades/forms.py | 33 +++++++++++- grades/models.py | 3 ++ grades/templates/add_grades.html | 97 +++++++++++++++++++++++++++-------- grades/templates/grading_systems.html | 46 ++++++++++++++++- grades/views.py | 6 +-- 5 files changed, 159 insertions(+), 26 deletions(-) (limited to 'grades') diff --git a/grades/forms.py b/grades/forms.py index 130659d..4f9c9a7 100644 --- a/grades/forms.py +++ b/grades/forms.py @@ -1,8 +1,39 @@ -from grades.models import GradingSystem +from grades.models import GradingSystem, GradeRange from django import forms class GradingSystemForm(forms.ModelForm): + + def __init__(self, *args, **kwargs): + super(GradingSystemForm, self).__init__(*args, **kwargs) + self.fields['name'].widget.attrs.update( + {'class': "form-control", 'placeholder': 'Grading Name'} + ) + self.fields['description'].widget.attrs.update( + {'class': "form-control", + 'placeholder': 'Grading description'} + ) class Meta: model = GradingSystem fields = ['name', 'description'] + + +class GradeRangeForm(forms.ModelForm): + def __init__(self, *args, **kwargs): + super(GradeRangeForm, self).__init__(*args, **kwargs) + self.fields['lower_limit'].widget.attrs.update( + {'class': "form-control", 'placeholder': 'Lower limit'} + ) + self.fields['upper_limit'].widget.attrs.update( + {'class': "form-control", 'placeholder': 'Upper limit'} + ) + self.fields['grade'].widget.attrs.update( + {'class': "form-control", 'placeholder': 'Grade'} + ) + self.fields['description'].widget.attrs.update( + {'class': "form-control", + 'placeholder': 'Description'} + ) + class Meta: + model = GradeRange + fields = "__all__" diff --git a/grades/models.py b/grades/models.py index fcea510..b395a24 100644 --- a/grades/models.py +++ b/grades/models.py @@ -44,3 +44,6 @@ class GradeRange(models.Model): upper_limit = models.FloatField() grade = models.CharField(max_length=10) description = models.CharField(max_length=127, null=True, blank=True) + + def __str__(self): + return self.system.name.title() diff --git a/grades/templates/add_grades.html b/grades/templates/add_grades.html index a3f52da..d05a9bb 100644 --- a/grades/templates/add_grades.html +++ b/grades/templates/add_grades.html @@ -1,9 +1,51 @@ {% extends "manage.html" %} +{% load custom_filters %} +{% block title %} Add/Edit Grading {% endblock %} {% block main %} - Back to Grading Systems -

-

Note: For grade range lower limit is inclusive and upper limit is exclusive

+


+
+
+ +
+
+
+
+ Note: For grade range lower limit is inclusive and upper limit is exclusive +

{% if not system_id %}
@@ -12,24 +54,39 @@ {% endif %} {% csrf_token %} - {{ grade_form }} + {% for field in grade_form %} + {{ field }} +
+ {% endfor %} + {{ formset.management_form }} +
+
+ {% for form in formset %} + {% for hidden in form.hidden_fields %} + {{ hidden }} + {% endfor %} + Grade Range {{forloop.counter}}. +
+ {% for field in form.visible_fields %} + {% if field.field.widget|is_checkbox %} + {{field.label}} + {% endif %} + {{ field }} +
+ {% endfor %} +
+ {% endfor %} +
- {{ formset.management_form }} -
- Grade Ranges -
- {% for form in formset %} -
- {{ form }} -
-
- {% endfor %} - {% if not is_default %} - - - {% else %} -

Note: This is a default grading system. You cannot change this.

- {% endif %} + {% if not is_default %} + + + {% else %} +
+ Note: This is a default grading system. You cannot change this. +
+ {% endif %} +

{% endblock %} diff --git a/grades/templates/grading_systems.html b/grades/templates/grading_systems.html index 3a71ebf..8129c72 100644 --- a/grades/templates/grading_systems.html +++ b/grades/templates/grading_systems.html @@ -1,8 +1,50 @@ {% extends "manage.html" %} +{% block title %} View Grading Systems {% endblock %} {% block main %} - Add a Grading System - Back to Courses +


+
+
+ +
+
+
+ +  Add a Grading System +

Available Grading Systems: diff --git a/grades/views.py b/grades/views.py index 67844bd..7403e4e 100644 --- a/grades/views.py +++ b/grades/views.py @@ -1,7 +1,7 @@ from django.shortcuts import render from django.contrib.auth.decorators import login_required from django.forms import inlineformset_factory -from grades.forms import GradingSystemForm +from grades.forms import GradingSystemForm, GradeRangeForm from grades.models import GradingSystem, GradeRange @@ -21,7 +21,7 @@ def add_grading_system(request, system_id=None): if system_id is not None: grading_system = GradingSystem.objects.get(id=system_id) GradeRangeFormSet = inlineformset_factory(GradingSystem, GradeRange, - fields='__all__', extra=0) + GradeRangeForm, extra=0) grade_form = GradingSystemForm(instance=grading_system) is_default = (grading_system is not None and grading_system.name == 'default') @@ -38,7 +38,7 @@ def add_grading_system(request, system_id=None): formset.save() if 'add' in request.POST: GradeRangeFormSet = inlineformset_factory( - GradingSystem, GradeRange, fields='__all__', extra=1 + GradingSystem, GradeRange, GradeRangeForm, extra=1 ) formset = GradeRangeFormSet(instance=grading_system) -- cgit From eb05d4b0bc3fd0e2ce5160f30251bd9b939ccef6 Mon Sep 17 00:00:00 2001 From: adityacp Date: Thu, 2 Jan 2020 15:56:43 +0530 Subject: Show the grading ranges in a single line --- grades/templates/add_grades.html | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'grades') diff --git a/grades/templates/add_grades.html b/grades/templates/add_grades.html index d05a9bb..97c3c47 100644 --- a/grades/templates/add_grades.html +++ b/grades/templates/add_grades.html @@ -60,21 +60,24 @@ {% endfor %} {{ formset.management_form }}
-
+
{% for form in formset %} {% for hidden in form.hidden_fields %} {{ hidden }} {% endfor %} Grade Range {{forloop.counter}}. -
- {% for field in form.visible_fields %} - {% if field.field.widget|is_checkbox %} - {{field.label}} - {% endif %} - {{ field }} -
- {% endfor %} -
+
+
+ {% for field in form.visible_fields %} +
+ {% if field.field.widget|is_checkbox %} + {{ field.label_tag }} + {% endif %} + {{ field }} +
+ {% endfor %} +
+
{% endfor %}
-- cgit From 664fa46ba041ebdc5912a3bf125056bbc52b1f95 Mon Sep 17 00:00:00 2001 From: adityacp Date: Fri, 3 Jan 2020 11:17:04 +0530 Subject: Remove unncessary break html tags and add bootstrap custom file input --- grades/templates/add_grades.html | 6 +++++- grades/templates/grading_systems.html | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'grades') diff --git a/grades/templates/add_grades.html b/grades/templates/add_grades.html index 97c3c47..6a9dec9 100644 --- a/grades/templates/add_grades.html +++ b/grades/templates/add_grades.html @@ -1,9 +1,9 @@ {% extends "manage.html" %} {% load custom_filters %} {% block title %} Add/Edit Grading {% endblock %} +{% block pagetitle %} Add/Edit Grading {% endblock %} {% block main %} -



+ + View Grading Systems + +

Note: For grade range lower limit is inclusive and upper limit is exclusive
diff --git a/grades/templates/grading_systems.html b/grades/templates/grading_systems.html index 8129c72..0b26e8e 100644 --- a/grades/templates/grading_systems.html +++ b/grades/templates/grading_systems.html @@ -1,8 +1,8 @@ {% extends "manage.html" %} {% block title %} View Grading Systems {% endblock %} +{% block pagetitle %} View Grading Systems {% endblock %} {% block main %} -