summaryrefslogtreecommitdiff
path: root/yaksh/forms.py
diff options
context:
space:
mode:
authorankitjavalkar2020-01-06 15:51:20 +0530
committerGitHub2020-01-06 15:51:20 +0530
commit41581d20e18ed54e160a248216c9ad6576fe16bf (patch)
tree6a576f7e9ed6eb24da945bd9b666197060862881 /yaksh/forms.py
parent18188766cf1e91fe086ed8bfe2939d836ea92ff7 (diff)
parent6eca1dd646eff0c1f90c129e10e7959e79eb83a2 (diff)
downloadonline_test-41581d20e18ed54e160a248216c9ad6576fe16bf.tar.gz
online_test-41581d20e18ed54e160a248216c9ad6576fe16bf.tar.bz2
online_test-41581d20e18ed54e160a248216c9ad6576fe16bf.zip
Merge pull request #634 from ankitjavalkar/fix-grades
Fix bug to only allow self created grading systems to show up in the course form
Diffstat (limited to 'yaksh/forms.py')
-rw-r--r--yaksh/forms.py24
1 files changed, 17 insertions, 7 deletions
diff --git a/yaksh/forms.py b/yaksh/forms.py
index 57140bc..742212a 100644
--- a/yaksh/forms.py
+++ b/yaksh/forms.py
@@ -3,6 +3,7 @@ from yaksh.models import (
get_model_class, Profile, Quiz, Question, Course, QuestionPaper, Lesson,
LearningModule
)
+from grades.models import GradingSystem
from django.contrib.auth import authenticate
from django.contrib.auth.models import User
from django.conf import settings
@@ -268,6 +269,13 @@ class QuestionFilterForm(forms.Form):
class CourseForm(forms.ModelForm):
""" course form for moderators """
+ class Meta:
+ model = Course
+ fields = [
+ 'name', 'enrollment', 'active', 'code', 'instructions',
+ 'start_enroll_time', 'end_enroll_time', 'grading_system',
+ 'view_grade'
+ ]
def save(self, commit=True, *args, **kwargs):
instance = super(CourseForm, self).save(commit=False)
@@ -280,13 +288,15 @@ class CourseForm(forms.ModelForm):
instance.save()
return instance
- class Meta:
- model = Course
- fields = [
- 'name', 'enrollment', 'active', 'code', 'instructions',
- 'start_enroll_time', 'end_enroll_time', 'grading_system',
- 'view_grade'
- ]
+ def __init__(self, user, *args, **kwargs):
+ super(CourseForm, self).__init__(*args, **kwargs)
+ if self.instance.id and self.instance.teachers.filter(id=user.id).exists():
+ self.fields['grading_system'].widget.attrs['disabled'] = True
+ else:
+ grading_choices = GradingSystem.objects.filter(
+ creator=user
+ )
+ self.fields['grading_system'].queryset = grading_choices
class ProfileForm(forms.ModelForm):