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

finish hooking up group applications

parent 4f56ace3
No related branches found
No related tags found
No related merge requests found
......@@ -46,6 +46,7 @@ body {
border-left: 1px solid lightgray;
padding-left: 0.5em;
max-width: fit-content;
min-width: 21em;
}
textarea {
......
......@@ -29,6 +29,10 @@ function retractApplication(id) {
submitAction(id, 'RETR');
}
function leaveGroup(id) {
submitAction(id, 'LEAVE');
}
function submitAction(id, action) {
let form = document.getElementById("status_edit_form");
let idField = document.getElementById("status_id");
......
......@@ -24,6 +24,7 @@ function addUser() {
userBox.innerHTML += `<div class="user-bubble" onclick="removeUser(this,'${username}')">${data.name}</div>`;
userSet.add(username);
errorBox.classList.add('hidden');
updateForm();
}
})
.catch(e => {
......@@ -40,5 +41,7 @@ function removeUser(item, username) {
function updateForm() {
const userForm = document.getElementById("id_additional_students");
console.log(userForm);
console.log("hi :)");
userForm.value = [...userSet].join(' ');
}
\ No newline at end of file
......@@ -16,7 +16,17 @@
<a href="/user/{{application.student.username}}" class="undecorated-link underline-hover">
<b>{{application.student.first_name}} {{application.student.last_name}}</b>
</a>
on {{application.date_created|date:"DATE_FORMAT"}} <br>
on {{application.date_created|date:"DATE_FORMAT"}}
{% if application.group_members.all|length > 0 %}
(with
{% for groupmate in application.group_members.all %}
<a href="/user/{{groupmate.username}}" class="undecorated-link underline-hover">
{{groupmate.first_name}} {{groupmate.last_name}},
</a>
{% endfor %}
)
{% endif %}
<br>
<hr>
{% comment %}<em>Description: </em>{{application.project.description}}<br/>{% endcomment %}
{{application.message}}
......
......@@ -21,7 +21,29 @@
{{application.project.professor.first_name}} {{application.project.professor.last_name}}
</a>
<br>
Applied on {{application.date_created|date:"DATE_FORMAT"}} <br>
{% if application.student.username != user.username %}
<a href="/user/{{application.student.username}}" class="undecorated-link underline-hover">
{{application.student.first_name}} {{application.student.last_name}}
</a>
applied
{%else%}
You applied
{% endif %}
on {{application.date_created|date:"DATE_FORMAT"}}
{% if application.group_members.all|length > 0 %}
(with
{% for groupmate in application.group_members.all %}
<a href="/user/{{groupmate.username}}" class="undecorated-link underline-hover">
{{groupmate.first_name}} {{groupmate.last_name}},
</a>
{% endfor %}
)
{% endif %}
{% if application.student.username != user.username %}
<br>
<button type="button" onclick="leaveGroup({{application.id}})">Leave group</button>
{% endif %}
<br>
{% if professorStatus != 'NONE' %}
{{application.project.professor.first_name}} {{application.project.professor.last_name}}
{% if professorStatus == 'OFFR' %}
......@@ -43,6 +65,7 @@
{% if studentStatus == 'RETR' %}
You retracted this application.<br>
{% endif %}
{% if application.student.username == user.username %}
{% if checkbox %}
Automatically accept offer:
<input type="checkbox" class="low-checkbox"
......@@ -55,6 +78,7 @@
{% if professorStatus != 'OFFR' and not application|is_closed %}
<button type='button' onclick='retractApplication({{application.id}})'>Retract Application</button><br>
{% endif %}
{% endif %}
<hr>
{% comment %}<em>Description: </em>{{application.project.description}}<br/>{% endcomment %}
{{application.message}}
......
......@@ -44,19 +44,19 @@
{% if offeredApplications %}
<h2>Extended Offers</h2>
{% for application in offeredApplications %}
{% application_student application comments|for_application:application True %}
{% application_student application user comments|for_application:application True %}
{% endfor %}
{% endif %}
{% if openApplications %}
<h2>Pending Applications</h2>
{% for application in openApplications %}
{% application_student application comments|for_application:application True %}
{% application_student application user comments|for_application:application True %}
{% endfor %}
{% endif %}
{% if closedApplications %}
<h2>Closed Applications</h2>
{% for application in closedApplications %}
{% application_student application comments|for_application:application False %}
{% application_student application user comments|for_application:application False %}
{% endfor %}
{% endif %}
</ol>
......
......@@ -38,6 +38,6 @@
{% endif %}
{% if student_application %}
<h2>Your application:</h2>
{% application_student student_application comments|for_application:student_application True %}
{% application_student student_application user comments|for_application:student_application True %}
{% endif %}
{% endblock %}
......@@ -45,7 +45,7 @@ def tags_dropdown(tags):
return { 'tagsByCategory': tags_by_category }
@register.inclusion_tag('pasapp/components/application_student.html')
def application_student(application, comments=[], interactive=False, comment_box=False):
def application_student(application, user, comments=[], interactive=False, comment_box=False):
if interactive:
checkbox = application.student_status in ('APPL', 'PRE') and application.professor_status in ('NONE')
responses = application.professor_status in ('OFFR') and application.student_status in ('APPL', 'PRE') # 'PRE' not necessary after automation
......@@ -53,7 +53,7 @@ def application_student(application, comments=[], interactive=False, comment_box
checkbox = responses = False
student_status = application.student_status
professor_status = application.professor_status
return { 'application': application,
return { 'application': application, 'user': user,
'studentStatus': student_status, 'professorStatus': professor_status,
'checkbox': checkbox, 'responses': responses,
'comments': comments, 'commentBox': comment_box }
......
......@@ -21,12 +21,20 @@ def get_next(request, fallback='/'):
return fallback
return next
def student_accepted(student):
def student_accepted(application):
student = application.student
student_accepted_recur(student, application, True)
def student_accepted_recur(student, application, allowRecursion = False):
other_applications = Application.objects.filter(student=student).exclude(student_status='ACC')
for app in other_applications:
app.student_status = 'RETR' if app.professor_status != 'OFFR' else 'DECL'
app.priority = None
app.save()
if allowRecursion:
group_students = application.group_members.all()
for groupmate in group_students:
student_accepted_recur(groupmate, application)
def project_closed(project):
open_applications = Application.objects.filter(project=project).exclude(student_status='ACC')
......
......@@ -182,6 +182,14 @@ def apply(request, project_id):
application = Application(
project=project, student=student, message=message, student_status=student_status)
application.save()
User = get_user_model()
group_users = form.cleaned_data.get('additional_students').split(' ')
for student in group_users:
if student == '':
continue
student_object = User.objects.get(username=student)
application.group_members.add(student_object)
return redirect(f"/project/{project_id}/")
form = ApplicationForm()
context = {'project': project, 'form': form}
......@@ -390,7 +398,9 @@ def student_applications_view(request):
'''
Displays all of the student's project applications and allows them to set rankings (see update_priorities below)
'''
applications = Application.objects.filter(student=request.user)
my_applications = Application.objects.filter(student=request.user)
group_applications = request.user.member_projects.all()
applications = (my_applications | group_applications).distinct()
closed_applications = applications.filter(app_closed_query)
applications = applications.exclude(app_closed_query)
......@@ -470,6 +480,10 @@ def update_student_status(request):
state = post_request['state']
application = Application.objects.get(pk=application_id)
if state == 'LEAVE':
application.group_members.remove(request.user)
return redirect(get_next(request,'/applications/'))
if request.user != application.student:
return HttpResponseBadRequest("This application is not yours.")
......@@ -492,7 +506,7 @@ def update_student_status(request):
application.save()
if state == 'ACC':
student_accepted(request.user)
student_accepted(application)
if state == 'RETR' or state == 'DECL':
application_declined(application)
return redirect(get_next(request,'/applications/'))
......@@ -531,7 +545,7 @@ def update_professor_status(request):
application.save()
if application.student_status == 'ACC':
student_accepted(application.student)
student_accepted(application)
elif action == 'decline':
application_declined(application)
return redirect(get_next(request,'/applications/'))
......@@ -539,6 +553,16 @@ def update_professor_status(request):
else:
return HttpResponseBadRequest("This endpoint only supports POST requests.")
def remove_from_group(request):
if request.method == 'POST':
post_request = request.POST
application_id = post_request['application']
action = post_request['action']
else:
return HttpResponseBadRequest("This endpoint only supports POST requests.")
return redirect(get_next(request,'/applications/'))
@login_required
def add_comment(request):
'''
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment