Skip to content

Commit 7bd7187

Browse files
committed
Give volunteer admins the same shift signup UI
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.
1 parent 7e0313b commit 7bd7187

File tree

2 files changed

+33
-36
lines changed

2 files changed

+33
-36
lines changed

apps/volunteer/schedule.py

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,7 @@ def schedule():
7575
venues = VolunteerVenue.get_all()
7676

7777
untrained_roles = [
78-
r
79-
for r in roles
80-
if r["is_interested"] and r["requires_training"] and not r["is_trained"]
78+
r for r in roles if r["is_interested"] and r["requires_training"] and not r["is_trained"]
8179
]
8280

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

100-
return render_template(
101-
"volunteer/shift.html", shift=shift, all_volunteers=all_volunteers
102-
)
98+
return render_template("volunteer/shift.html", shift=shift, all_volunteers=all_volunteers)
10399

104100

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

121117
if shift.current_count >= shift.max_needed:
122-
return redirect_next_or_schedule(
123-
"This shift is already full. You have not been signed up."
124-
)
125-
126-
if (
127-
shift.role.requires_training
128-
and shift.role not in Volunteer.get_for_user(current_user).trained_roles
129-
):
130-
return redirect_next_or_schedule(
131-
"You must complete training before you can sign up for this shift."
132-
)
118+
return redirect_next_or_schedule("This shift is already full. You have not been signed up.")
119+
120+
if shift.role.requires_training and shift.role not in Volunteer.get_for_user(current_user).trained_roles:
121+
return redirect_next_or_schedule("You must complete training before you can sign up for this shift.")
133122

134123
for shift_entry in user.shift_entries:
135124
if shift.is_clash(shift_entry.shift):

templates/volunteer/schedule.html

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -73,27 +73,35 @@ <h2>Pick your shifts</h2>
7373
{% else %}
7474
<td class="start_time hidden">{{ hour }}</td>
7575
{% endif %}
76-
<td class="end_time">{{ shift.end_time if shift.end else '--' }}</td>
77-
<td class="time mobile-only">{{ hour }}{% if shift.end %} to {{ shift.end_time }}{% endif %}</td>
76+
<td class="end_time">
77+
{% if current_user.has_permission("volunteer:admin") %}
78+
<a href="{{ url_for('.shift', shift_id=shift.id) }}">{{ shift.end_time if shift.end else '--' }}</a>
79+
{% else %}
80+
{{ shift.end_time if shift.end else '--' }}
81+
{% endif %}
82+
</td>
83+
<td class="time mobile-only">
84+
{% if current_user.has_permission("volunteer:admin") %}
85+
<a href="{{ url_for('.shift', shift_id=shift.id) }}">{{ hour }}{% if shift.end %} to {{ shift.end_time }}{% endif %}</a>
86+
{% else %}
87+
{{ hour }}{% if shift.end %} to {{ shift.end_time }}{% endif %}
88+
{% endif %}
89+
</td>
7890
<td class="venue">{{ shift.venue.name }}</td>
7991
<td class="role">{{ shift.role.name }}</td>
8092
<td class="staffing">{{ shift.current_count }}/{{ shift.max_needed }}</td>
81-
{% if current_user.has_permission("volunteer:admin") %}
82-
<td class="button"><a href="{{ url_for('.shift', shift_id=shift.id) }}" class="btn btn-block btn-primary">Details</a></td>
83-
{% else %}
84-
<td class="button">
85-
{%- if shift.is_user_shift -%}
86-
<form method="post" action="{{ url_for('.shift_cancel', shift_id=shift.id) }}">
87-
<button class="btn btn-block btn-danger">Cancel</button>
88-
</form>
89-
{%- else -%}
90-
<form method="post" action="{{ url_for('.shift_sign_up', shift_id=shift.id) }}">
91-
<button class="btn btn-block btn-success">Sign Up</button>
92-
</form>
93-
{%- endif -%}
94-
</form>
95-
</td>
96-
{% endif %}
93+
<td class="button">
94+
{%- if shift.is_user_shift -%}
95+
<form method="post" action="{{ url_for('.shift_cancel', shift_id=shift.id, next=url_for('.schedule', day=active_day)) }}">
96+
<button class="btn btn-block btn-danger">Cancel</button>
97+
</form>
98+
{%- else -%}
99+
<form method="post" action="{{ url_for('.shift_sign_up', shift_id=shift.id, next=url_for('.schedule', day=active_day)) }}">
100+
<button class="btn btn-block btn-success">Sign Up</button>
101+
</form>
102+
{%- endif -%}
103+
</form>
104+
</td>
97105
</tr>
98106
{% endfor %}
99107
{% endfor %}

0 commit comments

Comments
 (0)