Skip to content

Commit

Permalink
Add search functionality in assignment view
Browse files Browse the repository at this point in the history
This reduces database queries when teachers are specifically looking for one student (a surprisingly common occurrence)
  • Loading branch information
krishnans2006 committed May 22, 2024
1 parent 809795d commit b302037
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
10 changes: 9 additions & 1 deletion tin/apps/assignments/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,17 @@ def show_view(request, assignment_id):
teacher_last_login = request.user.last_login
time_24_hours_ago = now() - datetime.timedelta(days=1)

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

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

if course.period_set.exists():
if query:
active_period = "query"
student_list = course.students.filter(full_name__icontains=query).order_by(
"periods", "last_name"
)
elif course.period_set.exists():
if period == "":
if request.user in course.teacher.all():
try:
Expand Down Expand Up @@ -157,6 +164,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,
"period_set": period_set,
"active_period": active_period,
"quiz_accessible": quiz_accessible,
Expand Down
2 changes: 1 addition & 1 deletion tin/static/css/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ a:hover {
text-align: center;
}

a.tin-btn {
.tin-btn {
border: 1px solid #cfcfcf;

border-radius: 4px;
Expand Down
10 changes: 10 additions & 0 deletions tin/templates/assignments/show.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ <h2 style="border-top:1px solid lightgray;padding-top:15px;">Filter Submissions<
href="{% url 'assignments:show' assignment.id %}?period=none">None</a>
<a class="right tin-btn" {% if active_period == "all" %}style="color:#4fab4f !important"{% endif %}
href="{% url 'assignments:show' assignment.id %}?period=all">All</a>
&ensp;
<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>
</form>
<br><br>
{% for period in period_set %}
<a class="right tin-btn" {% if active_period.id == period.id %}style="color:#4fab4f !important"{% endif %}
Expand Down

0 comments on commit b302037

Please sign in to comment.