mirror of
https://github.com/ae-utbm/sith.git
synced 2026-09-09 22:09:14 +00:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
61d4c1be32 | ||
|
|
a48ee76767 |
@@ -4,11 +4,15 @@
|
|||||||
{% trans %}Delete confirmation{% endtrans %}
|
{% trans %}Delete confirmation{% endtrans %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{# Don't display tabs and errors #}
|
{% if is_fragment %}
|
||||||
{% block tabs %}
|
|
||||||
{% endblock %}
|
{# Don't display tabs and errors #}
|
||||||
{% block errors %}
|
{% block tabs %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
{% block errors %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% block file %}
|
{% block file %}
|
||||||
<h2>{% trans %}Delete confirmation{% endtrans %}</h2>
|
<h2>{% trans %}Delete confirmation{% endtrans %}</h2>
|
||||||
@@ -19,32 +23,30 @@
|
|||||||
{% set action = current %}
|
{% set action = current %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<p>{% trans obj=object %}Are you sure you want to delete "{{ obj }}"?{% endtrans %}</p>
|
<form action="{{ action }}" method="post">
|
||||||
<form
|
|
||||||
method="post"
|
|
||||||
{% if is_fragment %}
|
|
||||||
hx-action="{{ action }}"
|
|
||||||
hx-target="#content"
|
|
||||||
hx-swap="innerHTML"
|
|
||||||
{% else %}
|
|
||||||
action="{{ action }}"
|
|
||||||
{% endif %}
|
|
||||||
>
|
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<input type="submit" value="{% trans %}Confirm{% endtrans %}" />
|
|
||||||
</form>
|
<p>{% trans obj=object %}Are you sure you want to delete "{{ obj }}"?{% endtrans %}</p>
|
||||||
<form
|
<button
|
||||||
method="get"
|
{% if is_fragment %}
|
||||||
{% if is_fragment %}
|
hx-post="{{ action }}"
|
||||||
hx-action="{{ previous }}"
|
hx-target="#content"
|
||||||
hx-target="#content"
|
hx-swap="innerHTML"
|
||||||
hx-swap="innerHTML"
|
{% endif %}
|
||||||
{% else %}
|
>{% trans %}Confirm{% endtrans %}</button>
|
||||||
action="javascript:history.back();"
|
|
||||||
{% endif %}
|
<button
|
||||||
>
|
{% if is_fragment %}
|
||||||
<input type="submit" name="cancel" value="{% trans %}Cancel{% endtrans %}" />
|
hx-get="{{ previous }}"
|
||||||
|
hx-target="#content"
|
||||||
|
hx-swap="innerHTML"
|
||||||
|
{% else %}
|
||||||
|
action="window.history.back()"
|
||||||
|
{% endif %}
|
||||||
|
>{% trans %}Cancel{% endtrans %}</button>
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+22
-6
@@ -21,7 +21,7 @@
|
|||||||
# Place - Suite 330, Boston, MA 02111-1307, USA.
|
# Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
from django.urls import path, register_converter
|
from django.urls import path, re_path, register_converter
|
||||||
from django.views.generic import RedirectView
|
from django.views.generic import RedirectView
|
||||||
|
|
||||||
from com.views import NewsListView
|
from com.views import NewsListView
|
||||||
@@ -193,11 +193,27 @@ urlpatterns = [
|
|||||||
name="user_gift_delete",
|
name="user_gift_delete",
|
||||||
),
|
),
|
||||||
# File views
|
# File views
|
||||||
path("file/", FileListView.as_view(), name="file_list"),
|
re_path(r"^file/$", FileListView.as_view(), name="file_list"),
|
||||||
path("file/<int:file_id>/", FileView.as_view(), name="file_detail"),
|
re_path(
|
||||||
path("file/<int:file_id>/edit/", FileEditView.as_view(), name="file_edit"),
|
r"^file/(?P<file_id>[0-9]+)/$",
|
||||||
path("file/<int:file_id>/prop/", FileEditPropView.as_view(), name="file_prop"),
|
FileView.as_view(),
|
||||||
path("file/<int:file_id>/delete/", FileDeleteView.as_view(), name="file_delete"),
|
name="file_detail",
|
||||||
|
),
|
||||||
|
re_path(
|
||||||
|
r"^file/(?P<file_id>[0-9]+)/edit/$",
|
||||||
|
FileEditView.as_view(),
|
||||||
|
name="file_edit",
|
||||||
|
),
|
||||||
|
re_path(
|
||||||
|
r"^file/(?P<file_id>[0-9]+)/prop/$",
|
||||||
|
FileEditPropView.as_view(),
|
||||||
|
name="file_prop",
|
||||||
|
),
|
||||||
|
re_path(
|
||||||
|
r"^file/(?P<file_id>[0-9]+)/delete/$",
|
||||||
|
FileDeleteView.as_view(),
|
||||||
|
name="file_delete",
|
||||||
|
),
|
||||||
path("file/moderation/", FileModerationView.as_view(), name="file_moderation"),
|
path("file/moderation/", FileModerationView.as_view(), name="file_moderation"),
|
||||||
path(
|
path(
|
||||||
"file/<int:file_id>/moderate/", FileModerateView.as_view(), name="file_moderate"
|
"file/<int:file_id>/moderate/", FileModerateView.as_view(), name="file_moderate"
|
||||||
|
|||||||
+9
-2
@@ -356,8 +356,15 @@ class FileDeleteView(AllowFragment, CanEditPropMixin, DeleteView):
|
|||||||
if "next" in self.request.GET:
|
if "next" in self.request.GET:
|
||||||
return self.request.GET["next"]
|
return self.request.GET["next"]
|
||||||
if self.object.parent is None:
|
if self.object.parent is None:
|
||||||
return reverse("core:file_list")
|
return reverse(
|
||||||
return reverse("core:file_detail", kwargs={"file_id": self.object.parent.id})
|
"core:file_list",
|
||||||
|
)
|
||||||
|
return reverse(
|
||||||
|
"core:file_detail",
|
||||||
|
kwargs={
|
||||||
|
"file_id": self.object.parent.id,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
kwargs = super().get_context_data(**kwargs)
|
kwargs = super().get_context_data(**kwargs)
|
||||||
|
|||||||
@@ -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")
|
||||||
|
|||||||
@@ -1,118 +0,0 @@
|
|||||||
import {
|
|
||||||
getCurrentUrlParams,
|
|
||||||
History,
|
|
||||||
updateQueryString,
|
|
||||||
} from "#core:utils/history.ts";
|
|
||||||
import { ueFetchUeList } from "#openapi";
|
|
||||||
|
|
||||||
const pageDefault = 1;
|
|
||||||
const pageSizeDefault = 100;
|
|
||||||
|
|
||||||
document.addEventListener("alpine:init", () => {
|
|
||||||
Alpine.data("ue_search", () => ({
|
|
||||||
ues: {
|
|
||||||
count: 0,
|
|
||||||
next: null,
|
|
||||||
previous: null,
|
|
||||||
results: [],
|
|
||||||
},
|
|
||||||
loading: false,
|
|
||||||
page: pageDefault,
|
|
||||||
// biome-ignore lint/style/useNamingConvention: api is in snake_case
|
|
||||||
page_size: pageSizeDefault,
|
|
||||||
search: "",
|
|
||||||
department: [],
|
|
||||||
// biome-ignore lint/style/useNamingConvention: api is in snake_case
|
|
||||||
credit_type: [],
|
|
||||||
semester: [],
|
|
||||||
// biome-ignore lint/style/useNamingConvention: api is in snake_case
|
|
||||||
to_change: [],
|
|
||||||
pushstate: History.Push,
|
|
||||||
|
|
||||||
update: undefined,
|
|
||||||
|
|
||||||
initializeArgs() {
|
|
||||||
const url = getCurrentUrlParams();
|
|
||||||
this.pushstate = History.Replace;
|
|
||||||
|
|
||||||
this.page = Number.parseInt(url.get("page"), 10) || pageDefault;
|
|
||||||
this.page_size = Number.parseInt(url.get("page_size"), 10) || pageSizeDefault;
|
|
||||||
this.search = url.get("search") || "";
|
|
||||||
this.department = url.getAll("department");
|
|
||||||
this.credit_type = url.getAll("credit_type");
|
|
||||||
/* The semester is easier to use on the backend as an enum (spring/autumn/both/none)
|
|
||||||
and easier to use on the frontend as an array ([spring, autumn]).
|
|
||||||
Thus there is some conversion involved when both communicate together */
|
|
||||||
this.semester = url.has("semester") ? url.get("semester").split("_AND_") : [];
|
|
||||||
|
|
||||||
this.update();
|
|
||||||
},
|
|
||||||
|
|
||||||
async init() {
|
|
||||||
this.update = Alpine.debounce(async () => {
|
|
||||||
/* Create the whole url before changing everything all at once */
|
|
||||||
const first = this.to_change.shift();
|
|
||||||
let url = updateQueryString(first.param, first.value, History.None);
|
|
||||||
for (const value of this.to_change) {
|
|
||||||
url = updateQueryString(value.param, value.value, History.None, url);
|
|
||||||
}
|
|
||||||
updateQueryString(first.param, first.value, this.pushstate, url);
|
|
||||||
await this.fetchData(); /* reload data on form change */
|
|
||||||
this.to_change = [];
|
|
||||||
this.pushstate = History.Push;
|
|
||||||
}, 50);
|
|
||||||
|
|
||||||
const searchParams = ["search", "department", "credit_type", "semester"];
|
|
||||||
const paginationParams = ["page", "page_size"];
|
|
||||||
|
|
||||||
for (const param of searchParams) {
|
|
||||||
this.$watch(param, () => {
|
|
||||||
if (this.pushstate !== History.Push) {
|
|
||||||
/* This means that we are doing a mass param edit */
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
/* Reset pagination on search */
|
|
||||||
this.page = pageDefault;
|
|
||||||
this.page_size = pageSizeDefault;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
for (const param of searchParams.concat(paginationParams)) {
|
|
||||||
this.$watch(param, (value) => {
|
|
||||||
this.to_change.push({ param: param, value: value });
|
|
||||||
this.update();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
window.addEventListener("popstate", () => {
|
|
||||||
this.initializeArgs();
|
|
||||||
});
|
|
||||||
this.initializeArgs();
|
|
||||||
},
|
|
||||||
|
|
||||||
async fetchData() {
|
|
||||||
this.loading = true;
|
|
||||||
const args = {
|
|
||||||
// biome-ignore lint/style/useNamingConvention: api is in snake_case
|
|
||||||
page_size: this.page_size,
|
|
||||||
};
|
|
||||||
for (const [param, value] of new URL(
|
|
||||||
window.location.href,
|
|
||||||
).searchParams.entries()) {
|
|
||||||
// Deal with array type params
|
|
||||||
if (["credit_type", "department", "semester"].includes(param)) {
|
|
||||||
if (args[param] === undefined) {
|
|
||||||
args[param] = [];
|
|
||||||
}
|
|
||||||
args[param].push(value);
|
|
||||||
} else {
|
|
||||||
args[param] = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.ues = (await ueFetchUeList({ query: args })).data;
|
|
||||||
this.loading = false;
|
|
||||||
},
|
|
||||||
|
|
||||||
maxPage() {
|
|
||||||
return Math.ceil(this.ues.count / this.page_size);
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
import { getCurrentUrlParams, updateQueryString } from "#core:utils/history";
|
||||||
|
import { type SimpleUeSchema, ueFetchUeList } from "#openapi";
|
||||||
|
|
||||||
|
const pageDefault = 1;
|
||||||
|
const pageSizeDefault = 100;
|
||||||
|
|
||||||
|
document.addEventListener("alpine:init", () => {
|
||||||
|
Alpine.data("ue_search", () => ({
|
||||||
|
ues: {
|
||||||
|
count: 0,
|
||||||
|
next: null as string | null,
|
||||||
|
previous: null as string | null,
|
||||||
|
results: [] as SimpleUeSchema[],
|
||||||
|
},
|
||||||
|
loading: false,
|
||||||
|
page: pageDefault,
|
||||||
|
// biome-ignore lint/style/useNamingConvention: api is in snake_case
|
||||||
|
page_size: pageSizeDefault,
|
||||||
|
search: "",
|
||||||
|
hideClosedUes: true,
|
||||||
|
department: [] as string[],
|
||||||
|
// biome-ignore lint/style/useNamingConvention: api is in snake_case
|
||||||
|
credit_type: [] as string[],
|
||||||
|
semester: [] as string[],
|
||||||
|
// biome-ignore lint/style/useNamingConvention: api is in snake_case
|
||||||
|
to_change: [] as { param: string; value: string }[],
|
||||||
|
|
||||||
|
// dummy implementation to make TS happy.
|
||||||
|
// The real function is initialized in init
|
||||||
|
update: () => {
|
||||||
|
console.warn("Update not yet initialized");
|
||||||
|
},
|
||||||
|
|
||||||
|
initializeArgs() {
|
||||||
|
const url = getCurrentUrlParams();
|
||||||
|
this.page = Number.parseInt(url.get("page") || pageDefault.toString(), 10);
|
||||||
|
this.page_size = Number.parseInt(
|
||||||
|
url.get("page_size") || pageSizeDefault.toString(),
|
||||||
|
10,
|
||||||
|
);
|
||||||
|
this.search = url.get("search") || "";
|
||||||
|
this.hideClosedUes = url.get("hideClosed") || true;
|
||||||
|
this.department = url.getAll("department");
|
||||||
|
this.credit_type = url.getAll("credit_type");
|
||||||
|
/* The semester is easier to use on the backend as an enum (spring/autumn/both/none)
|
||||||
|
and easier to use on the frontend as an array ([spring, autumn]).
|
||||||
|
Thus there is some conversion involved when both communicate together */
|
||||||
|
this.semester = url.get("semester")?.split("_AND_") || [];
|
||||||
|
|
||||||
|
this.update();
|
||||||
|
},
|
||||||
|
|
||||||
|
async init() {
|
||||||
|
this.update = Alpine.debounce(async () => {
|
||||||
|
/* Create the whole url before changing everything all at once */
|
||||||
|
for (const val of this.to_change) {
|
||||||
|
updateQueryString(val.param, val.value);
|
||||||
|
}
|
||||||
|
await this.fetchData(); /* reload data on form change */
|
||||||
|
this.to_change = [];
|
||||||
|
}, 50);
|
||||||
|
|
||||||
|
const searchParams = [
|
||||||
|
"search",
|
||||||
|
"hideClosedUes",
|
||||||
|
"department",
|
||||||
|
"credit_type",
|
||||||
|
"semester",
|
||||||
|
];
|
||||||
|
const paginationParams = ["page", "page_size"];
|
||||||
|
|
||||||
|
for (const param of searchParams) {
|
||||||
|
this.$watch(param, () => {
|
||||||
|
/* Reset pagination on search */
|
||||||
|
this.page = pageDefault;
|
||||||
|
this.page_size = pageSizeDefault;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
for (const param of searchParams.concat(paginationParams)) {
|
||||||
|
this.$watch(param, (value: string) => {
|
||||||
|
this.to_change.push({ param: param, value: value });
|
||||||
|
this.update();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
this.initializeArgs();
|
||||||
|
},
|
||||||
|
|
||||||
|
async fetchData() {
|
||||||
|
this.loading = true;
|
||||||
|
|
||||||
|
const res = await ueFetchUeList({
|
||||||
|
query: {
|
||||||
|
// biome-ignore lint/style/useNamingConvention: api is in snake_case
|
||||||
|
page_size: this.page_size,
|
||||||
|
// biome-ignore lint/style/useNamingConvention: api is in snake_case
|
||||||
|
credit_type: this.credit_type.length > 0 ? this.credit_type : 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,
|
||||||
|
search: this.search || undefined,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (res.data !== undefined) {
|
||||||
|
this.ues = res.data;
|
||||||
|
}
|
||||||
|
this.loading = false;
|
||||||
|
},
|
||||||
|
|
||||||
|
maxPage() {
|
||||||
|
return Math.ceil(this.ues.count / this.page_size);
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
});
|
||||||
@@ -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 = [
|
||||||
|
|||||||
Reference in New Issue
Block a user