diff options
Diffstat (limited to 'yaksh')
-rw-r--r-- | yaksh/forms.py | 24 | ||||
-rw-r--r-- | yaksh/views.py | 4 |
2 files changed, 19 insertions, 9 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): diff --git a/yaksh/views.py b/yaksh/views.py index 56f1873..c0317d9 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -982,7 +982,7 @@ def add_course(request, course_id=None): if not is_moderator(user): raise Http404('You are not allowed to view this page') if request.method == 'POST': - form = CourseForm(request.POST, instance=course) + form = CourseForm(user, request.POST, instance=course) if form.is_valid(): new_course = form.save(commit=False) if course_id is None: @@ -994,7 +994,7 @@ def add_course(request, course_id=None): request, 'yaksh/add_course.html', {'form': form} ) else: - form = CourseForm(instance=course) + form = CourseForm(user, instance=course) return my_render_to_response( request, 'yaksh/add_course.html', {'form': form} ) |