From 5d92e6fac7901c9829a759aec539e603dfb66038 Mon Sep 17 00:00:00 2001 From: adityacp Date: Tue, 26 Apr 2016 19:00:01 +0530 Subject: rebase changes --- yaksh/forms.py | 5 +- yaksh/models.py | 5 ++ yaksh/templates/yaksh/addteacher.html | 57 +++++++++++++++++++ yaksh/templates/yaksh/course_detail.html | 2 + yaksh/templates/yaksh/courses.html | 5 ++ yaksh/templates/yaksh/user_data.html | 2 +- yaksh/templates/yaksh/viewcourse.html | 51 +++++++++++++++++ yaksh/urls.py | 3 + yaksh/views.py | 94 +++++++++++++++++++++++++++++--- 9 files changed, 213 insertions(+), 11 deletions(-) create mode 100644 yaksh/templates/yaksh/addteacher.html create mode 100644 yaksh/templates/yaksh/viewcourse.html (limited to 'yaksh') 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 %} + +{% endblock %} + +{% block manage %} +

Add Teachers for this course


+

Search teacher with username, firstname, lastname, email


+
+
+ {% csrf_token %} + Search Teacher:

+
+
+
+

+
+{% csrf_token %} +{% if success == True %} + {% if teachers|length == 1 or teachers|length == 0%} +

No results found

+ {% else %} +
Search Results

+ + + + + + + + + {% for teacher in teachers %} + {% if teacher != user %} + + + + + + + + + + {% endif %} + {% endfor %} +
First NameLast NameEmailInstituteDepartmentPosition
{{ teacher.first_name }}{{ teacher.last_name }}{{ teacher.email }}{{ teacher.profile.institute }}{{ teacher.profile.department }}{{ teacher.profile.position }}
+ + {% endif %} +{% endif %} +
+{% if status == True %} +

Added Teacher(s) to this course

+{% 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 @@ {% endblock %} {% block manage %} +{% for course in courses %}
Requests

@@ -88,4 +89,5 @@ +{% 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 %} +View Allotted Courses
{% if not courses %}
You have not created any courses
{% else %} +

Course(s) created by you

{% for course in courses %}
@@ -28,6 +30,9 @@ {{ course.name }}
+

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