From 3bbaff2ebca026042cce3deb025effb9e83e0859 Mon Sep 17 00:00:00 2001 From: adityacp Date: Wed, 28 Feb 2018 16:54:22 +0530 Subject: Change forms.py, models.py, test_models.py and templates - Add help text for timezone field in user registration form - Add new method in course model to get days remaining to start a course - Show start time and end time of a course to the students - Disallow to enroll to a course which is not active - Add model test for the new course method --- yaksh/forms.py | 6 +- yaksh/models.py | 8 ++ yaksh/templates/yaksh/course_modules.html | 166 +++++++++++++++--------------- yaksh/templates/yaksh/quizzes_user.html | 35 +++++-- yaksh/templates/yaksh/view_profile.html | 4 + yaksh/test_models.py | 18 ++++ 6 files changed, 143 insertions(+), 94 deletions(-) diff --git a/yaksh/forms.py b/yaksh/forms.py index 258a1ee..6b8d1c1 100644 --- a/yaksh/forms.py +++ b/yaksh/forms.py @@ -85,10 +85,12 @@ class UserRegisterForm(forms.Form): department = forms.CharField( max_length=64, help_text='Department you work/study at') position = forms.CharField( - max_length=64, help_text='Student/Faculty/Researcher/Industry/etc.') + max_length=64, + help_text='Student/Faculty/Researcher/Industry/Fellowship/etc.') timezone = forms.ChoiceField( choices=[(tz, tz) for tz in pytz.common_timezones], - initial=pytz.utc) + help_text='Course timings are shown based on the selected timezone', + initial=pytz.country_timezones['IN'][0]) def clean_username(self): u_name = self.cleaned_data["username"] diff --git a/yaksh/models.py b/yaksh/models.py index f065190..2e759ee 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -722,6 +722,14 @@ class Course(models.Model): percent = round((count / len(modules))) return percent + def days_remain_to_start(self): + """ Get the days remaining for the start of the course """ + if timezone.now() < self.start_enroll_time: + remaining_days = (self.start_enroll_time - timezone.now()).days + 1 + else: + remaining_days = 0 + return remaining_days + def __str__(self): return self.name diff --git a/yaksh/templates/yaksh/course_modules.html b/yaksh/templates/yaksh/course_modules.html index fad1be0..afbae75 100644 --- a/yaksh/templates/yaksh/course_modules.html +++ b/yaksh/templates/yaksh/course_modules.html @@ -18,102 +18,100 @@ {% endif %} {% if learning_modules %} - {% for module in learning_modules %} -
- - - - - - -
- - {{module.name|title}} - - - - - - View Lessons/Quizzes/Exercises - - {% get_module_status user module course as module_status %} - Status: - {% if module_status == "completed" %} - - {{module_status|title}} - - {% elif module_status == "inprogress" %} - - {{module_status|title}} - - {% else %} - - {{module_status|title}} - - {% endif %} -
-
-
- - - - - - - - {% for unit in module.get_learning_units %} +
Lesson/Quiz/ExerciseStatusTypeView AnswerPaper
+ {% for module in learning_modules %} - - - - {% endfor %} -
- {% if unit.type == "quiz" %} - {{unit.quiz.description}} - {% else %} - {{unit.lesson.name}} - {% endif %} + + {{module.name|title}} - {% get_unit_status course module unit user as status %} - {% if status == "completed" %} - {{status|title}} + - {% elif status == "inprogress" %} - {{status|title}} + - {% else %} - {{status|title}} - - {% endif %} - - {% if unit.type == "quiz" %} - {% if unit.quiz.is_exercise %} - Exercise - {% else %} - Quiz - {% endif %} - {% else %} - Lesson - {% endif %} + + View Lessons/Quizzes/Exercises +
+ + + + + + + + {% for unit in module.get_learning_units %} + + + + + + + {% endfor %} +
Lesson/Quiz/ExerciseStatusTypeView AnswerPaper
+ {% if unit.type == "quiz" %} + {{unit.quiz.description}} + {% else %} + {{unit.lesson.name}} + {% endif %} + + {% get_unit_status course module unit user as status %} + {% if status == "completed" %} + {{status|title}} + + {% elif status == "inprogress" %} + {{status|title}} + + {% else %} + {{status|title}} + + {% endif %} + + {% if unit.type == "quiz" %} + {% if unit.quiz.is_exercise %} + Exercise + {% else %} + Quiz + {% endif %} + {% else %} + Lesson + {% endif %} + + {% if unit.type == "quiz" %} + {% if unit.quiz.view_answerpaper %} + + Can View + {% else %} + + Cannot view now + {% endif %} + {% else %} + ------ + {% endif %} +
+
- {% if unit.type == "quiz" %} - {% if unit.quiz.view_answerpaper %} - Can View + {% get_module_status user module course as module_status %} + Status: + {% if module_status == "completed" %} + + {{module_status|title}} + + {% elif module_status == "inprogress" %} + + {{module_status|title}} + {% else %} - - Cannot view now + + {{module_status|title}} + {% endif %} - {% else %} - ------ - {% endif %}
-
- {% endfor %} + {% endfor %} + {% else %}

No lectures found

