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

Added application page

parent 82c0cdd3
No related branches found
No related tags found
No related merge requests found
......@@ -28,3 +28,7 @@ class NewUserForm(UserCreationForm):
class NewProjectForm(forms.Form):
title = forms.CharField(label="Title", max_length=200)
description = forms.CharField(label="Description", max_length=2048)
class ApplicationForm(forms.Form):
message = forms.CharField(label="Message", max_length=2000)
......@@ -16,3 +16,19 @@
display: inline;
margin: 0;
}
.nav-item {
display: inline;
margin: 0;
border-bottom: none;
color: #222;
font-size: larger;
}
.nav-item:hover {
border-bottom: 2px solid darkturquoise;
}
.undecorated-link {
text-decoration: none;
}
......@@ -13,6 +13,9 @@
<body>
<div class="floating-header">
<h1 id="logo">PAS</h1>
<div>
<a href="/" class="undecorated-link nav-item">Projects</a>
</div>
{% if user.username %}
<div>
Logged in as {{user.username}}
......@@ -20,10 +23,11 @@
</div>
{% else %}
<div>
<form action="/login/" method="post">
<form action="/login/" method="post" style="display: inline">
{% csrf_token %} {{ loginForm }}
<input type="submit" value="Log In" />
</form>
| or <a href="register">register new user</a>
</div>
{% endif %}
</div>
......
{% extends 'pasapp/base_template.html' %}
{% block title %} Applying for {{project.title}} {% endblock %}
{% block content %}
<h1>Apply for {{project.title}}</h1>
<form action="/project/{{project.id}}/apply/" method="post">
{% csrf_token %} {{ form }}
<input type="submit" value="Apply" />
</form>
{% endblock %}
......@@ -5,14 +5,14 @@
<h1>{{project.title}}</h1>
<h3>{{project.professor}}</h3>
{% if project.professor.id == user.id %}
<a href="/project/{{project.id}}/edit">Edit this project</a>
<a href="/project/{{project.id}}/edit/">Edit this project</a>
{% endif %}
<p>{{project.description}}</p>
<em>Status: </em>{{project.status}}
<br />
<form action="/apply/{{project.id}}/" method="post">
{% csrf_token %} {{ form }}
<input type="submit" value="Apply" />
</form>
{% load custom_filters %}
{% if user|is_student %}
<a href="/project/{{project.id}}/apply/">Apply to this project</a>
{% endif %}
<p>(i) {{numApplicants}} students have applied so far.</p>
{% endblock %}
from django import template
register = template.Library()
@register.filter(name='is_professor')
def is_professor(user):
return user.groups.filter(name='professor').exists()
@register.filter(name='is_student')
def is_student(user):
return user.groups.filter(name='student').exists()
......@@ -9,8 +9,8 @@ urlpatterns = [
path('register/', views.register, name='register'),
path('project/<int:project_id>/',
views.project_details, name='project_detail'),
path('apply/<int:project_id>/', views.apply, name='apply'),
path('project/<int:project_id>/applications',
path('project/<int:project_id>/apply/', views.apply, name='apply'),
path('project/<int:project_id>/applications/',
views.project_applications, name='project_applications'),
path('project/create/', views.create_project, name='create_project'),
path('project/<int:project_id>/edit/',
......
......@@ -4,10 +4,10 @@ from django.contrib.auth.forms import AuthenticationForm
from django.http.response import Http404, HttpResponseForbidden, HttpResponseRedirect
from django.shortcuts import get_object_or_404, redirect, render
from django.http import HttpResponse
from pasapp.forms import NewProjectForm, NewUserForm
from pasapp.forms import ApplicationForm, NewProjectForm, NewUserForm
from pasapp.models import Application, Project
from pasapp.utils import contextWithHeader, is_professor
from pasapp.utils import contextWithHeader, is_professor, is_student
# Create your views here.
......@@ -24,17 +24,22 @@ def project_details(request, project_id):
return render(request, 'pasapp/project_details.html', contextWithHeader(context, request))
@login_required
@user_passes_test(is_student)
def apply(request, project_id):
if request.method == 'GET':
raise Http404("This endpoint does not support GET requests.")
project = get_object_or_404(Project, pk=project_id)
if request.method == 'POST':
form = ApplicationForm(request.POST)
if form.is_valid():
student = request.user
if student is None:
return redirect("login")
message = form.cleaned_data.get('message')
application = Application(
project=project, student=student, message="test123")
project=project, student=student, message=message)
application.save()
return redirect("index")
return redirect(f"/project/{project_id}/")
form = ApplicationForm()
context = {'project': project, 'form': form}
return render(request, 'pasapp/create_application.html', contextWithHeader(context, request))
@login_required
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment