Skip to content

Commit

Permalink
Moderator interface: Course dashboard optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
CruiseDevice committed May 24, 2021
1 parent 8031599 commit f5fae46
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 143 deletions.
47 changes: 16 additions & 31 deletions yaksh/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,27 +564,7 @@ def get_total_students(self, course):
return AnswerPaper.objects.filter(
question_paper=qp,
course=course
).values_list("user", flat=True).distinct().count()

def get_passed_students(self, course):
try:
qp = self.questionpaper_set.get().id
except QuestionPaper.DoesNotExist:
qp = None
return AnswerPaper.objects.filter(
question_paper=qp,
course=course, passed=True
).values_list("user", flat=True).distinct().count()

def get_failed_students(self, course):
try:
qp = self.questionpaper_set.get().id
except QuestionPaper.DoesNotExist:
qp = None
return AnswerPaper.objects.filter(
question_paper=qp,
course=course, passed=False
).values_list("user", flat=True).distinct().count()
)

def get_answerpaper_status(self, user, course):
try:
Expand Down Expand Up @@ -737,8 +717,7 @@ class LearningModule(models.Model):
is_trial = models.BooleanField(default=False)

def get_quiz_units(self):
return [unit.quiz for unit in self.learning_unit.filter(
type="quiz")]
return self.learning_unit.filter(type="quiz")

