diff options
Diffstat (limited to 'yaksh/forms.py')
-rw-r--r-- | yaksh/forms.py | 108 |
1 files changed, 81 insertions, 27 deletions
diff --git a/yaksh/forms.py b/yaksh/forms.py index def9c32..73d4b54 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 @@ -216,6 +217,13 @@ class UserLoginForm(forms.Form): class ExerciseForm(forms.ModelForm): + + def __init__(self, *args, **kwargs): + super(ExerciseForm, self).__init__(*args, **kwargs) + self.fields['description'].widget.attrs.update( + {'class': form_input_class, 'placeholder': "Exercise Description"} + ) + class Meta: model = Quiz fields = ['description', 'view_answerpaper', 'active'] @@ -228,6 +236,34 @@ class QuizForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(QuizForm, self).__init__(*args, **kwargs) + self.fields['start_date_time'].widget.attrs.update( + {'class': form_input_class} + ) + self.fields['end_date_time'].widget.attrs.update( + {'class': form_input_class} + ) + self.fields['duration'].widget.attrs.update( + {'class': form_input_class} + ) + self.fields['description'].widget.attrs.update( + {'class': form_input_class} + ) + self.fields['attempts_allowed'].widget.attrs.update( + {'class': 'custom-select'} + ) + self.fields['time_between_attempts'].widget.attrs.update( + {'class': form_input_class} + ) + self.fields['instructions'].widget.attrs.update( + {'class': form_input_class} + ) + self.fields['weightage'].widget.attrs.update( + {'class': form_input_class} + ) + self.fields['pass_criteria'].widget.attrs.update( + {'class': form_input_class} + ) + self.fields["instructions"].initial = dedent("""\ <p> This examination system has been developed with the intention of @@ -341,8 +377,26 @@ 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 __init__(self, *args, **kwargs): + def save(self, commit=True, *args, **kwargs): + instance = super(CourseForm, self).save(commit=False) + if instance.code: + instance.hidden = True + else: + instance.hidden = False + + if commit: + instance.save() + return instance + + def __init__(self, user, *args, **kwargs): super(CourseForm, self).__init__(*args, **kwargs) self.fields['name'].widget.attrs.update( {'class': form_input_class, 'placeholder': 'Course Name'} @@ -365,25 +419,14 @@ class CourseForm(forms.ModelForm): self.fields['grading_system'].widget.attrs.update( {'class': 'custom-select'} ) - - def save(self, commit=True, *args, **kwargs): - instance = super(CourseForm, self).save(commit=False) - if instance.code: - instance.hidden = True + if (self.instance.id and + self.instance.teachers.filter(id=user.id).exists()): + self.fields['grading_system'].widget.attrs['disabled'] = True else: - instance.hidden = False - - if commit: - instance.save() - return instance - - class Meta: - model = Course - fields = [ - 'name', 'enrollment', 'active', 'code', 'instructions', - 'start_enroll_time', 'end_enroll_time', 'grading_system', - 'view_grade' - ] + grading_choices = GradingSystem.objects.filter( + creator=user + ) + self.fields['grading_system'].queryset = grading_choices class ProfileForm(forms.ModelForm): @@ -446,9 +489,15 @@ class LessonForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(LessonForm, self).__init__(*args, **kwargs) des_msg = "Enter Lesson Description as Markdown text" - name_msg = "Enter Lesson Name" - self.fields['description'].widget.attrs['placeholder'] = des_msg - self.fields['name'].widget.attrs['placeholder'] = name_msg + self.fields['name'].widget.attrs.update( + {'class': form_input_class, 'placeholder': 'Lesson Name'} + ) + self.fields['description'].widget.attrs.update( + {'class': form_input_class, 'placeholder': des_msg} + ) + self.fields['video_file'].widget.attrs.update( + {'class': "custom-file-input"} + ) class Meta: model = Lesson @@ -468,17 +517,22 @@ class LessonForm(forms.ModelForm): class LessonFileForm(forms.Form): - Lesson_files = forms.FileField(widget=forms.ClearableFileInput( - attrs={'multiple': True}), - required=False) + Lesson_files = forms.FileField( + widget=forms.ClearableFileInput( + attrs={'multiple': True, 'class': "custom-file-input"}), + required=False) class LearningModuleForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(LearningModuleForm, self).__init__(*args, **kwargs) - name_msg = "Enter Learning Module Name" - self.fields['name'].widget.attrs['placeholder'] = name_msg self.fields['name'].widget.attrs['size'] = 30 + self.fields['name'].widget.attrs.update( + {'class': form_input_class, 'placeholder': 'Module Name'} + ) + self.fields['description'].widget.attrs.update( + {'class': form_input_class, 'placeholder': 'Module Description'} + ) class Meta: model = LearningModule |