add a switch to filter closed UEs

This commit is contained in:
imperosol
2026-09-01 00:34:29 +02:00
parent bbdf6a5dd2
commit 582e6af2c9
3 changed files with 23 additions and 2 deletions
+8
View File
@@ -153,6 +153,7 @@ class UeFilterSchema(FilterSchema):
set[Literal["CS", "TM", "EC", "OM", "QC"]] | None, set[Literal["CS", "TM", "EC", "OM", "QC"]] | None,
FilterLookup("credit_type__in"), FilterLookup("credit_type__in"),
] = None ] = None
is_open: bool | None = None
language: str = "FR" language: str = "FR"
department: Annotated[set[str] | None, FilterLookup("department__in")] = None department: Annotated[set[str] | None, FilterLookup("department__in")] = None
@@ -187,3 +188,10 @@ class UeFilterSchema(FilterSchema):
return Q() return Q()
value.add("AUTUMN_AND_SPRING") value.add("AUTUMN_AND_SPRING")
return Q(semester__in=value) return Q(semester__in=value)
def filter_is_open(self, value: bool | None) -> Q: # noqa: FBT001
if value is None:
return Q()
if not value:
return Q(semester="CLOSED")
return ~Q(semester="CLOSED")
@@ -17,6 +17,7 @@ document.addEventListener("alpine:init", () => {
// biome-ignore lint/style/useNamingConvention: api is in snake_case // biome-ignore lint/style/useNamingConvention: api is in snake_case
page_size: pageSizeDefault, page_size: pageSizeDefault,
search: "", search: "",
hideClosedUes: true,
department: [] as string[], department: [] as string[],
// biome-ignore lint/style/useNamingConvention: api is in snake_case // biome-ignore lint/style/useNamingConvention: api is in snake_case
credit_type: [] as string[], credit_type: [] as string[],
@@ -38,6 +39,7 @@ document.addEventListener("alpine:init", () => {
10, 10,
); );
this.search = url.get("search") || ""; this.search = url.get("search") || "";
this.hideClosedUes = url.get("hideClosed") || true;
this.department = url.getAll("department"); this.department = url.getAll("department");
this.credit_type = url.getAll("credit_type"); this.credit_type = url.getAll("credit_type");
/* The semester is easier to use on the backend as an enum (spring/autumn/both/none) /* The semester is easier to use on the backend as an enum (spring/autumn/both/none)
@@ -58,7 +60,13 @@ document.addEventListener("alpine:init", () => {
this.to_change = []; this.to_change = [];
}, 50); }, 50);
const searchParams = ["search", "department", "credit_type", "semester"]; const searchParams = [
"search",
"hideClosedUes",
"department",
"credit_type",
"semester",
];
const paginationParams = ["page", "page_size"]; const paginationParams = ["page", "page_size"];
for (const param of searchParams) { for (const param of searchParams) {
@@ -87,7 +95,8 @@ document.addEventListener("alpine:init", () => {
// biome-ignore lint/style/useNamingConvention: api is in snake_case // biome-ignore lint/style/useNamingConvention: api is in snake_case
credit_type: this.credit_type.length > 0 ? this.credit_type : undefined, credit_type: this.credit_type.length > 0 ? this.credit_type : undefined,
semester: this.semester.length > 0 ? this.semester : undefined, semester: this.semester.length > 0 ? this.semester : undefined,
// biome-ignore lint/style/useNamingConvention: api is snake_case
is_open: this.hideClosedUes ? true : undefined,
department: this.department.length > 0 ? this.department : undefined, department: this.department.length > 0 ? this.department : undefined,
search: this.search || undefined, search: this.search || undefined,
}, },
+4
View File
@@ -44,6 +44,10 @@
x-model.debounce.500ms="search" x-model.debounce.500ms="search"
/> />
</fieldset> </fieldset>
<fieldset>
<input type="checkbox" class="switch" x-model="hideClosedUes" id="hide-closed-ues" name="hide-closed-ues">
<label for="hide-closed-ues">{% trans %}Hide closed UEs{% endtrans %}</label>
</fieldset>
<div class="row gap-3x margin-bottom radio-guide"> <div class="row gap-3x margin-bottom radio-guide">
<fieldset> <fieldset>
{% set departments = [ {% set departments = [