{% endif %} diff --git a/yaksh/templates/yaksh/quizzes_user.html b/yaksh/templates/yaksh/quizzes_user.html index cf08752..05af528 100644 --- a/yaksh/templates/yaksh/quizzes_user.html +++ b/yaksh/templates/yaksh/quizzes_user.html @@ -39,25 +39,44 @@ No Courses to display
- {% if not course.active %} - Closed - {% endif %} {% if user in course.requests.all %} Request Pending {% elif user in course.rejected.all %}Request Rejected {% elif user in course.students.all %}Enrolled {% else %} - {% if course.is_active_enrollment %} - {% if course.is_self_enroll %} - Enroll + {% if course.active %} + {% if course.is_active_enrollment %} + {% if course.is_self_enroll %} + Enroll + {% else %} + Enroll + {% endif %} {% else %} - Enroll + + Enrollment Closed + {% endif %} {% else %} - Enrollment Closed + + Course is not activated + {% endif %} {% endif %}
+
+ {% if course.days_remain_to_start != 0 %} + + {{course.days_remain_to_start}} day(s) to start + + {% endif %} +
+ {% if course.is_active_enrollment %} +
+ Start Date : {{course.start_enroll_time}} +
+ End Date  : {{course.end_enroll_time}} +
+ {% endif %} {% if course.instructions %}
diff --git a/yaksh/templates/yaksh/view_profile.html b/yaksh/templates/yaksh/view_profile.html index 5f06135..ce95226 100644 --- a/yaksh/templates/yaksh/view_profile.html +++ b/yaksh/templates/yaksh/view_profile.html @@ -31,6 +31,10 @@ + + + + Edit Profile {% endblock %} diff --git a/yaksh/test_models.py b/yaksh/test_models.py index cd4279b..6cedc4b 100644 --- a/yaksh/test_models.py +++ b/yaksh/test_models.py @@ -1665,6 +1665,24 @@ class CourseTestCases(unittest.TestCase): updated_percent = self.course.percent_completed(self.student1) self.assertEqual(updated_percent, 25) + def test_course_time_remaining_to_start(self): + # check if course has 0 days left to start + self.assertEqual(self.course.days_remain_to_start(), 0) + + # check if course has some days left to start + course_time = self.course.start_enroll_time + self.course.start_enroll_time = datetime( + 2199, 12, 31, 10, 8, 15, 0, + tzinfo=pytz.utc + ) + self.course.save() + updated_course = Course.objects.get(id=self.course.id) + time_diff = updated_course.start_enroll_time - timezone.now() + actual_days = time_diff.days + 1 + self.assertEqual(updated_course.days_remain_to_start(), actual_days) + self.course.start_enroll_time = course_time + self.course.save() + ############################################################################### class TestCaseTestCases(unittest.TestCase): -- cgit From b0df46ec36a043d3c51014cf5746d7def9cb17b9 Mon Sep 17 00:00:00 2001 From: adityacp Date: Thu, 8 Mar 2018 14:34:17 +0530 Subject: Change model method name in course model --- yaksh/models.py | 2 +- yaksh/templates/yaksh/quizzes_user.html | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/yaksh/models.py b/yaksh/models.py index 2e759ee..c8a4d4d 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -722,7 +722,7 @@ class Course(models.Model): percent = round((count / len(modules))) return percent - def days_remain_to_start(self): + def days_before_start(self): """ Get the days remaining for the start of the course """ if timezone.now() < self.start_enroll_time: remaining_days = (self.start_enroll_time - timezone.now()).days + 1 diff --git a/yaksh/templates/yaksh/quizzes_user.html b/yaksh/templates/yaksh/quizzes_user.html index 05af528..49f8d2d 100644 --- a/yaksh/templates/yaksh/quizzes_user.html +++ b/yaksh/templates/yaksh/quizzes_user.html @@ -63,9 +63,9 @@ No Courses to display {% endif %}
- {% if course.days_remain_to_start != 0 %} + {% if course.days_before_start != 0 %} - {{course.days_remain_to_start}} day(s) to start + {{course.days_before_start}} day(s) to start {% endif %}
-- cgit From d015f6e34d67ac71814f91f99d2bbdfa3458f3cc Mon Sep 17 00:00:00 2001 From: adityacp Date: Tue, 20 Mar 2018 12:26:18 +0530 Subject: Fix models test case --- yaksh/test_models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yaksh/test_models.py b/yaksh/test_models.py index 6cedc4b..a2613df 100644 --- a/yaksh/test_models.py +++ b/yaksh/test_models.py @@ -1667,7 +1667,7 @@ class CourseTestCases(unittest.TestCase): def test_course_time_remaining_to_start(self): # check if course has 0 days left to start - self.assertEqual(self.course.days_remain_to_start(), 0) + self.assertEqual(self.course.days_before_start(), 0) # check if course has some days left to start course_time = self.course.start_enroll_time @@ -1679,7 +1679,7 @@ class CourseTestCases(unittest.TestCase): updated_course = Course.objects.get(id=self.course.id) time_diff = updated_course.start_enroll_time - timezone.now() actual_days = time_diff.days + 1 - self.assertEqual(updated_course.days_remain_to_start(), actual_days) + self.assertEqual(updated_course.days_before_start(), actual_days) self.course.start_enroll_time = course_time self.course.save() -- cgit