From 171a82aa3ef07fc9344c8c5b42542bec0a3ca5ab Mon Sep 17 00:00:00 2001
From: ankitjavalkar
Date: Thu, 30 Mar 2017 18:10:09 +0530
Subject: Multiple changes to Course: - Allow a start and end time for Course
enrollment - Allow Course to be editable
---
yaksh/forms.py | 3 ++-
yaksh/models.py | 21 ++++++++++++++++++
yaksh/templates/yaksh/courses.html | 7 ++++--
yaksh/templates/yaksh/quizzes_user.html | 4 ++++
yaksh/test_models.py | 32 +++++++++++++++++++++++++++
yaksh/test_views.py | 5 +++--
yaksh/urls.py | 1 +
yaksh/views.py | 38 +++++++++++++++++++++++++++++++++
8 files changed, 106 insertions(+), 5 deletions(-)
(limited to 'yaksh')
diff --git a/yaksh/forms.py b/yaksh/forms.py
index c6283c8..a0eee71 100644
--- a/yaksh/forms.py
+++ b/yaksh/forms.py
@@ -276,7 +276,8 @@ class CourseForm(forms.ModelForm):
class Meta:
model = Course
- fields = ['name', 'active', 'enrollment', 'instructions']
+ fields = ['name', 'active', 'enrollment',
+ 'start_enroll_time', 'end_enroll_time', 'instructions']
class ProfileForm(forms.ModelForm):
diff --git a/yaksh/models.py b/yaksh/models.py
index 9e05af0..802a1fc 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -126,6 +126,24 @@ class Course(models.Model):
teachers = models.ManyToManyField(User, related_name='teachers')
is_trial = models.BooleanField(default=False)
instructions = models.TextField(default=None, null=True, blank=True)
+
+ # The start date of the course enrollment.
+ start_enroll_time = models.DateTimeField(
+ "Start Date and Time for enrollment of course",
+ default=timezone.now,
+ null=True
+ )
+
+ # The end date and time of the course enrollment
+ end_enroll_time = models.DateTimeField(
+ "End Date and Time for enrollment of course",
+ default=datetime(
+ 2199, 1, 1,
+ tzinfo=pytz.timezone(timezone.get_current_timezone_name())
+ ),
+ null=True
+ )
+
objects = CourseManager()
def request(self, *users):
@@ -134,6 +152,9 @@ class Course(models.Model):
def get_requests(self):
return self.requests.all()
+ def is_active_enrollment(self):
+ return self.start_enroll_time <= timezone.now() < self.end_enroll_time
+
def enroll(self, was_rejected, *users):
self.students.add(*users)
if not was_rejected:
diff --git a/yaksh/templates/yaksh/courses.html b/yaksh/templates/yaksh/courses.html
index 970d488..075d5aa 100644
--- a/yaksh/templates/yaksh/courses.html
+++ b/yaksh/templates/yaksh/courses.html
@@ -78,8 +78,11 @@
-
-
Quiz(zes)
{% if course.get_quizzes %} {% for quiz in course.get_quizzes %} {{ quiz.description }}No quiz
{% endif %}Question Paper(s)
+ {% for quiz in course.get_quizzes %} + {% if quiz.questionpaper_set.get %} + Question Paper for {{ quiz.description }}No Question Paper + Add +
+ {% endif %} + {% endfor %} +