summaryrefslogtreecommitdiff
path: root/yaksh/forms.py
diff options
context:
space:
mode:
authorprathamesh2016-03-02 15:48:39 +0530
committerprathamesh2016-03-02 15:48:39 +0530
commitd9793c01304498d7f59820cf2ab2d7a5483851f8 (patch)
treee1e2b3fdfb64e9165c56be7115303ea69b14cd17 /yaksh/forms.py
parent3b055ad0ad3232a25408632a020d5e3c284c245b (diff)
downloadonline_test-d9793c01304498d7f59820cf2ab2d7a5483851f8.tar.gz
online_test-d9793c01304498d7f59820cf2ab2d7a5483851f8.tar.bz2
online_test-d9793c01304498d7f59820cf2ab2d7a5483851f8.zip
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.
Diffstat (limited to 'yaksh/forms.py')
-rw-r--r--yaksh/forms.py17
1 files changed, 14 insertions, 3 deletions
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']