Skip to content

Commit

Permalink
Refactor extra_shifts query and update edit_page template
Browse files Browse the repository at this point in the history
This commit refactors the extra_shifts query in the `edit_page` function of `extra_duties.py` to include a subquery for ShiftInterest objects. It also updates the `edit_page.html` template to display the registrar and comment for each shift if they exist. If not, it provides an option to select a registrar and save the selection.
  • Loading branch information
Tubo committed Jan 4, 2024
1 parent d0bb885 commit d521189
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 22 deletions.
9 changes: 7 additions & 2 deletions radscheduler/core/views/extra_duties.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,17 @@ def interest(request, interest_id):

@staff_member_required
def edit_page(request):
subquery = ShiftInterest.objects.filter(registrar=request.user.registrar, shift=OuterRef("pk"))
extra_shifts = (
Shift.objects.filter(extra_duty=True, registrar=None)
Shift.objects.filter(extra_duty=True, date__gte=date.today() - timedelta(days=30))
.annotate(
interest_id=Subquery(subquery.values("pk")),
comment=Subquery(subquery.values("comment")),
)
.order_by("-date")
.select_related("registrar__user")
.prefetch_related("interests", "interests__registrar__user")
).all()
)
end = extra_shifts.first().date if extra_shifts else date.today()
start = extra_shifts.last().date if extra_shifts else date.today()
registrars = active_registrars(start, end)
Expand Down
44 changes: 25 additions & 19 deletions radscheduler/templates/extra_duties/edit_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,31 @@
{% endfor %}
</td>
<td>
<div x-data="{shift_id: {{ shift.id }} }" class="input-group">
<select class="form-select"
id="registrar_selected"
name="registrar"
x-ref="select_element">
<option value=""></option>
{% for registrar in registrars %}
<option value="{{ registrar.pk }}" class="registrar_option">{{ registrar.user.username }}</option>
{% endfor %}
</select>
<button class="btn btn-primary"
type="button"
@click="$store.select_random(shift_id, $refs.select_element)">Roll</button>
<button class="btn btn-warning"
type="button"
hx-post="{% url 'extra_save_registrar' shift.pk %}"
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-include="previous #registrar_selected">Save</button>
</div>
{% if shift.registrar %}
{{ shift.registrar }}: {{ shift.comment }}
{% else %}
<div x-data="{shift_id: {{ shift.id }} }" class="input-group">
<select class="form-select"
id="registrar_selected"
name="registrar"
x-ref="select_element">
<option value=""></option>
{% for registrar in registrars %}
<option value="{{ registrar.pk }}" class="registrar_option">{{ registrar.user.username }}</option>
{% endfor %}
</select>
<button class="btn btn-primary"
type="button"
@click="$store.select_random(shift_id, $refs.select_element)">
Roll
</button>
<button class="btn btn-warning"
type="button"
hx-post="{% url 'extra_save_registrar' shift.pk %}"
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-include="previous #registrar_selected">Save</button>
</div>
{% endif %}
</td>
</tr>
{% endfor %}
Expand Down
2 changes: 1 addition & 1 deletion radscheduler/templates/extra_duties/row.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<input type="text"
name="comment"
class="form-control"
placeholder="Comment"
placeholder="Preferred RDOs etc"
value="{{ shift.comment }}" />
<button class="btn btn-sm btn-primary"
type="button"
Expand Down

0 comments on commit d521189

Please sign in to comment.