Skip to content

Commit

Permalink
Add "rostered" status for leaves
Browse files Browse the repository at this point in the history
  • Loading branch information
Tubo committed Mar 15, 2024
1 parent 381a911 commit cb92857
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
23 changes: 20 additions & 3 deletions radscheduler/core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import Any

from django.contrib import admin
from django.db.models import Q
from django.db.models import Exists, OuterRef, Q
from django.db.models.query import QuerySet
from django.http import FileResponse
from django.http.request import HttpRequest
Expand Down Expand Up @@ -205,13 +205,21 @@ class LeaveAdmin(admin.ModelAdmin):
"reg_approved",
"dot_approved",
"microster",
"rostered",
"printed",
"no_abutting_weekend",
"cancelled",
"created",
"last_edited",
)
list_editable = ("dot_approved", "reg_approved", "printed", "microster", "no_abutting_weekend", "cancelled")
list_editable = (
"dot_approved",
"reg_approved",
"printed",
"microster",
"no_abutting_weekend",
"cancelled",
)
list_filter = (
(
"date",
Expand All @@ -234,7 +242,12 @@ class LeaveAdmin(admin.ModelAdmin):
ordering = ("-date", "registrar")

def get_queryset(self, request: HttpRequest) -> QuerySet[Any]:
queryset = super().get_queryset(request).select_related("registrar", "registrar__user")
queryset = super().get_queryset(request)
queryset = queryset.annotate(
# Check if a shift exists for the leave date
rostered=Exists(Shift.objects.filter(registrar=OuterRef("registrar"), date=OuterRef("date")))
)
queryset = queryset.select_related("registrar", "registrar__user")
return queryset

def get_list_display(self, request: HttpRequest) -> Sequence[str]:
Expand Down Expand Up @@ -274,6 +287,10 @@ def custom_date_format(self, obj):
return obj.date.strftime("%d-%m-%Y, %a")
return ""

@admin.display(description="Rostered", boolean=True)
def rostered(self, obj):
return obj.rostered

@admin.action(description="Print the selected leave forms")
def print_selected(self, request, queryset):
buffer = leaves_to_buffer(queryset)
Expand Down
2 changes: 2 additions & 0 deletions radscheduler/core/views/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def change_shift_registrar(request, pk):
"current_registrar": shift.registrar,
},
)

elif request.method == "POST":
form = ShiftChangeForm(request.POST)
if form.is_valid():
Expand All @@ -112,6 +113,7 @@ def change_shift_registrar(request, pk):
shift.registrar = registrar
shift.save()
return render(request, "generator/shift_cell_button.html", {"shift": mapper.shift_from_db(shift)})

elif request.method == "DELETE":
form = ShiftChangeForm(request.POST)
if form.is_valid():
Expand Down

0 comments on commit cb92857

Please sign in to comment.