Quiz(zes)
{% if course.get_quizzes %}
diff --git a/yaksh/templates/yaksh/user_data.html b/yaksh/templates/yaksh/user_data.html
index 3350763..22be3ed 100644
--- a/yaksh/templates/yaksh/user_data.html
+++ b/yaksh/templates/yaksh/user_data.html
@@ -82,7 +82,7 @@ User IP address: {{ paper.user_ip }}
Monitor quiz
{% else %}
{% with data.papers.0 as paper %}
-
Monitor quiz
+
Monitor quiz
{% endwith %}
{% endif %}
diff --git a/yaksh/templates/yaksh/viewcourse.html b/yaksh/templates/yaksh/viewcourse.html
new file mode 100644
index 0000000..a3ef3e6
--- /dev/null
+++ b/yaksh/templates/yaksh/viewcourse.html
@@ -0,0 +1,51 @@
+{% extends "manage.html" %}
+
+{% block title %} Courses {% endblock title %}
+
+{% block subtitle %} Courses {% endblock %}
+
+{% block css %}
+
+{% endblock %}
+
+{% block manage %}
+
Course(s) Allotted
+{% if not courses %}
+
You are not added to any course(s)
+{% else %}
+{% for course in courses %}
+
{{ course.creator.get_full_name }} added you to this course
+
+
+
+
+
+ Course
+ {% if course.active %}
+ Active
+ {% else %}
+ Closed
+ {% endif %}
+
+
{{ course.name }}
+
+
+
+
Quiz(zes)
+ {% if course.get_quizzes %}
+ {% for quiz in course.get_quizzes %}
+
{{ quiz.description }}
+ {% endfor %}
+ {% else %}
+
No quiz
+ {% endif %}
+
+
+
+
+
+{% endfor %}
+
+
+{% endif %}
+{% endblock %}
diff --git a/yaksh/urls.py b/yaksh/urls.py
index 471a36b..9554750 100644
--- a/yaksh/urls.py
+++ b/yaksh/urls.py
@@ -85,4 +85,7 @@ urlpatterns += [
views.enroll, {'was_rejected': True}),
url(r'manage/enrolled/reject/(?P
\d+)/$',
views.reject, {'was_enrolled': True})
+ url(r'^manage/searchteacher/(?P\d+)/$', views.search_teacher),
+ url(r'^manage/addteacher/(?P\d+)/$', views.add_teacher),
+ url(r'^manage/viewcourse/$', views.view_courses)
]
diff --git a/yaksh/views.py b/yaksh/views.py
index 1709488..5ff4793 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -11,9 +11,10 @@ from django.contrib.auth import login, logout, authenticate
from django.shortcuts import render_to_response, get_object_or_404, redirect
from django.template import RequestContext
from django.http import Http404
-from django.db.models import Sum, Max
+from django.db.models import Sum, Max, Q
from django.views.decorators.csrf import csrf_exempt
from django.contrib.auth.decorators import login_required
+from django.contrib.auth.models import Group
from taggit.models import Tag
from itertools import chain
import json
@@ -610,7 +611,8 @@ def course_detail(request, course_id):
raise Http404('You are not allowed to view this page')
course = get_object_or_404(Course, creator=user, pk=course_id)
return my_render_to_response('yaksh/course_detail.html', {'course': course},
- context_instance=ci)
+ context_instance=ci)
+
@login_required
@@ -656,7 +658,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 = get_object_or_404(Course, creator=user, pk=course_id)
+ course = get_object_or_404(Course, Q(creator=user)|Q(teachers=user),
+ pk=course_id)
if course.active:
course.deactivate()
else:
@@ -701,7 +704,8 @@ def monitor(request, questionpaper_id=None):
raise Http404('You are not allowed to view this page!')
if questionpaper_id is None:
- q_paper = QuestionPaper.objects.filter(quiz__course__creator=user)
+ q_paper = QuestionPaper.objects.filter(Q(quiz__course__creator=user)|
+ Q(quiz__course__teachers=user)).distinct()
context = {'papers': [],
'quiz': None,
'quizzes': q_paper}
@@ -709,8 +713,9 @@ def monitor(request, questionpaper_id=None):
context_instance=ci)
# quiz_id is not None.
try:
- q_paper = QuestionPaper.objects.get(id=questionpaper_id,
- quiz__course__creator=user)
+ q_paper = QuestionPaper.objects.filter(Q(quiz__course__creator=user)|
+ Q(quiz__course__teachers=user),
+ id=questionpaper_id).distinct()
except QuestionPaper.DoesNotExist:
papers = []
q_paper = None
@@ -833,7 +838,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:
+ course = Course.objects.filter(teachers=user, id=quiz.course.id)
+ if quiz.course.creator != user and not course:
raise Http404('The question paper does not belong to your course')
papers = AnswerPaper.objects.get_latest_attempts(questionpaper_id)
if not papers:
@@ -978,7 +984,6 @@ def design_questionpaper(request):
@login_required
def view_profile(request):
""" view moderators and users profile """
-
user = request.user
ci = RequestContext(request)
context = {}
@@ -1025,3 +1030,76 @@ def edit_profile(request):
context['form'] = form
return my_render_to_response('yaksh/editprofile.html', context,
context_instance=ci)
+
+
+def search_teacher(request, course_id):
+ """ search teachers for the course """
+ 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')
+ if len(u_name) == 0:
+ context['success'] = False
+ return my_render_to_response('yaksh/addteacher.html', context,
+ context_instance=ci)
+ else:
+ teachers = User.objects.filter(Q(username__icontains=u_name)|
+ Q(first_name__icontains=u_name)|Q(last_name__icontains=u_name)|
+ Q(email__icontains=u_name)).exclude(is_superuser=1)
+ context['success'] = True
+ context['teachers'] = teachers
+ return my_render_to_response('yaksh/addteacher.html', context,
+ context_instance=ci)
+ else:
+ context['success'] = False
+ return my_render_to_response('yaksh/addteacher.html', context,
+ context_instance=ci)
+
+
+@login_required
+def add_teacher(request, course_id):
+ """ add teachers to the course also add students to
+ moderator group if a student is alotted to course """
+
+ user = request.user
+ ci = RequestContext(request)
+ 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':
+ teacher_ids = request.POST.getlist('check')
+ if not teacher_ids:
+ return my_render_to_response('yaksh/addteacher.html', context,
+ context_instance=ci)
+ else:
+ teachers = User.objects.filter(id__in=teacher_ids)
+ course.add_teachers(*teachers)
+ groupname = Group.objects.get(name='moderator')
+ groupname.user_set.add(*teachers)
+ context['status'] = True
+ for teacher in teachers:
+ if teacher.profile.position.lower() == "student":
+ teacher.profile.position = "Faculty"
+ teacher.profile.save()
+ 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 """
+
+ user = request.user
+ ci = RequestContext(request)
+ courses = Course.objects.filter(teachers=user)
+ return my_render_to_response('yaksh/viewcourse.html', {'courses': courses},
+ context_instance=ci)
+
--
cgit