diff options
author | adityacp | 2016-04-28 12:22:30 +0530 |
---|---|---|
committer | adityacp | 2016-04-28 12:22:30 +0530 |
commit | 3438ca95172897b594c216967d51cf5771d75f73 (patch) | |
tree | 29567883d637b65deabcfb3a858730d8d1c97f99 /yaksh | |
parent | 6b09383890b8367628124a854810326d7bbac7c4 (diff) | |
download | online_test-3438ca95172897b594c216967d51cf5771d75f73.tar.gz online_test-3438ca95172897b594c216967d51cf5771d75f73.tar.bz2 online_test-3438ca95172897b594c216967d51cf5771d75f73.zip |
further commented changes
Diffstat (limited to 'yaksh')
-rw-r--r-- | yaksh/models.py | 3 | ||||
-rw-r--r-- | yaksh/templates/yaksh/addteacher.html | 2 | ||||
-rw-r--r-- | yaksh/templates/yaksh/courses.html | 2 | ||||
-rw-r--r-- | yaksh/tests.py | 19 | ||||
-rw-r--r-- | yaksh/urls.py | 2 | ||||
-rw-r--r-- | yaksh/views.py | 12 |
6 files changed, 28 insertions, 12 deletions
diff --git a/yaksh/models.py b/yaksh/models.py index bb85085..cb9582f 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -112,6 +112,9 @@ class Course(models.Model): def is_creator(self, user): return self.creator == user + def is_teacher(self, user): + return True if user in self.teachers.all() else False + def is_self_enroll(self): return True if self.enrollment == enrollment_methods[1][0] else False diff --git a/yaksh/templates/yaksh/addteacher.html b/yaksh/templates/yaksh/addteacher.html index 790c06c..6bb5c9a 100644 --- a/yaksh/templates/yaksh/addteacher.html +++ b/yaksh/templates/yaksh/addteacher.html @@ -50,7 +50,7 @@ {% endif %} {% endfor %} </table> - <button class="btn" type="submit">Add</button> + <button class="btn" type="submit">Add Selected</button> {% endif %} {% endif %} </form> diff --git a/yaksh/templates/yaksh/courses.html b/yaksh/templates/yaksh/courses.html index 43a9535..06c848c 100644 --- a/yaksh/templates/yaksh/courses.html +++ b/yaksh/templates/yaksh/courses.html @@ -9,7 +9,7 @@ {% endblock %} {% block manage %} -<a href="{{URL_ROOT}}/exam/manage/viewcourse/">View Allotted Courses</a><br> +<a href="{{URL_ROOT}}/exam/manage/allotted_course/">View Allotted Courses</a><br> {% if not courses %} <center><h4> No new Courses added </h4></center> {% else %} diff --git a/yaksh/tests.py b/yaksh/tests.py index bd733c3..831a0fb 100644 --- a/yaksh/tests.py +++ b/yaksh/tests.py @@ -21,6 +21,12 @@ def setUpModule(): Profile.objects.create(user=student, roll_number=3, institute='IIT', department='Chemical', position='Student') + student1 = User.objects.create_user(username='demo_user4', + password='demo', + email='demo@test.com') + Profile.objects.create(user=student1, roll_number=4, institute='IIT', + department='Chemical', position='Student') + # create group group = Group(name="moderator") group.save() @@ -393,6 +399,7 @@ class CourseTestCases(unittest.TestCase): self.creator = User.objects.get(pk=1) self.student1 = User.objects.get(pk=2) self.student2 = User.objects.get(pk=3) + self.student3 = User.objects.get(pk=4) self.quiz1 = Quiz.objects.get(pk=1) self.quiz2 = Quiz.objects.get(pk=2) @@ -457,6 +464,12 @@ class CourseTestCases(unittest.TestCase): def test_remove_teachers(self): """ Test to remove teachers from a course""" - self.course.add_teachers(self.student1, self.student2) - self.course.remove_teachers(self.student1) - self.assertSequenceEqual(self.course.get_teachers(), [self.student2]) + self.course.add_teachers(self.student2, self.student3) + self.course.remove_teachers(self.student2) + self.assertSequenceEqual(self.course.get_teachers(), [self.student3]) + + def test_is_teacher(self): + """ Test to check if user is teacher""" + self.course.add_teachers(self.student2) + result = self.course.is_teacher(self.student2) + self.assertTrue(result) diff --git a/yaksh/urls.py b/yaksh/urls.py index 1716818..ea1922d 100644 --- a/yaksh/urls.py +++ b/yaksh/urls.py @@ -87,6 +87,6 @@ urlpatterns += [ views.reject, {'was_enrolled': True}), url(r'^manage/searchteacher/(?P<course_id>\d+)/$', views.search_teacher), url(r'^manage/addteacher/(?P<course_id>\d+)/$', views.add_teacher), - url(r'^manage/viewcourse/$', views.view_courses), + url(r'^manage/allotted_course/$', views.allotted_courses), url(r'^manage/remove_teachers/(?P<course_id>\d+)/$', views.remove_teachers) ] diff --git a/yaksh/views.py b/yaksh/views.py index dd8cc2b..3823976 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -608,12 +608,11 @@ def courses(request): def course_detail(request, course_id): user = request.user ci = RequestContext(request) - if not is_moderator(user): - raise Http404('You are not allowed to view this page') course = Course.objects.filter(Q(creator=user)|Q(teachers=user), pk=course_id).first() - if user != course.creator and user not in course.teachers.all(): + if not is_moderator(user) or not course: raise Http404('You are not allowed to view this page') + return my_render_to_response('yaksh/course_detail.html', {'course': course}, context_instance=ci) @@ -843,7 +842,8 @@ def download_csv(request, questionpaper_id): if not is_moderator(user): raise Http404('You are not allowed to view this page!') quiz = Quiz.objects.get(questionpaper=questionpaper_id) - if quiz.course.creator != user and user not in quiz.course.teachers.all(): + + if not quiz.course.is_creator(user) and not quiz.course.is_teacher(user): raise Http404('The question paper does not belong to your course') papers = AnswerPaper.objects.get_latest_attempts(questionpaper_id) if not papers: @@ -1098,7 +1098,7 @@ def add_teacher(request, course_id): @login_required -def view_courses(request): +def allotted_courses(request): """ show courses allotted to a user """ user = request.user @@ -1113,7 +1113,7 @@ def view_courses(request): @login_required def remove_teachers(request, course_id): - """ show courses allotted to a user """ + """ remove user from a course """ user = request.user if not is_moderator(user): |