On peut filtrer les imports récurrents

This commit is contained in:
Jean-Marie Favreau 2024-11-23 16:31:04 +01:00
parent 720a187116
commit 0872af5144
3 changed files with 62 additions and 19 deletions

View File

@ -477,3 +477,17 @@ class DuplicatedEventsFilter(django_filters.FilterSet):
def fixed_qs(self, queryset, name, value):
return DuplicatedEvents.not_fixed_qs(queryset, value)
class RecurrentImportFilter(django_filters.FilterSet):
name = django_filters.ModelMultipleChoiceFilter(
label="Filtrer par nom",
field_name="name",
queryset=RecurrentImport.objects.all().order_by("name__unaccent")
)
class Meta:
model = RecurrentImport
fields = ["name"]

View File

@ -6,8 +6,11 @@
{% load utils_extra %}
{% load rimports_extra %}
{% load cat_extra %}
{% load static %}
{% block entete_header %}
{% css_categories %}
<script src="{% static 'choicejs/choices.min.js' %}"></script>
{% endblock %}
{% block configurer-bouton %}{% endblock %}
@ -31,7 +34,14 @@
<a href="{% url 'add_rimport'%}" role="button">Ajouter {% picto_from_name "plus-circle" %}</a>
</div>
<h1>Importations récurrentes {% if status %}<em>{{ status }}</em>{% endif %}</h1>
{% include "agenda_culturel/rimports-info-inc.html" with all=0 %}
<p>Résumé&nbsp;: {% include "agenda_culturel/rimports-info-inc.html" with all=0 %}</p>
<h2>Filtrer</h2>
<form method="get" class="form django-form">
{{ filter.form.as_div }}<br />
<button type="submit">Filtrer</button>
</form>
</header>
<table role="grid">
@ -87,4 +97,18 @@
{% include "agenda_culturel/side-nav.html" with current="rimports" %}
</div>
<script>
const imports = document.querySelector('#id_name');
const choices_imports = new Choices(imports, {
placeholderValue: 'Chercher un import par son nom',
allowHTML: true,
delimiter: ',',
removeItemButton: true,
shouldSort: false,
}
);
</script>
{% endblock %}

View File

@ -46,6 +46,7 @@ from .filters import (
SimpleSearchEventFilter,
SearchEventFilter,
DuplicatedEventsFilter,
RecurrentImportFilter,
)
from .models import (
@ -1057,33 +1058,35 @@ def cancel_import(request, pk):
@login_required(login_url="/accounts/login/")
@permission_required("agenda_culturel.view_recurrentimport")
def recurrent_imports(request, status=None):
newest = BatchImportation.objects.filter(recurrentImport=OuterRef("pk")).order_by(
"-created_date"
)
events = RecurrentImport.objects.annotate(
last_run_status=Subquery(newest.values("status")[:1])
)
"-created_date")
if status is None:
events_selected = events.all()
else:
events_selected = events.filter(last_run_status=status)
events_selected = events_selected.order_by("-pk")
qs = RecurrentImport.objects.all(). \
annotate(last_run_status=Subquery(newest.values("status")[:1])). \
order_by("-pk")
paginator = Paginator(events_selected, 10)
page = request.GET.get("page")
nb_failed = (events
nb_failed = (qs
.filter(last_run_status=BatchImportation.STATUS.FAILED)
.count())
nb_canceled = (events
nb_canceled = (qs
.filter(last_run_status=BatchImportation.STATUS.CANCELED)
.count())
nb_running = (events
nb_running = (qs
.filter(last_run_status=BatchImportation.STATUS.RUNNING)
.count())
nb_all = events.count()
nb_all = qs.count()
if not status is None:
qs = qs.filter(last_run_status=status)
filter = RecurrentImportFilter(request.GET, queryset=qs)
paginator = PaginatorFilter(filter, 10, request)
page = request.GET.get("page")
try:
response = paginator.page(page)
@ -1093,7 +1096,9 @@ def recurrent_imports(request, status=None):
response = paginator.page(paginator.num_pages)
return render(
request, "agenda_culturel/rimports.html", {"paginator_filter": response, "nb_all": nb_all, "nb_failed": nb_failed, "nb_canceled": nb_canceled, "nb_running": nb_running, "status": status}
request, "agenda_culturel/rimports.html", {"paginator_filter": response,
"filter": filter,
"nb_all": nb_all, "nb_failed": nb_failed, "nb_canceled": nb_canceled, "nb_running": nb_running, "status": status}
)