Skip to content

Commit

Permalink
Give volunteer admins the same shift signup UI
Browse files Browse the repository at this point in the history
It was very clunky for a volunteer admin to sign up to shifts for
themselves, because the button to do so was replaced with a details
button.

That's now a link from the start time.

Also, an unintended formatting pass on schedule.py.
  • Loading branch information
jellybob committed May 15, 2024
1 parent 7e0313b commit 7bd7187
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 36 deletions.
25 changes: 7 additions & 18 deletions apps/volunteer/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ def schedule():
venues = VolunteerVenue.get_all()

untrained_roles = [
r
for r in roles
if r["is_interested"] and r["requires_training"] and not r["is_trained"]
r for r in roles if r["is_interested"] and r["requires_training"] and not r["is_trained"]
]

return render_template(
Expand All @@ -97,17 +95,15 @@ def shift(shift_id):
shift = Shift.query.get_or_404(shift_id)
all_volunteers = Volunteer.query.order_by(Volunteer.nickname).all()

return render_template(
"volunteer/shift.html", shift=shift, all_volunteers=all_volunteers
)
return render_template("volunteer/shift.html", shift=shift, all_volunteers=all_volunteers)


@volunteer.route("/shift/<shift_id>/sign-up", methods=["POST"])
@feature_flag("VOLUNTEERS_SCHEDULE")
@v_user_required
def shift_sign_up(shift_id):
shift = Shift.query.get_or_404(shift_id)
if current_user.has_permission("volunteer:admin") and request.form["user_id"]:
if current_user.has_permission("volunteer:admin") and "user_id" in request.form:
user = User.query.get(request.form["user_id"])
else:
user = current_user
Expand All @@ -119,17 +115,10 @@ def shift_sign_up(shift_id):
return redirect_next_or_schedule(f"Signed up for {shift.role.name} shift")

if shift.current_count >= shift.max_needed:
return redirect_next_or_schedule(
"This shift is already full. You have not been signed up."
)

if (
shift.role.requires_training
and shift.role not in Volunteer.get_for_user(current_user).trained_roles
):
return redirect_next_or_schedule(
"You must complete training before you can sign up for this shift."
)
return redirect_next_or_schedule("This shift is already full. You have not been signed up.")

if shift.role.requires_training and shift.role not in Volunteer.get_for_user(current_user).trained_roles:
return redirect_next_or_schedule("You must complete training before you can sign up for this shift.")

for shift_entry in user.shift_entries:
if shift.is_clash(shift_entry.shift):
Expand Down
44 changes: 26 additions & 18 deletions templates/volunteer/schedule.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,27 +73,35 @@ <h2>Pick your shifts</h2>
{% else %}
<td class="start_time hidden">{{ hour }}</td>
{% endif %}
<td class="end_time">{{ shift.end_time if shift.end else '--' }}</td>
<td class="time mobile-only">{{ hour }}{% if shift.end %} to {{ shift.end_time }}{% endif %}</td>
<td class="end_time">
{% if current_user.has_permission("volunteer:admin") %}
<a href="{{ url_for('.shift', shift_id=shift.id) }}">{{ shift.end_time if shift.end else '--' }}</a>
{% else %}
{{ shift.end_time if shift.end else '--' }}
{% endif %}
</td>
<td class="time mobile-only">
{% if current_user.has_permission("volunteer:admin") %}
<a href="{{ url_for('.shift', shift_id=shift.id) }}">{{ hour }}{% if shift.end %} to {{ shift.end_time }}{% endif %}</a>
{% else %}
{{ hour }}{% if shift.end %} to {{ shift.end_time }}{% endif %}
{% endif %}
</td>
<td class="venue">{{ shift.venue.name }}</td>
<td class="role">{{ shift.role.name }}</td>
<td class="staffing">{{ shift.current_count }}/{{ shift.max_needed }}</td>
{% if current_user.has_permission("volunteer:admin") %}
<td class="button"><a href="{{ url_for('.shift', shift_id=shift.id) }}" class="btn btn-block btn-primary">Details</a></td>
{% else %}
<td class="button">
{%- if shift.is_user_shift -%}
<form method="post" action="{{ url_for('.shift_cancel', shift_id=shift.id) }}">
<button class="btn btn-block btn-danger">Cancel</button>
</form>
{%- else -%}
<form method="post" action="{{ url_for('.shift_sign_up', shift_id=shift.id) }}">
<button class="btn btn-block btn-success">Sign Up</button>
</form>
{%- endif -%}
</form>
</td>
{% endif %}
<td class="button">
{%- if shift.is_user_shift -%}
<form method="post" action="{{ url_for('.shift_cancel', shift_id=shift.id, next=url_for('.schedule', day=active_day)) }}">
<button class="btn btn-block btn-danger">Cancel</button>
</form>
{%- else -%}
<form method="post" action="{{ url_for('.shift_sign_up', shift_id=shift.id, next=url_for('.schedule', day=active_day)) }}">
<button class="btn btn-block btn-success">Sign Up</button>
</form>
{%- endif -%}
</form>
</td>
</tr>
{% endfor %}
{% endfor %}
Expand Down

0 comments on commit 7bd7187

Please sign in to comment.