Skip to content

Commit

Permalink
Buttons on shift page work now
Browse files Browse the repository at this point in the history
Refs #19, #23, #34, #45
  • Loading branch information
simonw committed Apr 2, 2022
1 parent b928927 commit d8fdc60
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 28 deletions.
2 changes: 1 addition & 1 deletion pillarpointstewards/config/urls.py
Expand Up @@ -32,7 +32,7 @@ def trigger_error(request):
path("auth0-callback/", auth0_login.callback),
path("healthcheck/", homepage.healthcheck),
path("shifts/<int:shift_id>/", shifts.shift),
path("cancel-shift//", shifts.cancel_shift),
path("cancel-shift/<int:shift_id>/", shifts.cancel_shift),
path("assign-shift/<int:shift_id>/", shifts.assign_shift),
path("shifts/", shifts.shifts),
path("shifts.ics", shifts.shifts_ics),
Expand Down
8 changes: 4 additions & 4 deletions pillarpointstewards/shifts/views.py
Expand Up @@ -19,6 +19,8 @@ def shift(request, shift_id):
"shift.html",
{
"shift": shift,
"user_is_on_shift": shift.stewards.filter(id=request.user.id).exists(),
"stewards": list(shift.stewards.all()),
"contact_details": Fragment.objects.get(slug="contact_details").fragment,
"forecast": Forecast.for_date(shift.shift_start.date()),
},
Expand Down Expand Up @@ -53,7 +55,7 @@ def cancel_shift(request, shift_id):
if shift.stewards.filter(id=request.user.id).exists():
shift.stewards.remove(request.user)
shift.shift_changes.create(user=request.user, change="cancelled")
return HttpResponse("Cancelled")
return HttpResponseRedirect(f"/shifts/{shift.pk}/")
else:
return HttpResponse("You were not on that shift")

Expand All @@ -64,9 +66,7 @@ def assign_shift(request, shift_id):
if not shift.stewards.filter(id=request.user.id).exists():
shift.stewards.add(request.user)
shift.shift_changes.create(user=request.user, change="assigned")
return HttpResponse(
render_calendar(request, shift.shift_start.year, shift.shift_start.month)
)
return HttpResponseRedirect(f"/shifts/{shift.pk}/")
else:
return HttpResponse("You were already on that shift")

Expand Down
60 changes: 37 additions & 23 deletions pillarpointstewards/templates/shift.html
@@ -1,12 +1,12 @@
{% extends "base.html" %}
{% load static %}

{% block title %}Shift: {{ shift }}{% endblock %}
{% block title %}Shift on {{ shift.shift_start|date:"jS F Y" }}{% endblock %}

{% block content %}
<section class="page-title">
<div class="title-wrapper stretch">
<h1 class="text"><span>Shift for the {{ shift.shift_start|date:"jS" }} {{ shift.shift_start|date:"F" }} {{ shift.shift_start|date:"y" }}</span></h1>
<h1 class="text"><span>Shift on {{ shift.shift_start|date:"jS F Y" }}</span></h1>
<div class="page-controls">
{% if request.user.is_authenticated %}
<a class="loginout" href="/logout/">
Expand All @@ -26,34 +26,48 @@ <h1 class="text"><span>Shift for the {{ shift.shift_start|date:"jS" }} {{ shift.
</section> <!-- end .page-title -->
<section class="content">
<div class="primary">
<h2 class="header1" title="{{ shift.shift_start.date }}">You are <!--not--> scheduled for the shift on {{ shift.shift_start|date:"jS" }} {{ shift.shift_start|date:"F" }} {{ shift.shift_start|date:"y" }}</h2>
<h2 class="header1" title="{{ shift.shift_start.date }}">You are {% if not user_is_on_shift %}not{% endif %} scheduled for this shift</h2>
<div class="intro">
<p><strong>Shift times:</strong> from {{ shift.shift_start|date:"g:iA"|lower }} to {{ shift.shift_end|date:"g:iA"|lower }}</p>
<p><strong>Lowest tide:</strong> -1ft at 8am</p>
<p><strong>Sunrise:</strong> 6am</p>
<p><strong>Sunset:</strong> 7pm</p>
<p><strong>Shift time:</strong> from {{ shift.shift_start|date:"g:iA"|lower }} to {{ shift.shift_end|date:"g:iA"|lower }}</p>
{% if shift.mllw_feet %}
<p><strong>Lowest tide:</strong> {{ shift.mllw_feet }}ft at {{ shift.lowest_tide|date:"g:iA"|lower }}</p>
{% endif %}
<p><strong>Dawn:</strong> {{ shift.dawn|date:"g:iA"|lower }}</p>
<p><strong>Dusk:</strong> {{ shift.dusk|date:"g:iA"|lower }}</p>
</div><br>

<h2>Volunteers on this shift <em>(0/3)</em></h2>

<!-- If there is no-one-->
<p>It looks like noone has signed up for this shift yet</p>
<!--endif -->
<h2>Volunteers on this shift <em>({{ stewards|length }}{% if shift.target_stewards %}/{{ shift.target_stewards }}{% endif %})</em></h2>

<!-- if there are volunteers assigned -->
{% if not stewards %}
<p>It looks like no-one has signed up for this shift yet</p>
{% else %}
<!-- if there are volunteers assigned -->
<ul class="people-list">
{% for steward in stewards %}
<li><div class="pic"></div><p class="name">{{ steward }}</p>
<p class="context">
{% if steward == request.user %}
You are signed up to this shift
{% else %}
Has volunteered on {{ steward.shifts.count }} shift{{ steward.shifts.count|pluralize }}</p>
{% endif %}
</p>
</li>
{% endfor %}
</ul>
{% endif %}

<ul class="people-list">
<li><a href="#"><div class="pic"></div><p class="name">Deedee McGubbins</p><p class="context">Has volunteered on 5 shifts so far</p></a></li>
<li><div class="pic"></div><p class="name">Amit Patel</p><p class="context">Has volunteered on 1 shift so far</p></li>
<li><div class="pic"></div><p class="name">Zahara Emmith Williams</p><p class="context">Has not volunteered on any shifts yet</p></li>
<li><div class="pic" style="background-image: url({% static "logo.png" %});"></div><p class="name">Your Name if assigned</p><p class="context">You are signed up to this shift</p></li>
</ul>

<!--endif -->

<form action="#" method="POST">
<button type="submit" class="button shift-assign"><!--Remove me from -->Add me to this shift</button>
</form>
{% if user_is_on_shift %}
<form action="/cancel-shift/{{ shift.pk }}/" method="POST">{% csrf_token %}
<button type="submit" class="button shift-assign">Remove me from this shift</button>
</form>
{% else %}
<form action="/assign-shift/{{ shift.pk }}/" method="POST">{% csrf_token %}
<button type="submit" class="button shift-assign">Add me to this shift</button>
</form>
{% endif %}

{% if forecast %}
<h2>Conditions</h2>
Expand Down

0 comments on commit d8fdc60

Please sign in to comment.