Skip to content

Commit

Permalink
Début de la refactorisation de l'interface dags/validations
Browse files Browse the repository at this point in the history
  • Loading branch information
kolok committed Jan 6, 2025
1 parent f6c4795 commit 7b9e138
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 3 deletions.
13 changes: 10 additions & 3 deletions jinja2/qfdmo/dags_validations.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,19 @@ <h1>Validations des «DAGs»</h1>
<p>
Cette page permet de valider les données des «DAGs».
</p>

<form>
{% if messages %}
<ul class="messages">
{% for message in messages %}
<li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
{% endfor %}
</ul>
{% endif %}
<form method='POST'>
{{ csrf_input }}
{{ form }}
{{ form.dagrun.value() }}
<div class="fr-my-3w">
<button type="submit" class="fr-btn" method='GET'>Afficher le résumé du dag</button>
<button type="submit" class="fr-btn" method='POST' name='search' value=1>Afficher le résumé du dag</button>
</div>

{% if dagrun_instance %}
Expand Down
48 changes: 48 additions & 0 deletions qfdmo/views/dags.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging

from django.contrib import messages
from django.contrib.auth.mixins import LoginRequiredMixin
from django.core.paginator import Paginator
from django.shortcuts import render
Expand All @@ -21,12 +22,59 @@ class DagsValidation(IsStaffMixin, FormView):
template_name = "qfdmo/dags_validations.html"
success_url = "/dags/validations"

def form_valid(self, form):
# MANAGE search and display dagrun details
if self.request.POST.get("search"):
dagrun = form.cleaned_data["dagrun"]
context = {"form": form}
context["dagrun_instance"] = dagrun
dagrun_lines = dagrun.dagrunchanges.all().order_by("?")[:100]
context["dagrun_lines"] = dagrun_lines
return render(self.request, "qfdmo/dags_validations.html", context)

# ELSE: update the status of the dagrun and its dagrunlines
dagrun = form.cleaned_data["dagrun"]
new_status = (
DagRunStatus.TO_INSERT.value
if self.request.POST.get("dag_valid") == "1"
else DagRunStatus.REJECTED.value
)

# FIXME: I am not sure we need the filter here
dagrun.dagrunchanges.filter(status=DagRunStatus.TO_VALIDATE.value).update(
status=new_status
)
dagrun.status = new_status
dagrun.save()
messages.success(
self.request,
f"La cohorte {dagrun} a été mise à jour avec le statut {new_status}",
)

return super().form_valid(form)

def form_invalid(self, form):
messages.error(self.request, "Il y a des erreurs dans le formulaire.")
return super().form_invalid(form)

# def form_valid(self, form):
# if self.request.POST.get("search"):
# messages.add_message(self.request, messages.INFO, "Form Valid.")
# return super().form_valid(form)


class DagsValidation1(IsStaffMixin, FormView):
form_class = DagsForm
template_name = "qfdmo/dags_validations.html"
success_url = "/dags/validations"

def get_initial(self):
initial = super().get_initial()
initial["dagrun"] = self.request.GET.get("dagrun")
return initial

def post(self, request, *args, **kwargs):

dag_valid = request.POST.get("dag_valid")
if dag_valid in ["1", "0"]:
return self.form_valid(self.get_form())
Expand Down

0 comments on commit 7b9e138

Please sign in to comment.