Skip to content
Snippets Groups Projects
Commit 5e62b403 authored by Odin Johan Vatne's avatar Odin Johan Vatne
Browse files

Added tag & professor filtering

parent 6b285ecc
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,10 @@
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}
h5 {
margin-bottom: 0;
}
.floating-header {
width: 100%;
display: flex;
......@@ -55,14 +59,17 @@
border: 1px indianred dashed;
}
.application {
display: flex;
.dashed-box {
border-radius: 4px;
border: 1px black dashed;
margin-bottom: 8px;
padding: 4px;
}
.application {
display: flex;
}
.priorityContainer {
display: flex;
flex-direction: column;
......@@ -79,3 +86,17 @@
color: darkcyan;
display: inline;
}
#split-content-container {
display: flex;
}
#main-content {
flex: 4;
margin-right: 8px;
}
#sidebar {
flex: 1;
margin-left: 1px solid lightgray;
}
......@@ -8,8 +8,7 @@
{% if applications %}
<ul>
{% for application in applications %}
<li class="application">
<div>
<li class="dashed-box">
<b>{{application.student.username}}</b> on {{application.date_sent}}
<br>
{% if application.priority %}
......@@ -19,7 +18,6 @@
{% endif %}
</br>
{{application.message}}
</div>
</li>
{% endfor %}
</ul>
......
......@@ -6,18 +6,61 @@
{% if user|is_professor %}
<a href="/project/create/">Add new project</a>
{% endif %}
<div id="split-content-container">
<div id="main-content">
{% if projects %}
<ul>
{% for project in projects %}
<li>
<li class="dashed-box">
<a href="{% url 'project_detail' project.id %}">{{ project.title }}</a>
by {{project.professor}}
<br/>
<em>Description: </em>{{project.description}}
<br/>
<em>Status: </em>{{project.status}}
<br/>
<ul id="tagBox">
{% for tag in tags %}
{% if tag.project.id == project.id %}
<li class="tag">{{tag.tag.name}}</li>
{% endif %}
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
{% else %}
<p>No projects are available.</p>
{% endif %}
</div>
<div id="sidebar">
<h3>Filter projects</h3>
<form action="/projects/filter/" method="post">
{% csrf_token %}
<h5>Tags</h5>
{% for tag in tags %}
{% if tag.tag.id in selectedTags %}
<input type="checkbox" name="tag{{tag.tag.id}}" checked/>
{% else %}
<input type="checkbox" name="tag{{tag.tag.id}}"/>
{% endif %}
<label for="tag{{tag.tag.id}}">{{tag.tag.name}}</label>
<br/>
{% endfor %}
<h5>Professors</h5>
{% for professor in professors %}
{% if professor.id in selectedProfessors %}
<input type="checkbox" name="prof{{professor.id}}" checked/>
{% else %}
<input type="checkbox" name="prof{{professor.id}}"/>
{% endif %}
<label for="prof{{professor.id}}">{{professor.username}}</label>
<br/>
{% endfor %}
<input type="submit" value="Filter"/>
</form>
</div>
</div>
{% endblock %}
......@@ -36,7 +36,7 @@
</form>
<ol>
{% for application in applications %}
<li class="application">
<li class="dashed-box application">
{% if application.priority %}
<div class="priorityContainer">
<div>Priority:</div>
......
......@@ -15,6 +15,7 @@ urlpatterns = [
views.project_applications, name='project_applications'),
path('project/<int:project_id>/edit/',
views.edit_project, name='edit_project'),
path('projects/filter/', views.index, name='filter_projects'),
path('applications/', views.my_applications, name='my_applications'),
path('applications/update_priorities/',
views.update_priorities, name='update_priorities'),
......
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.decorators import login_required, user_passes_test
from django.contrib.auth.forms import AuthenticationForm
from django.contrib.auth.models import User
from django.http.response import Http404, HttpResponseBadRequest, HttpResponseForbidden, HttpResponseRedirect
from django.shortcuts import get_object_or_404, redirect, render
from django.http import HttpResponse
......@@ -13,8 +14,36 @@ from pasapp.utils import contextWithHeader, is_professor, is_student
# Create your views here.
def index(request):
tagIds, professorIds = [], []
if request.method == "POST":
post_request = request.POST
for key in post_request.keys():
if key.startswith("prof"):
professorIds.append(int(key.replace("prof", "", 1)))
elif key.startswith("tag"):
tagIds.append(int(key.replace("tag", "", 1)))
if tagIds:
projectTags = ProjectTag.objects.filter(tag_id__in=tagIds).all()
tagProjects = {relation.project for relation in projectTags}
else:
tagProjects = Project.objects.all()
if professorIds:
professorProjects = Project.objects.filter(
professor_id__in=professorIds).all()
else:
professorProjects = Project.objects.all()
projects = tagProjects.intersection(professorProjects)
else:
projects = Project.objects.order_by('-title')
context = {'projects': projects}
tags = ProjectTag.objects.all()
professors = {project.professor for project in Project.objects.all()}
print(professorIds)
context = {'projects': projects, 'tags': tags, 'professors': professors,
'selectedTags': tagIds, 'selectedProfessors': professorIds}
return render(request, 'pasapp/projects.html', contextWithHeader(context, request))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment