From 887cfb20d0ba158aa0e0838d6b40f334084d202e Mon Sep 17 00:00:00 2001 From: adityacp Date: Thu, 2 Jan 2020 15:35:07 +0530 Subject: Change courses page with new UI --- yaksh/forms.py | 38 +- yaksh/static/yaksh/css/custom.css | 2 +- yaksh/static/yaksh/images/yaksh_circular_logo.png | Bin 0 -> 11577 bytes .../registration/password_change_done.html | 2 +- .../registration/password_change_form.html | 2 +- yaksh/templates/yaksh/add_course.html | 87 ++- yaksh/templates/yaksh/courses.html | 618 +++++---------------- yaksh/templates/yaksh/editprofile.html | 12 +- yaksh/templates/yaksh/moderator_dashboard.html | 70 +-- yaksh/templates/yaksh/paginator.html | 2 +- yaksh/templates/yaksh/profile_updated.html | 11 +- yaksh/templatetags/custom_filters.py | 6 + yaksh/urls.py | 2 + yaksh/views.py | 41 +- 14 files changed, 330 insertions(+), 563 deletions(-) create mode 100644 yaksh/static/yaksh/images/yaksh_circular_logo.png diff --git a/yaksh/forms.py b/yaksh/forms.py index aa4d7b9..8cc3d0a 100644 --- a/yaksh/forms.py +++ b/yaksh/forms.py @@ -308,6 +308,30 @@ class QuestionFilterForm(forms.Form): class CourseForm(forms.ModelForm): """ course form for moderators """ + def __init__(self, *args, **kwargs): + super(CourseForm, self).__init__(*args, **kwargs) + self.fields['name'].widget.attrs.update( + {'class': form_input_class, 'placeholder': 'Course Name'} + ) + self.fields['enrollment'].widget.attrs.update( + {'class': 'custom-select'} + ) + self.fields['code'].widget.attrs.update( + {'class': form_input_class, 'placeholder': 'Course Code'} + ) + self.fields['instructions'].widget.attrs.update( + {'class': form_input_class, 'placeholder': 'Course instructions'} + ) + self.fields['start_enroll_time'].widget.attrs.update( + {'class': form_input_class, 'placeholder': 'Course Start DateTime'} + ) + self.fields['end_enroll_time'].widget.attrs.update( + {'class': form_input_class, 'placeholder': 'Course End DateTime'} + ) + self.fields['grading_system'].widget.attrs.update( + {'class': 'custom-select'} + ) + def save(self, commit=True, *args, **kwargs): instance = super(CourseForm, self).save(commit=False) if instance.code: @@ -346,18 +370,24 @@ class ProfileForm(forms.ModelForm): user = kwargs.pop('user') super(ProfileForm, self).__init__(*args, **kwargs) self.fields['first_name'].initial = user.first_name + self.fields['first_name'].widget.attrs.update( + {'class': form_input_class, 'placeholder': 'First Name'} + ) self.fields['last_name'].initial = user.last_name + self.fields['last_name'].widget.attrs.update( + {'class': form_input_class, 'placeholder': 'Last Name'} + ) self.fields['institute'].widget.attrs.update( - {'class': form_input_class} + {'class': form_input_class, 'placeholder': 'Institute'} ) self.fields['department'].widget.attrs.update( - {'class': form_input_class} + {'class': form_input_class, 'placeholder': 'Department'} ) self.fields['roll_number'].widget.attrs.update( - {'class': form_input_class} + {'class': form_input_class, 'placeholder': 'Roll Number'} ) self.fields['position'].widget.attrs.update( - {'class': form_input_class} + {'class': form_input_class, 'placeholder': 'Position'} ) self.fields['timezone'] = forms.ChoiceField( choices=[(tz, tz) for tz in pytz.common_timezones], diff --git a/yaksh/static/yaksh/css/custom.css b/yaksh/static/yaksh/css/custom.css index 92a1fc7..d0d5c82 100644 --- a/yaksh/static/yaksh/css/custom.css +++ b/yaksh/static/yaksh/css/custom.css @@ -26,4 +26,4 @@ body, .dropdown-menu { #login-btn, #signup-btn, #forgot-btn{ width: 75%; -} \ No newline at end of file +} diff --git a/yaksh/static/yaksh/images/yaksh_circular_logo.png b/yaksh/static/yaksh/images/yaksh_circular_logo.png new file mode 100644 index 0000000..ab5daed Binary files /dev/null and b/yaksh/static/yaksh/images/yaksh_circular_logo.png differ diff --git a/yaksh/templates/registration/password_change_done.html b/yaksh/templates/registration/password_change_done.html index ccaf312..9dd04b5 100644 --- a/yaksh/templates/registration/password_change_done.html +++ b/yaksh/templates/registration/password_change_done.html @@ -1,4 +1,4 @@ -{% extends "manage.html" %} +{% extends "base.html" %} {% load static %} {% block title %} Change Password {% endblock %} diff --git a/yaksh/templates/registration/password_change_form.html b/yaksh/templates/registration/password_change_form.html index 4b2218f..b4880c6 100644 --- a/yaksh/templates/registration/password_change_form.html +++ b/yaksh/templates/registration/password_change_form.html @@ -1,4 +1,4 @@ -{% extends "manage.html" %} +{% extends "base.html" %} {% block pagetitle %} Change Password {% endblock %} diff --git a/yaksh/templates/yaksh/add_course.html b/yaksh/templates/yaksh/add_course.html index 64cc9ff..2f584c9 100644 --- a/yaksh/templates/yaksh/add_course.html +++ b/yaksh/templates/yaksh/add_course.html @@ -1,32 +1,81 @@ {% extends "manage.html" %} +{% load static %} -{% block subtitle %}Add Course{% endblock %} +{% block title %}Add Course{% endblock %} {% block css %} - + {% endblock %} {% block script %} - + {% endblock %} {% block content %} -
-
- {% csrf_token %} -
- - {{ form.as_table }} -
-
- -
+


+
+ +
+ + {% csrf_token %} +
+ + {{ form.as_table }} +
+
+ +
-
-
- +
+ + + Cancel + +
+
+
{% endblock %} diff --git a/yaksh/templates/yaksh/courses.html b/yaksh/templates/yaksh/courses.html index 4e7a153..4548d33 100644 --- a/yaksh/templates/yaksh/courses.html +++ b/yaksh/templates/yaksh/courses.html @@ -1,29 +1,7 @@ {% extends "manage.html" %} {% block title %} Courses {% endblock %} {% block pagetitle %} Courses {% endblock pagetitle %} -{% block script %} - -{% endblock %} + {% block css %} {% endblock %} {% block content %} -
- - -{% endblock %} -{% block footer %} - -
-
-
- {% if user %} - {% block info %} - {{user.get_full_name|title}} with Roll no. {{user.profile.roll_number}} is logged in as {{user.username}} - {% endblock %} - {% endif %} -
-
- | -
-
- Any Queries? Email : info@fossee.in -
-
-
- -{% endblock %} +{% endblock %} \ No newline at end of file diff --git a/yaksh/templates/yaksh/editprofile.html b/yaksh/templates/yaksh/editprofile.html index df6d328..2161716 100644 --- a/yaksh/templates/yaksh/editprofile.html +++ b/yaksh/templates/yaksh/editprofile.html @@ -5,7 +5,7 @@

My Profile


-
+ {% csrf_token %}
@@ -18,14 +18,18 @@ {% for field in form %} {% for error in field.errors %}
- + {{ error|escape }}
{% endfor %} {% endfor %} {% for error in form.non_field_errors %}
- + {{ error|escape }}
{% endfor %} @@ -38,7 +42,7 @@
   - Cancel + Cancel
diff --git a/yaksh/templates/yaksh/moderator_dashboard.html b/yaksh/templates/yaksh/moderator_dashboard.html index 33671aa..ff4bcf1 100644 --- a/yaksh/templates/yaksh/moderator_dashboard.html +++ b/yaksh/templates/yaksh/moderator_dashboard.html @@ -8,29 +8,29 @@
{% block pagetitle %}

My Dashboard

{% endblock %} -

List of quizzes! Click on the given links to have a look at answer papers for a quiz.

+

+ List of quizzes! Click on the given links to have a look at answer papers for a quiz +


-  Add Course +  Add Course - Create Demo Course + Create Demo Course -
-
- {% if msg %} -
-
- - {{ msg }} -
+
+ {% if msg %} +
+
+ + {{ msg }}
- {% endif %} -
+
+ {% endif %} {% with objects as courses %} {% if not courses %} @@ -38,15 +38,18 @@ No Courses found. Add a new course or Create demo course
{% else %} +
{% include "yaksh/paginator.html" %}
{% for course in courses %}
-
+
-

{{ course.name | truncatechars:40 }}

+

+ {{ course.name | truncatechars:40 }} +

{% if course.active %} @@ -75,19 +78,19 @@
{{ course.name }} - - - - - - - - {% get_course_details course as course_details %} - {% if course_details %} + {% get_course_details course as course_details %} + {% if course_details %} +
QuizTaken ByNo. of users PassedNo. of users Failed
+ + + + + + {% for quiz, users_no, passed, failed in course_details %} @@ -95,11 +98,14 @@ - {% endfor %} - {% else %} - No Quizzes - {% endif %} -
QuizTaken ByNo. of users PassedNo. of users Failed
- + {{ quiz.description }} {{passed}} {{failed}}
+ {% endfor %} + + {% else %} +

+
+ No Quizzes +
+ {% endif %}
diff --git a/yaksh/templates/yaksh/paginator.html b/yaksh/templates/yaksh/paginator.html index 3170081..5438b77 100644 --- a/yaksh/templates/yaksh/paginator.html +++ b/yaksh/templates/yaksh/paginator.html @@ -1,4 +1,4 @@ -
-
+
{% endblock content %} diff --git a/yaksh/templatetags/custom_filters.py b/yaksh/templatetags/custom_filters.py index 29f4b59..1cd3ca2 100644 --- a/yaksh/templatetags/custom_filters.py +++ b/yaksh/templatetags/custom_filters.py @@ -1,5 +1,6 @@ from django import template from django.template.defaultfilters import stringfilter +from django.forms.fields import CheckboxInput from ast import literal_eval import os try: @@ -87,3 +88,8 @@ def replace_spaces(name): @register.simple_tag def course_grade(course, user): return course.get_grade(user) + + +@register.filter(name='is_checkbox') +def is_checkbox(value): + return isinstance(value, CheckboxInput) diff --git a/yaksh/urls.py b/yaksh/urls.py index d453381..3397fb1 100644 --- a/yaksh/urls.py +++ b/yaksh/urls.py @@ -109,6 +109,8 @@ urlpatterns = [ url(r'^manage/duplicate_course/(?P\d+)/$', views.duplicate_course, name='duplicate_course'), url(r'manage/courses/$', views.courses, name='courses'), + url(r'manage/allotted/courses/$', views.allotted_courses, + name='allotted_courses'), url(r'manage/add_course/$', views.add_course, name='add_course'), url(r'manage/edit_course/(?P\d+)$', views.add_course, name='edit_course'), diff --git a/yaksh/views.py b/yaksh/views.py index 78b30bf..7e9b706 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -15,6 +15,7 @@ from django.core.exceptions import ( MultipleObjectsReturned, ObjectDoesNotExist ) from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger +from django.contrib import messages from taggit.models import Tag import json import six @@ -1040,11 +1041,40 @@ 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).order_by('-active', '-id') + creator=user, is_trial=False).order_by('-id') + paginator = Paginator(courses, 20) + page = request.GET.get('page') + try: + courses = paginator.page(page) + except PageNotAnInteger: + # If page is not an integer, deliver first page. + courses = paginator.page(1) + except EmptyPage: + # If page is out of range (e.g. 9999), deliver last page of results. + courses = paginator.page(paginator.num_pages) + context = {'objects': courses, 'created': True} + return my_render_to_response(request, 'yaksh/courses.html', context) + + +@login_required +@email_verified +def allotted_courses(request): + user = request.user + if not is_moderator(user): + raise Http404('You are not allowed to view this page') allotted_courses = Course.objects.filter( - teachers=user, is_trial=False).order_by('-active', '-id') - context = {'courses': courses, "allotted_courses": allotted_courses, - "type": "courses"} + teachers=user, is_trial=False).order_by('-id') + paginator = Paginator(allotted_courses, 20) + page = request.GET.get('page') + try: + allotted_courses = paginator.page(page) + except PageNotAnInteger: + # If page is not an integer, deliver first page. + allotted_courses = paginator.page(1) + except EmptyPage: + # If page is out of range (e.g. 9999), deliver last page of results. + allotted_courses = paginator.page(paginator.num_pages) + context = {'allotted': True, "objects": allotted_courses} return my_render_to_response(request, 'yaksh/courses.html', context) @@ -1166,9 +1196,12 @@ def toggle_course_status(request, course_id): if course.active: course.deactivate() + message = '{0} deactivated successfully'.format(course.name) else: course.activate() + message = '{0} activated successfully'.format(course.name) course.save() + messages.info(request, message) return my_redirect("/exam/manage/courses") -- cgit