Skip to content

Commit

Permalink
Merge branch 'main' into schedule-aa
Browse files Browse the repository at this point in the history
  • Loading branch information
russss authored May 26, 2024
2 parents 0ea12c4 + 70aad02 commit 3039e4b
Show file tree
Hide file tree
Showing 23 changed files with 75 additions and 24 deletions.
2 changes: 1 addition & 1 deletion apps/volunteer/data/venues/arcade.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
mapref: https://map.emfcamp.org/#20.82/52.0397817/-2.3767928
mapref: https://map.emfcamp.org/#17.03/52.041068/-2.377307/m=52.042011,-2.377318
name: Arcade
2 changes: 1 addition & 1 deletion apps/volunteer/data/venues/badge_tent.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
mapref: https://map.emfcamp.org/#20.24/52.0405486/-2.3781891
mapref: https://map.emfcamp.org/#17.06/52.041602/-2.375338/m=52.042277,-2.375297
name: Badge Tent
2 changes: 1 addition & 1 deletion apps/volunteer/data/venues/bar.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
mapref: https://map.emfcamp.org/#19/52.0420157/-2.3770749
mapref: https://map.emfcamp.org/#16.62/52.04154/-2.3771/m=52.042322,-2.377277
name: Bar
2 changes: 1 addition & 1 deletion apps/volunteer/data/venues/car_park.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
mapref: https://map.emfcamp.org/#19.19/52.0389412/-2.3783488
mapref: https://map.emfcamp.org/#16/52.038135/-2.37846/m=52.038723,-2.37851
name: Car Park
2 changes: 1 addition & 1 deletion apps/volunteer/data/venues/cybar.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
mapref: https://map.emfcamp.org/#19/52.0409755/-2.3786306
mapref: https://map.emfcamp.org/#17.02/52.043133/-2.37699/m=52.0437884,-2.3770287
name: Cybar
2 changes: 1 addition & 1 deletion apps/volunteer/data/venues/entrance_tent.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
mapref: https://map.emfcamp.org/#18/52.039226/-2.378184
mapref: https://map.emfcamp.org/#16.65/52.039551/-2.378303/m=52.0392897,-2.3783524
name: Entrance Tent
2 changes: 1 addition & 1 deletion apps/volunteer/data/venues/green_room.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
mapref: https://map.emfcamp.org/#20.72/52.0414959/-2.378016
mapref: https://map.emfcamp.org/#16.76/52.040738/-2.377879/m=52.0406657,-2.3780121
name: Green Room
2 changes: 1 addition & 1 deletion apps/volunteer/data/venues/info_volunteer_tent.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
mapref: https://map.emfcamp.org/#20.82/52.0397817/-2.3767928
mapref: https://map.emfcamp.org/#16.61/52.04099/-2.376626/m=52.041813,-2.3769969
name: Info/Volunteer Tent
2 changes: 1 addition & 1 deletion apps/volunteer/data/venues/logistics_tent.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
mapref: https://map.emfcamp.org/#20.82/52.0397817/-2.3767928
mapref: https://map.emfcamp.org/#16.53/52.040206/-2.37686/m=52.0399083,-2.3767278
name: Logistics Tent
2 changes: 1 addition & 1 deletion apps/volunteer/data/venues/noc.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
mapref: https://map.emfcamp.org/#21.49/52.0415113/-2.3776567
mapref: https://map.emfcamp.org/#16.95/52.039438/-2.377115/m=52.0395588,-2.3771013
name: NOC
2 changes: 1 addition & 1 deletion apps/volunteer/data/venues/null_sector.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
mapref: https://map.emfcamp.org/#19/52.0409755/-2.3786306
mapref: https://map.emfcamp.org/#17.17/52.043132/-2.377102/m=52.0436251,-2.3770731
name: Null Sector
2 changes: 1 addition & 1 deletion apps/volunteer/data/venues/phone_tent.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
mapref: https://map.emfcamp.org/#20.42/52.0399054/-2.3768637
mapref: https://map.emfcamp.org/#16.81/52.039713/-2.376886/m=52.0399211,-2.3768469
name: Phone Team Tent
2 changes: 1 addition & 1 deletion apps/volunteer/data/venues/shop.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
mapref: https://map.emfcamp.org/#20.82/52.0397817/-2.3767928
mapref: https://map.emfcamp.org/#17.24/52.041165/-2.377744/m=52.0413849,-2.3778526
name: Shop
2 changes: 1 addition & 1 deletion apps/volunteer/data/venues/stage_a.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
mapref: https://map.emfcamp.org/#17/52.039601/-2.377759
mapref: https://map.emfcamp.org/#16.51/52.039593/-2.378368/m=52.0399551,-2.3783369
name: Stage A
2 changes: 1 addition & 1 deletion apps/volunteer/data/venues/stage_b.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
mapref: https://map.emfcamp.org/#17/52.041798/-2.376412
mapref: https://map.emfcamp.org/#16.72/52.041168/-2.376755/m=52.041798,-2.37667
name: Stage B
2 changes: 1 addition & 1 deletion apps/volunteer/data/venues/stage_c.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
mapref: https://map.emfcamp.org/#17/52.040482/-2.377432
mapref: https://map.emfcamp.org/#16.84/52.040478/-2.377832/m=52.040607,-2.377842
name: Stage C
2 changes: 1 addition & 1 deletion apps/volunteer/data/venues/vehicle_gate_y.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
mapref: https://map.emfcamp.org/#21.49/52.0415113/-2.3776567
mapref: https://map.emfcamp.org/#16.43/52.039329/-2.376927/m=52.0391181,-2.3770662
name: Vehicle Gate Y
2 changes: 1 addition & 1 deletion apps/volunteer/data/venues/voc.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
mapref: https://map.emfcamp.org/#20.72/52.0414959/-2.378016
mapref: https://map.emfcamp.org/#16.91/52.04049/-2.37799/m=52.040724,-2.377994
name: VOC
2 changes: 1 addition & 1 deletion apps/volunteer/data/venues/volunteer_kitchen.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
mapref: https://map.emfcamp.org/#20.82/52.0397817/-2.3767928
mapref: https://map.emfcamp.org/#17.05/52.041005/-2.376121/m=52.0417823,-2.3760325
name: Volunteer Kitchen
2 changes: 1 addition & 1 deletion apps/volunteer/data/venues/youth_workshop.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
mapref: https://map.emfcamp.org/#19.46/52.0420979/-2.3753702
mapref: https://map.emfcamp.org/#16.68/52.040881/-2.377577/m=52.041475,-2.377593
name: Youth Workshop
53 changes: 51 additions & 2 deletions apps/volunteer/schedule.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
# coding=utf-8
import pendulum
from icalendar import Calendar, Event
from datetime import datetime
from flask import render_template, request, redirect, url_for, flash, session
from flask import render_template, request, redirect, url_for, flash, abort, session, Response
from flask import current_app as app
from collections import defaultdict
from flask_login import current_user
from sqlalchemy.orm import joinedload

