From d9793c01304498d7f59820cf2ab2d7a5483851f8 Mon Sep 17 00:00:00 2001 From: prathamesh Date: Wed, 2 Mar 2016 15:48:39 +0530 Subject: Course module implemented Moderator can now create courses. Under his courses he can create quizzes. Students can enroll for the course. Moderator can approve or reject enrollment request of the student. Student can view quizzes only for the enrolled course. --- yaksh/forms.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'yaksh/forms.py') diff --git a/yaksh/forms.py b/yaksh/forms.py index de40419..1af02f7 100644 --- a/yaksh/forms.py +++ b/yaksh/forms.py @@ -1,5 +1,5 @@ from django import forms -from yaksh.models import Profile, Quiz, Question, TestCase +from yaksh.models import Profile, Quiz, Question, TestCase, Course from django.contrib.auth import authenticate from django.contrib.auth.models import User @@ -132,12 +132,15 @@ class QuizForm(forms.Form): It has the related fields and functions required.""" def __init__(self, *args, **kwargs): + user = kwargs.pop('user') super(QuizForm, self).__init__(*args, **kwargs) quizzes = [('', 'Select a prerequisite quiz')] - quizzes = quizzes + \ - list(Quiz.objects.values_list('id', 'description')) + quizzes += list(Quiz.objects.filter( + course__creator=user).values_list('id', 'description')) self.fields['prerequisite'] = forms.CharField(required=False, widget=forms.Select(choices=quizzes)) + self.fields['course'] = forms.ModelChoiceField( + queryset=Course.objects.filter(creator=user)) start_date = forms.DateField(initial=datetime.date.today(), required=False) start_time = forms.TimeField(initial=datetime.datetime.now().time(), required=False) @@ -156,6 +159,7 @@ class QuizForm(forms.Form): help_text='Will be in days') def save(self): + course = self.cleaned_data["course"] start_date = self.cleaned_data["start_date"] start_time = self.cleaned_data["start_time"] end_date = self.cleaned_data["end_date"] @@ -169,6 +173,7 @@ class QuizForm(forms.Form): attempts_allowed = self.cleaned_data["attempts_allowed"] time_between_attempts = self.cleaned_data["time_between_attempts"] new_quiz = Quiz() + new_quiz.course = course new_quiz.start_date_time = datetime.datetime.combine(start_date, start_time) new_quiz.end_date_time = datetime.datetime.combine(end_date, @@ -265,3 +270,9 @@ class QuestionFilterForm(forms.Form): TestCaseFormSet = inlineformset_factory(Question, TestCase,\ can_order=False, can_delete=False, extra=1) + + +class CourseForm(forms.ModelForm): + class Meta: + model = Course + fields = ['name', 'active', 'enrollment'] -- cgit