Beispiel #1
0
def schedule():
    shifts = Shift.get_all()
    by_time = defaultdict(lambda: defaultdict(list))

    if current_user.has_permission("volunteer:admin"):
        all_volunteers = Volunteer.query.order_by(Volunteer.nickname).all()
    else:
        all_volunteers = []

    for s in shifts:
        day_key = s.start.strftime("%a").lower()
        hour_key = s.start.strftime("%H:%M")

        to_add = s.to_localtime_dict()
        to_add["sign_up_url"] = url_for(".shift", shift_id=to_add["id"])
        to_add["is_user_shift"] = current_user in s.volunteers

        by_time[day_key][hour_key].append(to_add)

    roles = _get_interested_roles(current_user)
    venues = VolunteerVenue.get_all()

    untrained_roles = [
        r for r in roles if r["is_interested"] and r["requires_training"]
        and not r["is_trained"]
    ]
    if datetime.utcnow() < config_date("EVENT_START"):
        def_day = "thu"
    else:
        def_day = pendulum.now().strftime("%a").lower()
    active_day = request.args.get("day", default=def_day)

    return render_template(
        "volunteer/schedule.html",
        roles=roles,
        venues=venues,
        all_shifts=by_time,
        active_day=active_day,
        all_volunteers=all_volunteers,
        untrained_roles=untrained_roles,
    )
Beispiel #2
0
def get_venues():
    return VolunteerVenue.get_all()