diff options
author | adityacp | 2016-04-27 16:42:32 +0530 |
---|---|---|
committer | adityacp | 2016-04-27 16:42:32 +0530 |
commit | 6b09383890b8367628124a854810326d7bbac7c4 (patch) | |
tree | 474ea52387e80a20580bba57120ef88b33f4c310 | |
parent | fa11260fdbe76f377909483d9c482ecf72ab3364 (diff) | |
download | online_test-6b09383890b8367628124a854810326d7bbac7c4.tar.gz online_test-6b09383890b8367628124a854810326d7bbac7c4.tar.bz2 online_test-6b09383890b8367628124a854810326d7bbac7c4.zip |
changes after comments
-rw-r--r-- | yaksh/models.py | 10 | ||||
-rw-r--r-- | yaksh/templates/yaksh/addteacher.html | 23 | ||||
-rw-r--r-- | yaksh/templates/yaksh/courses.html | 38 | ||||
-rw-r--r-- | yaksh/templates/yaksh/viewcourse.html | 51 | ||||
-rw-r--r-- | yaksh/tests.py | 16 | ||||
-rw-r--r-- | yaksh/urls.py | 3 | ||||
-rw-r--r-- | yaksh/views.py | 55 |
7 files changed, 112 insertions, 84 deletions
diff --git a/yaksh/models.py b/yaksh/models.py index 6db1298..bb85085 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -24,13 +24,11 @@ class Profile(models.Model): position = models.CharField(max_length=64) def is_moderator(self, user): - return True if user.groups.filter(name='moderator').exists() else False + return user.groups.filter(name='moderator').exists() def _add_to_group(self, user): group = Group.objects.get(name="moderator") user.groups.add(group) - user.profile.position = "Faculty" - user.profile.save() languages = ( ("python", "Python"), @@ -139,6 +137,12 @@ class Course(models.Model): rejected_teachers.append(teacher) return added_teachers, rejected_teachers + def get_teachers(self): + return self.teachers.all() + + def remove_teachers(self, *teachers): + self.teachers.remove(*teachers) + def __unicode__(self): return self.name diff --git a/yaksh/templates/yaksh/addteacher.html b/yaksh/templates/yaksh/addteacher.html index b438262..790c06c 100644 --- a/yaksh/templates/yaksh/addteacher.html +++ b/yaksh/templates/yaksh/addteacher.html @@ -25,8 +25,10 @@ <center><h3>No results found</h3></center> {% else %} <center><b><u>Search Results</u></b></center><br> + <center><b>Search results does not include teachers already added</b></center><br> <table> <th></th> + <th>Username</th> <th>First Name</th> <th>Last Name</th> <th>Email</th> @@ -34,8 +36,10 @@ <th>Department</th> <th>Position</th> {% for teacher in teachers %} + {% if teacher not in course.get_teachers %} <tr> <td><input type="checkbox" name="check" value="{{ teacher.id }}"></td> + <td>{{ teacher.username }}</td> <td>{{ teacher.first_name }}</td> <td>{{ teacher.last_name }}</td> <td>{{ teacher.email }}</td> @@ -43,6 +47,7 @@ <td>{{ teacher.profile.department }}</td> <td>{{ teacher.profile.position }}</td> </tr> + {% endif %} {% endfor %} </table> <button class="btn" type="submit">Add</button> @@ -51,31 +56,35 @@ </form> {% if status == True and teachers_added or teachers_rejected %} <center> -<h4>Note: Teacher(s) without profile are rejected</h4> +<h4>Teacher(s) without profile are rejected</h4> <div class="row"> <div class="span6 wrap"> <center><b><u>Teacher(s) Added</u></b></center><br> + {% if teachers_added %} {% for teacher in teachers_added %} <div class="well"> <div class="row"> - <div class="span3" style="padding-top:10px"> - <h5>{{ teacher.get_full_name }}</h5> - </div> + <h5>{{ teacher.get_full_name }}</h5> </div> </div> {% endfor %} + {% else %} + <center><b>No Teacher(s) Added</b></center> + {% endif %} </div> <div class="span6 wrap"> <center><b><u>Teacher(s) Rejected</u></b></center><br> + {% if teachers_rejected %} {% for teacher in teachers_rejected %} <div class="well"> <div class="row"> - <div class="span4" style="padding-top:10px"> - <h5>{{ teacher.get_full_name }}</h5> - </div> + <h5>{{ teacher.get_full_name }}</h5> </div> </div> {% endfor %} + {% else %} + <center><b>No Teacher(s) Rejected</b></center> + {% endif %} </div> </div> </center> diff --git a/yaksh/templates/yaksh/courses.html b/yaksh/templates/yaksh/courses.html index 245c3cb..43a9535 100644 --- a/yaksh/templates/yaksh/courses.html +++ b/yaksh/templates/yaksh/courses.html @@ -11,10 +11,13 @@ {% block manage %} <a href="{{URL_ROOT}}/exam/manage/viewcourse/">View Allotted Courses</a><br> {% if not courses %} - <center><h5> You have not created any courses </h5></center> + <center><h4> No new Courses added </h4></center> {% else %} -<center><h3> Course(s) created by you </h3></center> +<center><h3> Course(s) Added</h3></center> {% for course in courses %} + {% if user != course.creator %} + <h4> {{course.creator.get_full_name}} added you to this course</h4> + {% endif %} <div class="row show-grid"> <div class="span14"> <div class="row"> @@ -28,11 +31,39 @@ {% endif %} </p> <a href="{{URL_ROOT}}/exam/manage/course_detail/{{course.id}}/">{{ course.name }}</a> - </br> + </br></br> + {% if user == course.creator %} + <div class="row"> + <div class="span6 wrap"> + <center><b><u>Teacher(s) Added to {{ course }}</u></b></center> + {% if course.get_teachers %} + <div align="left"> + <form action="{{URL_ROOT}}/exam/manage/remove_teachers/{{ course.id }}/" method="post"> + {% csrf_token %} + {% for teacher in course.get_teachers %} + <div class="well"> + <div class="row"> + <div class="span3" style="width: auto;"> + <input type="checkbox" name="remove" value="{{ teacher.id }}"> {{ teacher.get_full_name }} + </div> + </div> + </div> + {% endfor %} + <button class="btn success" type="submit">Remove Selected</button> + </div> + {% else %} + <center><b>No Teacher(s) Added</b></center> + {% endif %} + </form> + </div> + </div> + {% endif %} </div> + {% if user == course.creator %} <div class="span6"> <p><b><a href="{{URL_ROOT}}/exam/manage/searchteacher/{{course.id}}/">Add Teacher</a></b></p> </div> + {% endif %} <div class="span6"> <p><b><u>Quiz(zes)</u></b></p> {% if course.get_quizzes %} @@ -48,7 +79,6 @@ </div> <br><br> {% endfor %} - <button class="btn primary" type="button" onClick='location.replace("{{URL_ROOT}}/exam/manage/add_course");'>Add New Course</button> <button class="btn primary" type="button" onClick='location.replace("{{URL_ROOT}}/exam/manage/addquiz");'>Add New Quiz</button> {% endif %} diff --git a/yaksh/templates/yaksh/viewcourse.html b/yaksh/templates/yaksh/viewcourse.html deleted file mode 100644 index a3ef3e6..0000000 --- a/yaksh/templates/yaksh/viewcourse.html +++ /dev/null @@ -1,51 +0,0 @@ -{% extends "manage.html" %}
-
-{% block title %} Courses {% endblock title %}
-
-{% block subtitle %} Courses {% endblock %}
-
-{% block css %}
-<link rel="stylesheet" media="all" type="text/css" href="{{ URL_ROOT }}/static/yaksh/css/course.css" />
-{% endblock %}
-
-{% block manage %}
-<center><h3> Course(s) Allotted </h3></center><br>
-{% if not courses %}
- <center><h3> You are not added to any course(s) </h3></center>
-{% else %}
-{% for course in courses %}
-<h4>{{ course.creator.get_full_name }} added you to this course</h4>
-<div class="row show-grid">
- <div class="span14">
- <div class="row">
- <div class="span6">
- <p>
- <b><u>Course</u></b>
- {% if course.active %}
- <span class="label success">Active</span>
- {% else %}
- <span class="label important">Closed</span>
- {% endif %}
- </p>
- <a href="{{URL_ROOT}}/exam/manage/course_detail/{{ course.id }}/">{{ course.name }}</a>
- </br>
- </div>
- <div class="span6">
- <p><b><u>Quiz(zes)</u></b></p>
- {% if course.get_quizzes %}
- {% for quiz in course.get_quizzes %}
- <a href="{{URL_ROOT}}/exam/manage/addquiz/{{ quiz.id }}/">{{ quiz.description }}</a><br>
- {% endfor %}
- {% else %}
- <p><b>No quiz </b>
- {% endif %}
- </div>
- </div>
- </div>
- </div>
- <br><br>
-{% endfor %}
-<button class="btn primary" type="button" onClick='location.replace("{{URL_ROOT}}/exam/manage/add_course");'>Add New Course</button>
-<button class="btn primary" type="button" onClick='location.replace("{{URL_ROOT}}/exam/manage/addquiz");'>Add New Quiz</button>
-{% endif %}
-{% endblock %}
diff --git a/yaksh/tests.py b/yaksh/tests.py index d69882d..bd733c3 100644 --- a/yaksh/tests.py +++ b/yaksh/tests.py @@ -60,13 +60,13 @@ def tearDownModule(): ############################################################################### class ProfileTestCases(unittest.TestCase): def setUp(self): - self.user = User.objects.get(pk=1) + self.user1 = User.objects.get(pk=1) self.profile = Profile.objects.get(pk=1) - self.user1 = User.objects.get(pk=3) + self.user2 = User.objects.get(pk=3) def test_user_profile(self): """ Test user profile""" - self.assertEqual(self.user.username, 'demo_user') + self.assertEqual(self.user1.username, 'demo_user') self.assertEqual(self.profile.user.username, 'demo_user') self.assertEqual(int(self.profile.roll_number), 1) self.assertEqual(self.profile.institute, 'IIT') @@ -74,9 +74,9 @@ class ProfileTestCases(unittest.TestCase): self.assertEqual(self.profile.position, 'Student') def test_is_moderator(self): - result = self.user1.profile.is_moderator(self.user1) + result = self.user2.profile.is_moderator(self.user2) self.assertTrue(result) - result = self.user.profile.is_moderator(self.user) + result = self.user1.profile.is_moderator(self.user1) self.assertFalse(result) ############################################################################### @@ -454,3 +454,9 @@ class CourseTestCases(unittest.TestCase): added_list, rejected_list = self.course.add_teachers(self.student1, self.student2) self.assertSequenceEqual(added_list, [self.student2]) self.assertSequenceEqual(rejected_list, [self.student1]) + + 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]) diff --git a/yaksh/urls.py b/yaksh/urls.py index 7f42faf..1716818 100644 --- a/yaksh/urls.py +++ b/yaksh/urls.py @@ -87,5 +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/viewcourse/$', views.view_courses), + url(r'^manage/remove_teachers/(?P<course_id>\d+)/$', views.remove_teachers) ] diff --git a/yaksh/views.py b/yaksh/views.py index a56182b..dd8cc2b 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -596,10 +596,12 @@ def self_enroll(request, course_id): @login_required def courses(request): user = request.user + ci = RequestContext(request) if not is_moderator(user): raise Http404('You are not allowed to view this page') courses = Course.objects.filter(creator=user) - return my_render_to_response('yaksh/courses.html', {'courses': courses}) + return my_render_to_response('yaksh/courses.html', {'courses': courses}, + context_instance=ci) @login_required @@ -608,8 +610,12 @@ def course_detail(request, course_id): 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() - return my_render_to_response('yaksh/course_detail.html', {'course': course}) + 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(): + raise Http404('You are not allowed to view this page') + return my_render_to_response('yaksh/course_detail.html', {'course': course}, + context_instance=ci) @login_required @@ -618,7 +624,8 @@ def enroll(request, course_id, user_id=None, was_rejected=False): 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() + course = Course.objects.filter(Q(creator=user)|Q(teachers=user), + pk=course_id).first() if request.method == 'POST': enroll_ids = request.POST.getlist('check') else: @@ -637,7 +644,8 @@ def reject(request, course_id, user_id=None, was_enrolled=False): 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() + course = Course.objects.filter(Q(creator=user)|Q(teachers=user), + pk=course_id).first() if request.method == 'POST': reject_ids = request.POST.getlist('check') else: @@ -655,7 +663,8 @@ def toggle_course_status(request, course_id): user = request.user 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() + course = Course.objects.filter(Q(creator=user)|Q(teachers=user), + pk=course_id).first() if course.active: course.deactivate() else: @@ -982,9 +991,6 @@ def view_profile(request): user = request.user ci = RequestContext(request) - if not is_moderator(user): - raise Http404('You are not allowed to view this page!') - context = {} if has_profile(user): return my_render_to_response('yaksh/view_profile.html', {'user':user}) @@ -996,6 +1002,7 @@ def view_profile(request): return my_render_to_response('yaksh/editprofile.html', context, context_instance=ci) + @login_required def edit_profile(request): """ edit profile details facility for moderator and students """ @@ -1031,12 +1038,18 @@ def edit_profile(request): context_instance=ci) +@login_required def search_teacher(request, course_id): """ search teachers for the course """ + user = request.user + ci = RequestContext(request) + + if not is_moderator(user): + raise Http404('You are not allowed to view this page!') + + context = {} course = get_object_or_404(Course, creator=user, pk=course_id) context['course'] = course - if not user.is_authenticated() or not is_moderator(user): - raise Http404('You are not allowed to view this page!') if request.method == 'POST': u_name = request.POST.get('uname') @@ -1074,15 +1087,16 @@ def add_teacher(request, course_id): teacher_ids = request.POST.getlist('check') teachers = User.objects.filter(id__in=teacher_ids) teachers_added, teachers_rejected = course.add_teachers(*teachers) + context['status'] = True context['teachers_added'] = teachers_added context['teachers_rejected'] = teachers_rejected - context['status'] = True return my_render_to_response('yaksh/addteacher.html', context, context_instance=ci) else: return my_render_to_response('yaksh/addteacher.html', context, context_instance=ci) + @login_required def view_courses(request): """ show courses allotted to a user """ @@ -1093,6 +1107,21 @@ def view_courses(request): raise Http404('You are not allowed to view this page!') courses = Course.objects.filter(teachers=user) - return my_render_to_response('yaksh/viewcourse.html', {'courses': courses}, + return my_render_to_response('yaksh/courses.html', {'courses': courses}, context_instance=ci) + +@login_required +def remove_teachers(request, course_id): + """ show courses allotted to a user """ + + user = request.user + if not is_moderator(user): + raise Http404('You are not allowed to view this page!') + + course = get_object_or_404(Course, creator=user, pk=course_id) + if request.method == "POST": + teacher_ids = request.POST.getlist('remove') + teachers = User.objects.filter(id__in=teacher_ids) + course.remove_teachers(*teachers) + return my_redirect('/exam/manage/courses') |