def get_lesson_units(self):
return [unit.lesson for unit in self.learning_unit.filter(
Expand Down Expand Up @@ -1099,17 +1078,23 @@ def get_unit_completion_status(self, unit, user, course_status):
return unit.get_completion_status(user, self, course_status)

def get_quizzes(self):
learning_modules = self.learning_module.all()
quiz_list = []
learning_modules = self.get_learning_modules()
unit_list = []
for module in learning_modules:
quiz_list.extend(module.get_quiz_units())
return quiz_list
unit_list.extend(module.learning_unit.filter(type='quiz'))
return unit_list

def get_quiz_details(self):
return [(quiz, quiz.get_total_students(self),
quiz.get_passed_students(self),
quiz.get_failed_students(self))
for quiz in self.get_quizzes()]
unit_list = self.get_quizzes()

quiz_data = []
for unit in unit_list:
total_students = unit.quiz.get_total_students(self)
t_students = total_students.distinct().count()
p_students = total_students.filter(passed=True).distinct().count()
f_students = total_students.filter(passed=False).distinct().count()
quiz_data.append((unit, t_students, p_students, f_students))
return quiz_data

def get_learning_units(self):
learning_modules = self.get_learning_modules()
Expand Down
216 changes: 106 additions & 110 deletions yaksh/templates/yaksh/moderator_dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,117 +5,113 @@
{% block pagetitle %} <h2>My Dashboard</h2> {% endblock %}

{% block content %}
<div class="container">
<center>
<h4>
List of quizzes! Click on the given links to have a look at answer papers for a quiz
</h4>
</center>
<hr>
<center>
<a href="{% url 'yaksh:add_course' %}" class="btn btn-success btn-lg">
<span class=" fa fa-plus-circle"></span>&nbsp;Add Course
</a>
<a href="{% url 'yaksh:create_demo_course' %}" class="btn btn-primary btn-lg">
Create Demo Course
</a>
<br><br>
{% if messages %}
{% for message in messages %}
<div class="alert alert-dismissible alert-{{ message.tags }}">
<button type="button" class="close" data-dismiss="alert">
<i class="fa fa-close"></i>
</button>
<strong>{{ message }}</strong>
</div>
{% endfor %}
{% endif %}
</center>
{% with objects as courses %}
<br>
{% if not courses %}
<div class="alert alert-info">
No Courses found. Add a new course or Create demo course
</div>
{% else %}
{% include "yaksh/paginator.html" %}
<br>
<div id="accordion">
{% for course in courses %}
<div class="card">
<div class="card-header">
<div class="row">
<div class="col-md-4">
<h4 data-toggle="tooltip" title="{{course.name}}">
{{ course.name | truncatechars:40 }}
</h4>
</div>
<div class="col-md-2">
{% if course.active %}
<span class="badge badge-pill badge-success">
Active
</span>
{% else %}
<span class="badge badge-pill badge-danger">
Inactive
</span>
{% endif %}
</div>
<div class="col-md-3">
<a href="{% url 'yaksh:course_detail' course.id %}" class="btn btn-primary">
<i class="fa fa-tasks"></i>
Manage Course
</a>
</div>
<div class="col-md">
<a class="card-link btn btn-outline-info" data-toggle="collapse" href="#collapse{{course.id}}">
Details
<i class="fa fa-toggle-down" id="toggle_course_{{course.id}}"></i>
</a>
<div class="container">
<center>
<h4>
List of quizzes! Click on the given links to have a look at answer papers for a quiz
</h4>
</center>
<hr>
<center>
<a href="{% url 'yaksh:add_course' %}" class="btn btn-success btn-lg">
<span class=" fa fa-plus-circle"></span>&nbsp;Add Course
</a>
<a href="{% url 'yaksh:create_demo_course' %}" class="btn btn-primary btn-lg">
Create Demo Course
</a>
<br><br>
{% if messages %}
{% for message in messages %}
<div class="alert alert-dismissible alert-{{ message.tags }}">
<button type="button" class="close" data-dismiss="alert">
<i class="fa fa-close"></i>
</button>
<strong>{{ message }}</strong>
</div>
{% endfor %}
{% endif %}
</center>
{% with objects as courses %}
<br/>
{% if not courses %}
<div class="alert alert-info">
No Courses found. Add a new course or Create a Demo Course
</div>
{% else %}
{% include 'yaksh/paginator.html' %}
<br/>
<div id="accordian">
{% for course in courses %}
<div class="card">
<div class="card-header">
<div class="row">
<div class="col-md-4">
<h4 data-toggle="tooltip" title="{{course.name}}">
{{ course.name | truncatechars:40 }}
</h4>
</div>
<div class="col-md-2">
{% if course.active %}
<span class="badge badge-pill badge-success">
Active
</span>
{% else %}
<span class="badge badge-pill badge-danger">
Inactive
</span>
{% endif %}
</div>
<div class="col-md-3">
<a href="{% url 'yaksh:course_detail' course.id %}" class="btn btn-primary">
<i class="fa fa-tasks"></i>
Manage Course
</a>
</div>
<div class="col-md">
<a class="card-link btn btn-outline-info" data-toggle="collapse" href="#collapse{{course.id}}">
Details
<i class="fa fa-toggle-down" id="toggle_course_{{course.id}}"></i>
</a>
</div>
</div>
</div>
</div>
</div>
<div id="collapse{{course.id}}" class="collapse hide" data-parent="#accordion">
<div class="card-body">
<strong>{{ course.name }}</strong>
{% get_course_details course as course_details %}
{% if course_details %}
<table class="table table-responsive-sm">
<tr>
<th>Quiz</th>
<th>Taken By</th>
<th>No. of users Passed</th>
<th>No. of users Failed</th>
</tr>
{% for quiz, users_no, passed, failed in course_details %}
<tr>
<td>
<a href="{% url 'yaksh:monitor' quiz.id course.id %}">
{{ quiz.description }}
</a>
</td>
<td>{{users_no}} user(s)</td>
<td>{{passed}}</td>
<td>{{failed}}</td>
</tr>
{% endfor %}
</table>
{% else %}
<br><br>
<div class="alert alert-info">
<strong>No Quizzes</strong>
<div id="collapse{{course.id}}" class="collapse hide" data-parent="#accordian">
<div class="card-body">
<strong>{{course.name}}</strong>
{% get_course_details course as course_details %}
{% if course_details %}
<table class="table table-responsive-sm">
<tr>
<th>Quiz</th>
<th>Taken By</th>
<th>No. of users Passed</th>
<th>No. of users Failed</th>
</tr>
{% for unit, total, passed, failed in course_details %}
<tr>
<td>
<a href="{% url 'yaksh:monitor' unit.quiz.id course.id %}">
{{ unit.quiz.description }}
</a>
</td>
<td>{{total}} user(s)</td>
<td>{{passed}}</td>
<td>{{failed}}</td>
</tr>
{% endfor %}
</table>
{% else %}
<br><br>
<div class="alert alert-info">
<strong>No Quizzes</strong>
</div>
{% endif %}
</div>
{% endif %}
</div>
</div>
</div>
{% endfor %}
</div>
<br>
{% endfor %}
</div>
{% include "yaksh/paginator.html" %}
<br>
{% endif %}
{% endwith %}
</div>
{% endblock %}

{% endif %}s
{% endwith %}
</div>
{% endblock content %}
4 changes: 2 additions & 2 deletions yaksh/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,11 +452,11 @@ def prof_manage(request, msg=None):
return my_redirect('/exam/login')
if not is_moderator(user):
return my_redirect('/exam/')
courses = Course.objects.get_queryset().filter(
courses = Course.objects.filter(
Q(creator=user) | Q(teachers=user),
is_trial=False).distinct().order_by("-active")

paginator = Paginator(courses, 20)
paginator = Paginator(courses, 15)
page = request.GET.get('page')
courses = paginator.get_page(page)
messages.info(request, msg)
Expand Down

0 comments on commit f5fae46

Please sign in to comment.