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

Filtering by professor on course review page #150

Merged
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
23 changes: 19 additions & 4 deletions home/templates/course_reviews.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ <h1 class="text-center">Reviews for <strong><a href="{{ course.get_absolute_url
<option value="asc">Rating</option>
</select>
</div>

<div class="input-group-prepend ml-3">
<label class="input-group-text" for="professor-filter" style="border-bottom-left-radius: 0;">Professor Filter:</label>
</div>

<div class="dropdown">
<select class="form-control text-white custom-select" name="professor-filter" id="professor-filter">
<option selected value="">All Professors</option>
{% for professor in professors %}
<option value={{professor.id}}>{{professor.name}}</option>
{% endfor%}
</select>
</div>
</div>
</div>
{% endif %}
Expand All @@ -49,10 +62,11 @@ <h1 class="text-center">Reviews for <strong><a href="{{ course.get_absolute_url
color_2: "secondary",
});

function sortReviews(direction) {
function sortReviews(direction, professor) {
var data = {
"csrfmiddlewaretoken": "{{ csrf_token }}",
"direction": direction,
"professor": professor,
"type": "course",
"obj_id": "{{ course.pk }}"
}
Expand All @@ -67,9 +81,10 @@ <h1 class="text-center">Reviews for <strong><a href="{{ course.get_absolute_url
});
}

$("#rating-select").on("change", function() {
var selectedRating = $(this).val();
sortReviews(selectedRating);
$("#rating-select, #professor-filter").on("change", function() {
var selectedRating = $("#rating-select").val();
var professorId = $("#professor-filter").val();
sortReviews(selectedRating, professorId);
});
</script>
{% endblock %}
9 changes: 7 additions & 2 deletions home/views/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ def get(self, request, name):
raise Http404()

reviews = course.review_set(manager="verified").order_by("-created_at")

professors = { review.professor for review in reviews }

context = {
"course": course,
"professors": professors,
"num_reviews": reviews.count(),
"reviews_table": VerifiedReviewsTable(reviews, request)
}
Expand Down Expand Up @@ -116,7 +118,10 @@ def post(self, request):
if data_type == "professor":
reviews = Review.verified.filter(professor__id=obj_id)
elif data_type == "course":
reviews = Review.verified.filter(course__id=obj_id)
if(data["professor"]==""):
reviews = Review.verified.filter(course__id=obj_id)
else:
reviews = Review.verified.filter(course__id=obj_id).filter(professor__id=int(data["professor"]))
else:
raise ValueError(f"Unknown type: {data_type}")

Expand Down
8 changes: 8 additions & 0 deletions planetterp/static/css/stylesheet.css
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,14 @@ body {
font-size: 18px;
}

#professor-filter {
background: #6c757d;
border-bottom-left-radius: 0;
border-top-left-radius: 0;
border-bottom-right-radius: 0;
border:1px solid #6c757d;
}

.card-header-gened {
text-align: center;
}
Expand Down