from main import db
from models.user import User
from models import event_year
from models.user import User, generate_api_token

from models.volunteer.role import Role
from models.volunteer.venue import VolunteerVenue
from models.volunteer.shift import Shift, ShiftEntry
from models.volunteer.volunteer import Volunteer
from models import config_date

from ..schedule import event_tz
from ..users import get_next_url
from ..common import feature_flag
from . import volunteer, v_user_required, v_admin_required
Expand Down Expand Up @@ -78,16 +83,60 @@ def schedule():
r for r in roles if r["is_interested"] and r["requires_training"] and not r["is_trained"]
]

token = generate_api_token(app.config["SECRET_KEY"], current_user.id)

return render_template(
"volunteer/schedule.html",
roles=roles,
venues=venues,
all_shifts=by_time,
active_day=active_day,
untrained_roles=untrained_roles,
token=token,
)


@volunteer.route("/schedule.ical")
@volunteer.route("/schedule.ics")
@feature_flag("VOLUNTEERS_SCHEDULE")
def schedule_ical():
code = request.args.get("token", None)
user = None
if code:
user = User.get_by_api_token(app.config.get("SECRET_KEY"), str(code))
if not current_user.is_anonymous:
user = current_user
if not user:
abort(404)

title = "EMF {} Volunteer Shifts for {}".format(event_year(), user.name)

cal = Calendar()
cal.add("summary", title)
cal.add("X-WR-CALNAME", title)
cal.add("X-WR-CALDESC", title)
cal.add("version", "2.0")

shifts = (Shift.query
.select_from(ShiftEntry)
.join(Shift.entries.and_(ShiftEntry.user == user))
.options(
joinedload(Shift.venue),
joinedload(Shift.role)
)).all()

for shift in shifts:
cal_event = Event()
cal_event.add("uid", "%s-%s" % (event_year(), shift.id))
cal_event.add("summary", "%s at %s" % (shift.role.name, shift.venue.name))
cal_event.add("location", shift.venue.name)
cal_event.add("dtstart", event_tz.localize(shift.start))
cal_event.add("dtend", event_tz.localize(shift.end))
cal.add_component(cal_event)

return Response(cal.to_ical(), mimetype="text/calendar")


@volunteer.route("/shift/<shift_id>", methods=["GET"])
@feature_flag("VOLUNTEERS_SCHEDULE")
@v_admin_required
Expand Down
2 changes: 1 addition & 1 deletion models/volunteer/shift.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Shift(BaseModel):
proposal = db.relationship("Proposal", backref="shift")

current_count = db.column_property(
select([func.count(ShiftEntry.shift_id)]).where(ShiftEntry.shift_id == id).scalar_subquery() # type: ignore[attr-defined]
select([func.count(ShiftEntry.shift_id)]).where(ShiftEntry.shift_id == id).correlate_except(ShiftEntry).scalar_subquery() # type: ignore[attr-defined,arg-type]
)

duration = db.column_property(end - start)
Expand Down
4 changes: 3 additions & 1 deletion templates/volunteer/schedule.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
<h2>Pick your shifts</h2>
<p>Select a day to sign up for shifts. To change which roles you're interested in, <a href="{{ url_for('.choose_role') }}">click here</a>.</p>

<p>You can get a list of all your shifts as an <a href="{{ url_for('.schedule_ical', token=token) }}">iCal feed</a>.</p>

{% if untrained_roles %}
<div class="alert alert-info">
You still need training before starting a shift for the following roles:
Expand Down Expand Up @@ -87,7 +89,7 @@ <h2>Pick your shifts</h2>
{{ hour }}{% if shift.end %} to {{ shift.end_time }}{% endif %}
{% endif %}
</td>
<td class="venue">{{ shift.venue.name }}</td>
<td class="venue"><a href="{{ shift.venue.mapref }}">{{ shift.venue.name }}</a></td>
<td class="role">{{ shift.role.name }}</td>
<td class="staffing">{{ shift.current_count }}/{{ shift.max_needed }}</td>
<td class="button">
Expand Down

0 comments on commit 3039e4b

Please sign in to comment.