summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPrabhu Ramachandran2016-08-30 16:14:51 +0530
committerGitHub2016-08-30 16:14:51 +0530
commitfb1877472b80b45d51e926966d6d21ca80b9ae9f (patch)
treef6a56a982a59e0ee3ecaf7dd5f47837c84f3c88b
parentdc7cde8882ecd993b90f08090e7d499f063aadf2 (diff)
parentb8c58435aef3b9c30ae8952f353648d70d228eec (diff)
downloadonline_test-fb1877472b80b45d51e926966d6d21ca80b9ae9f.tar.gz
online_test-fb1877472b80b45d51e926966d6d21ca80b9ae9f.tar.bz2
online_test-fb1877472b80b45d51e926966d6d21ca80b9ae9f.zip
Merge pull request #122 from maheshgudi/course_changes
made UI changes to courses page and teacher can add another teacher
-rw-r--r--yaksh/admin.py5
-rw-r--r--yaksh/models.py4
-rw-r--r--yaksh/templates/yaksh/addteacher.html4
-rw-r--r--yaksh/templates/yaksh/courses.html82
-rw-r--r--yaksh/urls.py1
-rw-r--r--yaksh/views.py57
6 files changed, 106 insertions, 47 deletions
diff --git a/yaksh/admin.py b/yaksh/admin.py
index 2ce3ac4..4ef2f3d 100644
--- a/yaksh/admin.py
+++ b/yaksh/admin.py
@@ -1,10 +1,13 @@
from yaksh.models import Question, Quiz
from yaksh.models import TestCase, StandardTestCase, StdoutBasedTestCase, Course
+from yaksh.models import Question, Quiz, Course, QuestionPaper
+from yaksh.models import TestCase, StandardTestCase, StdoutBasedTestCase
from django.contrib import admin
admin.site.register(Question)
admin.site.register(TestCase)
admin.site.register(StandardTestCase)
admin.site.register(StdoutBasedTestCase)
-admin.site.register(Quiz)
admin.site.register(Course)
+admin.site.register(Quiz)
+admin.site.register(QuestionPaper)
diff --git a/yaksh/models.py b/yaksh/models.py
index 73d4b27..898662c 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -570,7 +570,9 @@ class QuestionPaper(models.Model):
if self.quiz.has_prerequisite():
prerequisite = self._get_prequisite_paper()
return prerequisite._is_questionpaper_passed(user)
-
+
+ def __unicode__(self):
+ return "Question Paper for " + self.quiz.description
###############################################################################
class QuestionSet(models.Model):
diff --git a/yaksh/templates/yaksh/addteacher.html b/yaksh/templates/yaksh/addteacher.html
index 7e04f71..6722a52 100644
--- a/yaksh/templates/yaksh/addteacher.html
+++ b/yaksh/templates/yaksh/addteacher.html
@@ -18,6 +18,7 @@
<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 %}
@@ -56,8 +57,7 @@
</form>
{% if status == True %}
<div class="row">
- <div class="span6 offset4 wrap">
- <center><b><u>Teacher(s) Added</u></b></center><br>
+ <div class="span6 offset4 wrap">
{% if teachers_added %}
{% for teacher in teachers_added %}
<div class="well">
diff --git a/yaksh/templates/yaksh/courses.html b/yaksh/templates/yaksh/courses.html
index 06c848c..42f49d1 100644
--- a/yaksh/templates/yaksh/courses.html
+++ b/yaksh/templates/yaksh/courses.html
@@ -9,15 +9,12 @@
{% endblock %}
{% block manage %}
-<a href="{{URL_ROOT}}/exam/manage/allotted_course/">View Allotted Courses</a><br>
+
{% if not courses %}
- <center><h4> No new Courses added </h4></center>
+ <center><h4> No new Courses created </h4></center>
{% else %}
-<center><h3> Course(s) Added</h3></center>
+<center><h3> Course(s) Created</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">
@@ -79,7 +76,76 @@
</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 %}
+
+{% if allotted_courses %}
+ <center><h3> Course(s) Allotted </h3></center>
+
+ {% for course in allotted_courses %}
+ <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></br>
+ <div class="row">
+ <div class="span6 wrap">
+ <center><b><u> Course Creator</u></b></center>
+ {{course.creator}}
+ <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 }}">&nbsp;{{ 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>
+ </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 %}
+ <a href="{{URL_ROOT}}/exam/manage/addquiz/{{quiz.id}}/">{{ quiz.description }}</a><br>
+ {% endfor %}
+ {% else %}
+ <p><b>No quiz </b></p>
+ {% endif %}
+ </div>
+ </div>
+ </div>
+ </div>
+ <br><br>
+ {% endfor %}
+{% else %}
+ <center><h4> No new Courses allotted </h4></center>
{% endif %}
+<button class="btn primary" type="button" onClick='location.replace("{{URL_ROOT}}/exam/manage/add_course");'>Add New Course</button>
+ {% if courses or allotted_courses %}
+ <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 cd97dd4..d14ed1d 100644
--- a/yaksh/urls.py
+++ b/yaksh/urls.py
@@ -97,7 +97,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, name='add_teacher'),
- url(r'^manage/allotted_course/$', views.allotted_courses),
url(r'^manage/remove_teachers/(?P<course_id>\d+)/$', views.remove_teachers, name='remove_teacher'),
url(r'^manage/download_questions/$', views.show_all_questions),
url(r'^manage/upload_questions/$', views.show_all_questions),
diff --git a/yaksh/views.py b/yaksh/views.py
index e1ec44e..16454b2 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -664,8 +664,10 @@ def courses(request):
if not is_moderator(user):
raise Http404('You are not allowed to view this page')
courses = Course.objects.filter(creator=user, is_trial=False)
- return my_render_to_response('yaksh/courses.html', {'courses': courses},
- context_instance=ci)
+ allotted_courses = Course.objects.filter(teachers=user, is_trial=False)
+ context = {'courses': courses, "allotted_courses": allotted_courses}
+ return my_render_to_response('yaksh/courses.html', context,
+ context_instance=ci)
@login_required
@@ -1164,25 +1166,24 @@ def search_teacher(request, course_id):
raise Http404('You are not allowed to view this page!')
context = {}
- course = get_object_or_404(Course, creator=user, pk=course_id)
+ course = get_object_or_404(Course, pk=course_id)
context['course'] = course
+ if user != course.creator and user not in course.teachers.all():
+ 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:
- return my_render_to_response('yaksh/addteacher.html', context,
- context_instance=ci)
- else:
+ if not len(u_name) == 0:
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(Q(id=user.id)|Q(is_superuser=1))
+ Q(email__icontains=u_name)).exclude(Q(id=user.id)|Q(is_superuser=1)|
+ Q(id=course.creator.id))
context['success'] = True
context['teachers'] = teachers
- 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)
+
+ return my_render_to_response('yaksh/addteacher.html', context,
+ context_instance=ci)
@login_required
@@ -1196,8 +1197,11 @@ def add_teacher(request, course_id):
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
+ course = get_object_or_404(Course, pk=course_id)
+ if user == course.creator or user in course.teachers.all():
+ context['course'] = course
+ else:
+ raise Http404('You are not allowed to view this page!')
if request.method == 'POST':
teacher_ids = request.POST.getlist('check')
@@ -1206,36 +1210,21 @@ def add_teacher(request, course_id):
course.add_teachers(*teachers)
context['status'] = True
context['teachers_added'] = teachers
- return my_render_to_response('yaksh/addteacher.html', context,
- context_instance=ci)
- else:
- return my_render_to_response('yaksh/addteacher.html', context,
+
+ return my_render_to_response('yaksh/addteacher.html', context,
context_instance=ci)
-@login_required
-def allotted_courses(request):
- """ show courses allotted to a user """
-
- 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(teachers=user)
- return my_render_to_response('yaksh/courses.html', {'courses': courses},
- context_instance=ci)
-
@login_required
def remove_teachers(request, course_id):
""" remove user from a course """
user = request.user
- if not is_moderator(user):
+ course = get_object_or_404(Course, pk=course_id)
+ if not is_moderator(user) and (user != course.creator and user not in course.teachers.all()):
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)