diff options
-rw-r--r-- | yaksh/forms.py | 5 | ||||
-rw-r--r-- | yaksh/models.py | 5 | ||||
-rw-r--r-- | yaksh/templates/yaksh/addteacher.html | 57 | ||||
-rw-r--r-- | yaksh/templates/yaksh/course_detail.html | 2 | ||||
-rw-r--r-- | yaksh/templates/yaksh/courses.html | 5 | ||||
-rw-r--r-- | yaksh/templates/yaksh/user_data.html | 2 | ||||
-rw-r--r-- | yaksh/templates/yaksh/viewcourse.html | 51 | ||||
-rw-r--r-- | yaksh/urls.py | 3 | ||||
-rw-r--r-- | yaksh/views.py | 94 |
9 files changed, 213 insertions, 11 deletions
diff --git a/yaksh/forms.py b/yaksh/forms.py index 681eca0..16f82fb 100644 --- a/yaksh/forms.py +++ b/yaksh/forms.py @@ -6,7 +6,7 @@ from django.contrib.auth.models import User from taggit.managers import TaggableManager from taggit.forms import TagField from django.forms.models import inlineformset_factory - +from django.db.models import Q from string import letters, punctuation, digits import datetime @@ -138,7 +138,8 @@ class QuizForm(forms.ModelForm): queryset=Quiz.objects.filter(course__creator=user)) self.fields['prerequisite'].required = False self.fields['course'] = forms.ModelChoiceField( - queryset=Course.objects.filter(creator=user)) + queryset=Course.objects.filter(Q(creator=user)| + Q(teachers=user)).distinct()) class Meta: model = Quiz diff --git a/yaksh/models.py b/yaksh/models.py index 9b92791..65b4dc0 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -71,6 +71,8 @@ class Course(models.Model): requests = models.ManyToManyField(User, related_name='requests') rejected = models.ManyToManyField(User, related_name='rejected') created_on = models.DateTimeField(auto_now_add=True) + teachers = models.ManyToManyField(User, related_name='teachers') + def request(self, *users): self.requests.add(*users) @@ -116,6 +118,9 @@ class Course(models.Model): def deactivate(self): self.active = False + def add_teachers(self, *users): + self.teachers.add(*users) + def __unicode__(self): return self.name diff --git a/yaksh/templates/yaksh/addteacher.html b/yaksh/templates/yaksh/addteacher.html new file mode 100644 index 0000000..0ebbbbd --- /dev/null +++ b/yaksh/templates/yaksh/addteacher.html @@ -0,0 +1,57 @@ +{% extends "manage.html" %} + +{% block title %} Add teacher {% endblock title %} +{% block subtitle %} {{ course.name }} {% endblock %} + +{% block css %} +<link rel="stylesheet" media="all" type="text/css" href="{{ URL_ROOT }}/static/yaksh/css/course.css" /> +{% endblock %} + +{% block manage %} +<center><h3>Add Teachers for this course</h3><br></center> +<center><h3>Search teacher with username, firstname, lastname, email</h3><br></center> +<div align="center"> + <form action="{{ URL_ROOT }}/exam/manage/searchteacher/{{ course.id }}/" method="post"> + {% csrf_token %} + Search Teacher: <input type="text" name="uname" style="height: 25px; padding: 0px"><br><br> + <center><button class="btn" type="submit">Search</button> + <button class="btn" type="button" name="button" onClick='location.replace("{{URL_ROOT}}/exam/manage/courses");'>Cancel</button> </center></form> +</div> +<br><br> +<form action="{{ URL_ROOT }}/exam/manage/addteacher/{{ course.id }}/" method="post"> +{% csrf_token %} +{% if success == True %} + {% if teachers|length == 1 or teachers|length == 0%} + <center><h3>No results found</h3></center> + {% else %} + <center><b><u>Search Results</u></b></center><br> + <table> + <th></th> + <th>First Name</th> + <th>Last Name</th> + <th>Email</th> + <th>Institute</th> + <th>Department</th> + <th>Position</th> + {% for teacher in teachers %} + {% if teacher != user %} + <tr> + <td><input type="checkbox" name="check" value="{{ teacher.id }}"></td> + <td>{{ teacher.first_name }}</td> + <td>{{ teacher.last_name }}</td> + <td>{{ teacher.email }}</td> + <td>{{ teacher.profile.institute }}</td> + <td>{{ teacher.profile.department }}</td> + <td>{{ teacher.profile.position }}</td> + </tr> + {% endif %} + {% endfor %} + </table> + <button class="btn" type="submit">Add</button> + {% endif %} +{% endif %} +</form> +{% if status == True %} +<center><h3>Added Teacher(s) to this course</h3></center> +{% endif %} +{% endblock %}
\ No newline at end of file diff --git a/yaksh/templates/yaksh/course_detail.html b/yaksh/templates/yaksh/course_detail.html index 7169667..44fab21 100644 --- a/yaksh/templates/yaksh/course_detail.html +++ b/yaksh/templates/yaksh/course_detail.html @@ -11,6 +11,7 @@ <script language="JavaScript" type="text/javascript" src="{{ URL_ROOT }}/static/yaksh/js/course.js"></script> {% endblock %} {% block manage %} +{% for course in courses %} <div class="row"> <div class="span6 wrap"> <center><b><u>Requests</u></b></center><br> @@ -88,4 +89,5 @@ <div class="pull-right"> <a class="btn primary" href="{{URL_ROOT}}/exam/manage/toggle_status/{{ course.id }}/">{% if course.active %}Deactivate Course {% else %} Activate Course {% endif %}</a> </div> +{% endfor %} {% endblock %} diff --git a/yaksh/templates/yaksh/courses.html b/yaksh/templates/yaksh/courses.html index f8f8273..245c3cb 100644 --- a/yaksh/templates/yaksh/courses.html +++ b/yaksh/templates/yaksh/courses.html @@ -9,9 +9,11 @@ {% endblock %} {% 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> {% else %} +<center><h3> Course(s) created by you </h3></center> {% for course in courses %} <div class="row show-grid"> <div class="span14"> @@ -29,6 +31,9 @@ </br> </div> <div class="span6"> + <p><b><a href="{{URL_ROOT}}/exam/manage/searchteacher/{{course.id}}/">Add Teacher</a></b></p> + </div> + <div class="span6"> <p><b><u>Quiz(zes)</u></b></p> {% if course.get_quizzes %} {% for quiz in 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 }} <a href="{{URL_ROOT}}/exam/manage/monitor/">Monitor quiz</a> {% else %} {% with data.papers.0 as paper %} -<a href="{{URL_ROOT}}/exam/manage/monitor/{{paper.quiz.id}}/">Monitor quiz</a> +<a href="{{URL_ROOT}}/exam/manage/monitor/{{paper.question_paper.id}}/">Monitor quiz</a> {% 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 %}
+<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/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<course_id>\d+)/$', 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) ] 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) + |