Skip to content

Commit

Permalink
Implement student filtering by submission count
Browse files Browse the repository at this point in the history
  • Loading branch information
krishnans2006 committed Jan 10, 2025
1 parent c594194 commit eee3a37
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
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
32 changes: 23 additions & 9 deletions tin/templates/assignments/show.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,25 +91,39 @@ <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 %}
Expand Down

0 comments on commit eee3a37

Please sign in to comment.