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

Add My Projects page

parent 65e02d2c
No related branches found
No related tags found
No related merge requests found
function deleteProject(id) {
let form = document.getElementById('delete_project_form');
document.getElementById('delete_id').value = id;
form.submit()
}
function publishProject(id) {
updateStatus(id, 'Open')
}
function closeProject(id) {
updateStatus(id, 'Closed')
}
function updateStatus(id, status) {
let form = document.getElementById('update_status_form');
document.getElementById('status_id').value = id;
document.getElementById('status_action').value = status;
form.submit()
}
\ No newline at end of file
{% extends 'pasapp/templates/base_template.html' %}
{% block title %} My Projects {% endblock %}
{% block imports %}
{% load static %}
<script src={% static 'pasapp/js/projects_actions.js' %}></script>
{% endblock %}
{% block onload %} {% endblock %}
{% block content %}
<div class="floating-header" style="height: 3em;">
<div>
<a href="/project/create/" class="undecorated-link nav-item">Add new project</a>
</div>
</div>
<form action="/project/update_status/?next=/projects/mine/" method="post" id="update_status_form">
{% csrf_token %}
<input type="hidden" name="project" id="status_id">
<input type="hidden" name="action" id="status_action">
</form>
<form action="/project/delete/?next=/projects/mine/" method="post" id="delete_project_form">
{% csrf_token %}
<input type="hidden" name="project" id="delete_id">
</form>
{% load custom_filters %}
{% if drafts %}
<h2>Drafts</h2>
<ul class="project-list">
{% for project in drafts %}
<li class="dashed-box project-listing">
<a href="{% url 'edit_project' project.id %}" class="undecorated-link underline-hover" title="Edit draft"><b>{{ project.title }}</b></a>
<br/>
{{project.description}}
<br/>
<a href="{% url 'edit_project' project.id %}?next=/projects/mine/"><button>✏️ Edit</button></a>
<a href="{% url 'copy_project' project.id %}"><button>📄 Copy</button></a>
<button onclick="publishProject({{project.id}})">📢 Publish</button>
<button onclick="deleteProject({{project.id}})">❌ Delete</button>
</li>
{% endfor %}
</ul>
<hr>
{% endif %}
{% if applied %}
<h2>Projects with applications</h2>
<ul class="project-list">
{% for project in applied %}
<li class="dashed-box project-listing">
<a href="{% url 'project_details' project.id %}" class="undecorated-link underline-hover" title="View project details"><b>{{ project.title }}</b></a>
<br/>
{{project.description}}
<br/>
<b>Status:</b> {{project.status}}
<br/>
🛈 <b>{{ projectApplications|get:project.id }} students have applied so far.</b>
<br/>
<a href="{% url 'project_details' project.id %}"><button>🔍 View</button></a>
<a href="{% url 'edit_project' project.id %}?next=/projects/mine/"><button>✏️ Edit</button></a>
<button onclick="closeProject({{project.id}})">🔒 Close</button>
</li>
{% endfor %}
</ul>
{% endif %}
{% if open %}
<h2>Open projects</h2>
<ul class="project-list">
{% for project in open %}
<li class="dashed-box project-listing">
<a href="{% url 'project_details' project.id %}" class="undecorated-link underline-hover" title="View project details"><b>{{ project.title }}</b></a>
<br/>
{{project.description}}
<br/>
<b>Status:</b> {{project.status}}
<br/>
🛈 No applications.
<br/>
<a href="{% url 'edit_project' project.id %}?next=/projects/mine/"><button>✏️ Edit</button></a>
<button onclick="closeProject({{project.id}})">🔒 Close</button>
<button onclick="deleteProject({{project.id}})">❌ Delete</button>
</li>
{% endfor %}
</ul>
{% endif %}
{% if other %}
<hr>
<h2>Closed projects</h2>
<ul class="project-list">
{% for project in other %}
<li class="dashed-box project-listing">
<a href="{% url 'project_details' project.id %}" class="undecorated-link underline-hover" title="View project details"><b>{{ project.title }}</b></a>
<br/>
{{project.description}}
<br/>
<b>Status:</b> {{project.status}}
<br/>
<a href="{% url 'edit_project' project.id %}?next=/projects/mine/"><button>✏️ Edit</button></a>
<a href="{% url 'copy_project' project.id %}"><button>📄 Copy</button></a>
<button onclick="deleteProject({{project.id}})">❌ Delete</button>
</li>
{% endfor %}
</ul>
{% endif %}
{% endblock %}
\ No newline at end of file
...@@ -42,6 +42,10 @@ ...@@ -42,6 +42,10 @@
<div> <div>
<a href="/" class="undecorated-link nav-item">Projects</a> <a href="/" class="undecorated-link nav-item">Projects</a>
{% if user.username %} {% if user.username %}
{% load custom_filters %}
{% if user|is_professor %}
<a href="/projects/mine/" class="undecorated-link nav-item">My Projects</a>
{% endif %}
<a href="/applications/" class="undecorated-link nav-item">Applications</a> <a href="/applications/" class="undecorated-link nav-item">Applications</a>
<a href="/user/{{user.username}}" class="undecorated-link nav-item">Profile</a> <a href="/user/{{user.username}}" class="undecorated-link nav-item">Profile</a>
{% endif %} {% endif %}
......
...@@ -18,6 +18,7 @@ urlpatterns = [ ...@@ -18,6 +18,7 @@ urlpatterns = [
path('project/<int:project_id>/edit/', path('project/<int:project_id>/edit/',
views.edit_project, name='edit_project'), views.edit_project, name='edit_project'),
path('projects/filter/', views.index, name='filter_projects'), path('projects/filter/', views.index, name='filter_projects'),
path('projects/mine/', views.my_projects, name='my_projects'),
path('applications/', views.my_applications, name='my_applications'), path('applications/', views.my_applications, name='my_applications'),
path('applications/update_priorities/', path('applications/update_priorities/',
views.update_priorities, name='update_priorities'), views.update_priorities, name='update_priorities'),
......
...@@ -127,6 +127,29 @@ def professor_project_details(request, project_id): ...@@ -127,6 +127,29 @@ def professor_project_details(request, project_id):
context = {'project': project, 'applications': applications, 'comments': comments, 'projectTags': project_tags} context = {'project': project, 'applications': applications, 'comments': comments, 'projectTags': project_tags}
return render(request, 'pasapp/pages/professor_project_details.html', contextWithHeader(context, request)) return render(request, 'pasapp/pages/professor_project_details.html', contextWithHeader(context, request))
@login_required
@user_passes_test(is_professor)
def my_projects(request):
professor = request.user
all_projects = Project.objects.filter(professor=professor)
drafts = all_projects.filter(status='Draft')
all_projects = all_projects.exclude(status='Draft')
open_projects = get_open_projects(all_projects)
other = all_projects.exclude(id__in=[project.id for project in open_projects])
all_applications = Application.objects.filter(project__in=open_projects) # ignores applications for closed and draft projects
project_applications = {project.id: 0 for project in open_projects}
applied_project_ids = all_applications.values_list('project__id', flat=True)
for id in applied_project_ids:
project_applications[id] += 1
applied = open_projects.filter(pk__in=set(applied_project_ids)) # TODO: sort by recent application
open_projects = open_projects.exclude(pk__in=set(applied_project_ids))
context = {'drafts': drafts, 'applied': applied, 'open': open_projects, 'other': other, 'projectApplications': project_applications}
return render(request, 'pasapp/pages/my_projects.html', contextWithHeader(context, request))
@login_required @login_required
@user_passes_test(is_student) @user_passes_test(is_student)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment