From b259e65bbadc62a9368238e778af5c205b32f5f6 Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Mon, 8 Aug 2016 16:07:25 +0530 Subject: made UI changes to courses page and teacher can add another teacher --- yaksh/templates/yaksh/addteacher.html | 11 +++++- yaksh/templates/yaksh/courses.html | 74 ++++++++++++++++++++++++++++++++--- yaksh/urls.py | 1 - yaksh/views.py | 35 +++++++---------- 4 files changed, 93 insertions(+), 28 deletions(-) diff --git a/yaksh/templates/yaksh/addteacher.html b/yaksh/templates/yaksh/addteacher.html index 7e04f71..2ab107b 100644 --- a/yaksh/templates/yaksh/addteacher.html +++ b/yaksh/templates/yaksh/addteacher.html @@ -18,6 +18,13 @@

+ +{% if message %} +
+ Sorry! {{message}} +
+{% endif %} +
{% csrf_token %} {% if success == True %} @@ -57,7 +64,9 @@ {% if status == True %}
-
Teacher(s) Added

+
+ Congrats! Following Teachers have been added: +
{% if teachers_added %} {% for teacher in teachers_added %}
diff --git a/yaksh/templates/yaksh/courses.html b/yaksh/templates/yaksh/courses.html index 06c848c..1c68472 100644 --- a/yaksh/templates/yaksh/courses.html +++ b/yaksh/templates/yaksh/courses.html @@ -9,15 +9,12 @@ {% endblock %} {% block manage %} -View Allotted Courses
+ {% if not courses %}

No new Courses added

{% else %}

Course(s) Added

{% for course in courses %} - {% if user != course.creator %} -

{{course.creator.get_full_name}} added you to this course

- {% endif %}
@@ -79,7 +76,74 @@


{% endfor %} + {% endif %} + +{% if allotted_courses %} +

Course(s) Allotted

+ + {% for course in allotted_courses %} +
+
+
+
+

+ Course + {% if course.active %} + Active + {% else %} + Closed + {% endif %} +

+ {{ course.name }} +

+
+
+
Course Creator
+ {{course.creator}} +
Teacher(s) Added to {{ course }}
+ {% if course.get_teachers %} +
+ + {% csrf_token %} + {% for teacher in course.get_teachers %} +
+
+
+  {{ teacher.get_full_name }} +
+
+
+ {% endfor %} + +
+ {% else %} +
No Teacher(s) Added
+ {% endif %} + +
+
+
+ +
+

Quiz(zes)

+ {% if course.get_quizzes %} + {% for quiz in course.get_quizzes %} + {{ quiz.description }}
+ {% endfor %} + {% else %} +

No quiz

+ {% endif %} +
+
+
+
+

+ {% endfor %} +{% endif %} + {% if courses or allotted_courses %} -{% endif %} +{% 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\d+)/$', views.search_teacher), url(r'^manage/addteacher/(?P\d+)/$', views.add_teacher, name='add_teacher'), - url(r'^manage/allotted_course/$', views.allotted_courses), url(r'^manage/remove_teachers/(?P\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..a2f6f9a 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,7 +1166,7 @@ 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, Q(creator=user)|Q(teachers=user), pk=course_id) context['course'] = course if request.method == 'POST': @@ -1196,16 +1198,20 @@ 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) + course = get_object_or_404(Course, Q(creator=user)|Q(teachers=user), pk=course_id) context['course'] = course if request.method == 'POST': teacher_ids = request.POST.getlist('check') teachers = User.objects.filter(id__in=teacher_ids) - add_to_group(teachers) - course.add_teachers(*teachers) - context['status'] = True - context['teachers_added'] = teachers + if not course.creator in teachers: + add_to_group(teachers) + course.add_teachers(*teachers) + context['status'] = True + context['teachers_added'] = teachers + else: + context["message"] = "You cannot add course creator as teacher." + return my_render_to_response('yaksh/addteacher.html', context, context_instance=ci) else: @@ -1213,19 +1219,6 @@ def add_teacher(request, course_id): 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): -- cgit From 29c50ad458de008b0672d0f2b1c64278a963850c Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Tue, 9 Aug 2016 11:32:19 +0530 Subject: changed search_teacher function to exclude course creator --- yaksh/templates/yaksh/addteacher.html | 11 +---------- yaksh/templates/yaksh/courses.html | 4 ++-- yaksh/views.py | 21 ++++++++------------- 3 files changed, 11 insertions(+), 25 deletions(-) diff --git a/yaksh/templates/yaksh/addteacher.html b/yaksh/templates/yaksh/addteacher.html index 2ab107b..6722a52 100644 --- a/yaksh/templates/yaksh/addteacher.html +++ b/yaksh/templates/yaksh/addteacher.html @@ -19,12 +19,6 @@


