summaryrefslogtreecommitdiff
path: root/grades
diff options
context:
space:
mode:
Diffstat (limited to 'grades')
-rw-r--r--grades/models.py5
-rw-r--r--grades/templates/add_grades.html35
-rw-r--r--grades/templates/grading_systems.html2
-rw-r--r--grades/tests/test_views.py2
-rw-r--r--grades/views.py14
5 files changed, 46 insertions, 12 deletions
diff --git a/grades/models.py b/grades/models.py
index b395a24..656c0d1 100644
--- a/grades/models.py
+++ b/grades/models.py
@@ -5,7 +5,8 @@ from django.contrib.auth.models import User
class GradingSystem(models.Model):
name = models.CharField(max_length=255, unique=True)
description = models.TextField(default='About the grading system!')
- creator = models.ForeignKey(User, null=True, blank=True)
+ creator = models.ForeignKey(User, null=True, blank=True,
+ on_delete=models.CASCADE)
def get_grade(self, marks):
ranges = self.graderange_set.all()
@@ -39,7 +40,7 @@ class GradingSystem(models.Model):
class GradeRange(models.Model):
- system = models.ForeignKey(GradingSystem)
+ system = models.ForeignKey(GradingSystem, on_delete=models.CASCADE)
lower_limit = models.FloatField()
upper_limit = models.FloatField()
grade = models.CharField(max_length=10)
diff --git a/grades/templates/add_grades.html b/grades/templates/add_grades.html
index 59a344d..f53a337 100644
--- a/grades/templates/add_grades.html
+++ b/grades/templates/add_grades.html
@@ -14,7 +14,7 @@
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'yaksh:add_course' %}">
- Add New Course
+ Add/Edit Course
</a>
</li>
<li class="nav-item dropdown hide">
@@ -46,13 +46,44 @@
Note: For grade range lower limit is inclusive and upper limit is exclusive
</div>
<br>
+{% if messages %}
+ {% for message in messages %}
+ <div class="alert alert-dismissible alert-{{ message.tags }}">
+ <button type="button" class="close" data-dismiss="alert">
+ <i class="fa fa-close"></i>
+ </button>
+ <strong>{{ message }}</strong>
+ </div>
+ {% endfor %}
+ <br>
+{% endif %}
{% if not system_id %}
<form action="{% url 'grades:add_grade' %}" method="POST">
{% else %}
<form action="{% url 'grades:edit_grade' system_id %}" method="POST">
{% endif %}
{% csrf_token %}
- <table class="table">
+ <table class="table table-responsive-sm">
+ {% if grade_form.errors %}
+ {% for field in grade_form %}
+ {% for error in field.errors %}
+ <div class="alert alert-dismissible alert-danger">
+ <button type="button" class="close" data-dismiss="alert">
+ <i class="fa fa-close"></i>
+ </button>
+ <strong>{{ error|escape }}</strong>
+ </div>
+ {% endfor %}
+ {% endfor %}
+ {% for error in grade_form.non_field_errors %}
+ <div class="alert alert-dismissible alert-danger">
+ <button type="button" class="close" data-dismiss="alert">
+ <i class="fa fa-close"></i>
+ </button>
+ <strong>{{ error|escape }}</strong>
+ </div>
+ {% endfor %}
+ {% endif %}
{% for field in grade_form %}
{{ field }}
<hr>
diff --git a/grades/templates/grading_systems.html b/grades/templates/grading_systems.html
index 8102230..88adfa0 100644
--- a/grades/templates/grading_systems.html
+++ b/grades/templates/grading_systems.html
@@ -13,7 +13,7 @@
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'yaksh:add_course' %}">
- Add New Course
+ Add/Edit Course
</a>
</li>
<li class="nav-item dropdown hide">
diff --git a/grades/tests/test_views.py b/grades/tests/test_views.py
index 6b76565..6e066a4 100644
--- a/grades/tests/test_views.py
+++ b/grades/tests/test_views.py
@@ -1,6 +1,6 @@
from django.test import TestCase, Client
from django.contrib.auth.models import User
-from django.core.urlresolvers import reverse
+from django.urls import reverse
from grades.models import GradingSystem
diff --git a/grades/views.py b/grades/views.py
index 7403e4e..48cd8e3 100644
--- a/grades/views.py
+++ b/grades/views.py
@@ -1,6 +1,7 @@
from django.shortcuts import render
from django.contrib.auth.decorators import login_required
from django.forms import inlineformset_factory
+from django.contrib import messages
from grades.forms import GradingSystemForm, GradeRangeForm
from grades.models import GradingSystem, GradeRange
@@ -30,12 +31,13 @@ def add_grading_system(request, system_id=None):
formset = GradeRangeFormSet(request.POST, instance=grading_system)
grade_form = GradingSystemForm(request.POST, instance=grading_system)
if grade_form.is_valid():
- system = grade_form.save(commit=False)
- system.creator = user
- system.save()
- system_id = system.id
- if formset.is_valid():
- formset.save()
+ grading_system = grade_form.save(commit=False)
+ grading_system.creator = user
+ grading_system.save()
+ system_id = grading_system.id
+ if formset.is_valid():
+ formset.save()
+ messages.success(request, "Grading system saved successfully")
if 'add' in request.POST:
GradeRangeFormSet = inlineformset_factory(
GradingSystem, GradeRange, GradeRangeForm, extra=1