Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement student filtering by submission count #95

Merged
merged 2 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions tin/apps/assignments/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ def show_view(request, assignment_id):

query = request.GET.get("query", "")

filter = request.GET.get("filter", "")

period = request.GET.get("period", "")
period_set = course.period_set.order_by("teacher", "name")

Expand All @@ -90,6 +92,22 @@ def show_view(request, assignment_id):
student_list = course.students.filter(full_name__icontains=query).order_by(
"last_name", "first_name"
)
elif filter:
active_period = "filter"
if filter == "no_submissions":
student_list = (
course.students.exclude(submissions__assignment=assignment)
.order_by("last_name", "first_name")
.distinct()
)
elif filter == "with_submissions":
student_list = (
course.students.filter(submissions__assignment=assignment)
.order_by("last_name", "first_name")
.distinct()
)
else:
student_list = course.students.all().order_by("last_name", "first_name")
elif course.period_set.exists():
if period == "":
if request.user in course.teacher.all():
Expand Down Expand Up @@ -164,6 +182,7 @@ def show_view(request, assignment_id):
"is_student": course.is_student_in_course(request.user),
"is_teacher": request.user in course.teacher.all(),
"query": query,
"filter": filter,
"period_set": period_set,
"active_period": active_period,
"quiz_accessible": quiz_accessible,
Expand Down
44 changes: 29 additions & 15 deletions tin/templates/assignments/show.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,31 +91,45 @@ <h2 class="left">{% if assignment.is_quiz %}[QUIZ] {% endif %}{{ assignment.name

{% if is_teacher or request.user.is_superuser %}
<h2 style="border-top:1px solid lightgray;padding-top:15px;">Filter Submissions</h2>
<a class="right tin-btn" {% if active_period == "none" %}style="color:#4fab4f !important"{% endif %}
<a class="right tin-btn" {% if active_period == "none" %}style="color:#4fab4f;"{% endif %}
href="{% url 'assignments:show' assignment.id %}?period=none">None</a>
<a class="right tin-btn" {% if active_period == "all" %}style="color:#4fab4f !important"{% endif %}
<a class="right tin-btn" {% if active_period == "all" %}style="color:#4fab4f;"{% endif %}
href="{% url 'assignments:show' assignment.id %}?period=all">All</a>
&ensp;
{% for period in period_set %}
<a class="right tin-btn" {% if active_period.id == period.id %}style="color:#4fab4f;"{% endif %}
href="{% url 'assignments:show' assignment.id %}?period={{ period.id }}">{{ period }}</a>
{% endfor %}
<br><br>
<form method="GET" action="{% url 'assignments:show' assignment.id %}" style="display: inline-block;">
<label>
<b>Matches:</b>
<input type="text" name="query" value="{{ query }}" placeholder="part of a name">
</label>
<button type="submit" class="tin-btn" style="cursor: pointer;{% if active_period == "query" %}color:#4fab4f !important;{% endif %}">
<i class="fa fa-search"></i>
<button type="submit" class="tin-btn" style="cursor: pointer;{% if active_period == "query" %}color:#4fab4f;{% endif %}">
<i class="fa fa-search fa-fw fa-fh"></i>
</button>
</form>
&emsp;
<form method="GET" action="{% url 'assignments:show' assignment.id %}" style="display: inline-block;">
<label>
<b>Filter:</b>
<select name="filter">
<option value="" {% if not filter %}selected{% endif %}>Select a filter</option>
<option value="no_submissions" {% if filter == "no_submissions" %}selected{% endif %}>Students with no submissions</option>
<option value="with_submissions" {% if filter == "with_submissions" %}selected{% endif %}>Students with at least one submission</option>
</select>
</label>
<button type="submit" class="tin-btn" style="cursor: pointer;{% if active_period == "filter" %}color:#4fab4f;{% endif %}">
<i class="fa fa-check fa-fw fa-fh"></i>
</button>
</form>
<br><br>
{% for period in period_set %}
<a class="right tin-btn" {% if active_period.id == period.id %}style="color:#4fab4f !important"{% endif %}
href="{% url 'assignments:show' assignment.id %}?period={{ period.id }}">{{ period }}</a>
{% endfor %}
<br><br>
{% if active_period != "none" %}
{% if assignment.is_quiz %}
<table id="submission-list" class="has-border">
<tr>
<th style="min-width:20px"></th>
<th style="min-width:20px; text-align: center;">#</th>
<th style="min-width:125px">Student</th>
{% if not active_period.name %}
<th style="min-width:65px;">Period</th>
Expand All @@ -128,7 +142,7 @@ <h2 style="border-top:1px solid lightgray;padding-top:15px;">Filter Submissions<
</tr>
{% for student, period, latest_submission, graded_submission, ended, quiz_issues in students_and_submissions %}
<tr>
<td style="text-align: center">{{ forloop.counter }}</td>
<td style="text-align: center;">{{ forloop.counter }}</td>
<td><a href="{% url 'assignments:student_submission' assignment.id student.id %}">{{ student.full_name }}
({{ student.username }})</a></td>
{% if not active_period.name %}
Expand All @@ -150,14 +164,14 @@ <h2 style="border-top:1px solid lightgray;padding-top:15px;">Filter Submissions<

{% if not students_and_submissions %}
<tr>
<td colspan="{% if not active_period.name %}7{% else %}6{% endif %}" class="italic center">No students in class</td>
<td colspan="{% if not active_period.name %}8{% else %}7{% endif %}" class="italic center">No matching students in class</td>
</tr>
{% endif %}
</table>
{% else %}
<table id="submission-list" class="has-border">
<tr>
<th style="min-width:20px"></th>
<th style="min-width:20px; text-align:center;">#</th>
<th style="min-width:125px">Student</th>
{% if not active_period.name %}
<th style="min-width:65px;">Period</th>
Expand All @@ -171,7 +185,7 @@ <h2 style="border-top:1px solid lightgray;padding-top:15px;">Filter Submissions<
</tr>
{% for student, period, latest_submission, graded_submission, new_login, new_24 in students_and_submissions %}
<tr>
<td style="text-align:center">{{ forloop.counter }}</td>
<td style="text-align:center;">{{ forloop.counter }}</td>
<td><a href="{% url 'assignments:student_submission' assignment.id student.id %}">{{ student.full_name }}
({{ student.username }})</a></td>
{% if not active_period.name %}
Expand Down Expand Up @@ -199,7 +213,7 @@ <h2 style="border-top:1px solid lightgray;padding-top:15px;">Filter Submissions<

{% if not students_and_submissions %}
<tr>
<td colspan="{% if not active_period.name %}8{% else %}7{% endif %}" class="italic center">No students in class</td>
<td colspan="{% if not active_period.name %}9{% else %}8{% endif %}" class="italic center">No matching students in class</td>
</tr>
{% endif %}
</table>
Expand Down
Loading