-{% if message %} -
- Sorry! {{message}} -
-{% endif %} -
{% csrf_token %} {% if success == True %} @@ -63,10 +57,7 @@
{% if status == True %}
-
-
- Congrats! Following Teachers have been added: -
+
{% if teachers_added %} {% for teacher in teachers_added %}
diff --git a/yaksh/templates/yaksh/courses.html b/yaksh/templates/yaksh/courses.html index 1c68472..5e2266c 100644 --- a/yaksh/templates/yaksh/courses.html +++ b/yaksh/templates/yaksh/courses.html @@ -11,9 +11,9 @@ {% block manage %} {% if not courses %} -

No new Courses added

+

No new Courses created

{% else %} -

Course(s) Added

+

Course(s) Created

{% for course in courses %}
diff --git a/yaksh/views.py b/yaksh/views.py index a2f6f9a..c1dde5f 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -1177,7 +1177,8 @@ def search_teacher(request, course_id): 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(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, @@ -1204,18 +1205,12 @@ def add_teacher(request, course_id): if request.method == 'POST': teacher_ids = request.POST.getlist('check') teachers = User.objects.filter(id__in=teacher_ids) - if not course.creator in teachers: - add_to_group(teachers) - course.add_teachers(*teachers) - context['status'] = True - context['teachers_added'] = teachers - else: - context["message"] = "You cannot add course creator as teacher." + add_to_group(teachers) + 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) @@ -1228,7 +1223,7 @@ def remove_teachers(request, course_id): 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 request.method == "POST": teacher_ids = request.POST.getlist('remove') teachers = User.objects.filter(id__in=teacher_ids) -- cgit From d9f6a93ea8d4ddf9f139649567bd680e3f101556 Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Tue, 9 Aug 2016 18:12:25 +0530 Subject: modified add search and remove_teachers functions --- yaksh/views.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/yaksh/views.py b/yaksh/views.py index c1dde5f..4944691 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -1171,21 +1171,16 @@ def search_teacher(request, course_id): 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(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 @@ -1199,8 +1194,9 @@ def add_teacher(request, course_id): raise Http404('You are not allowed to view this page!') context = {} - course = get_object_or_404(Course, Q(creator=user)|Q(teachers=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 if request.method == 'POST': teacher_ids = request.POST.getlist('check') @@ -1220,10 +1216,10 @@ 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 or user in course.teachers.all()): raise Http404('You are not allowed to view this page!') - course = get_object_or_404(Course, Q(creator=user)|Q(teachers=user), pk=course_id) if request.method == "POST": teacher_ids = request.POST.getlist('remove') teachers = User.objects.filter(id__in=teacher_ids) -- cgit From 80e3a68ddfcc15fc88442d7af53d804653c4d2a4 Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Tue, 9 Aug 2016 18:13:22 +0530 Subject: added Course and question paper classes in admin.py --- yaksh/admin.py | 4 ++++ yaksh/models.py | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/yaksh/admin.py b/yaksh/admin.py index 2ce3ac4..b25c0af 100644 --- a/yaksh/admin.py +++ b/yaksh/admin.py @@ -1,10 +1,14 @@ 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(Course) admin.site.register(Quiz) admin.site.register(Course) +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): -- cgit From 5d49a64d11d6a6868c74bf9a22bb7cc0fa7b8c6b Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Mon, 29 Aug 2016 13:53:41 +0530 Subject: changed template; modified search_teacher, add_teacher and remove_teachers view functions --- yaksh/templates/yaksh/courses.html | 4 +++- yaksh/views.py | 9 +++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/yaksh/templates/yaksh/courses.html b/yaksh/templates/yaksh/courses.html index 5e2266c..42f49d1 100644 --- a/yaksh/templates/yaksh/courses.html +++ b/yaksh/templates/yaksh/courses.html @@ -141,9 +141,11 @@


{% endfor %} +{% else %} +

No new Courses allotted

{% endif %} + {% if courses or allotted_courses %} - {% endif %} {% endblock %} diff --git a/yaksh/views.py b/yaksh/views.py index 4944691..16454b2 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -1166,9 +1166,12 @@ def search_teacher(request, course_id): raise Http404('You are not allowed to view this page!') context = {} - course = get_object_or_404(Course, Q(creator=user)|Q(teachers=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 not len(u_name) == 0: @@ -1197,6 +1200,8 @@ def add_teacher(request, course_id): 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') @@ -1217,7 +1222,7 @@ def remove_teachers(request, course_id): user = request.user course = get_object_or_404(Course, pk=course_id) - if not is_moderator(user) and (user == course.creator or user in course.teachers.all()): + 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!') if request.method == "POST": -- cgit From b8c58435aef3b9c30ae8952f353648d70d228eec Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Mon, 29 Aug 2016 14:11:13 +0530 Subject: minor changes in admin --- yaksh/admin.py | 1 - 1 file changed, 1 deletion(-) diff --git a/yaksh/admin.py b/yaksh/admin.py index b25c0af..4ef2f3d 100644 --- a/yaksh/admin.py +++ b/yaksh/admin.py @@ -10,5 +10,4 @@ admin.site.register(StandardTestCase) admin.site.register(StdoutBasedTestCase) admin.site.register(Course) admin.site.register(Quiz) -admin.site.register(Course) admin.site.register(QuestionPaper) -- cgit