Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
69c5c93
Add 3 mores status to ProcedureStatusChoices
pitiscarf Oct 21, 2026
39944c7
Handle new status in front
pitiscarf Oct 21, 2026
17501a1
add Event.created_by field
pitiscarf Nov 3, 2026
9b541dc
Fill Event.created_by in nuxt
pitiscarf Nov 3, 2026
c1cbee5
event_type by default in EventFactory
pitiscarf Nov 10, 2026
ba4a478
Add end_of_day date utility function
pitiscarf Nov 19, 2026
bf30e83
Compute procedure status taking event types impact into account
pitiscarf Oct 14, 2026
9cee5c6
Add management command update_procedure_status
pitiscarf Oct 15, 2026
b47cc43
Add /api-internes/procedures/<id>/synchronize-status endpoint
pitiscarf Oct 19, 2026
c26a46b
Use synchronize-status in nuxt side
pitiscarf Oct 19, 2026
060f8b4
Improve procedure view with impactful events in admin
pitiscarf Oct 27, 2026
c2aca67
Update opposability logic in CommuneProcedure
pitiscarf Oct 28, 2026
d2724f9
Add command update_commune_procedure_opposability
pitiscarf Oct 28, 2026
e63ac9e
synchronize opposability in synchronize-status
pitiscarf Oct 29, 2026
f6059c1
Synchronize status & opposability every day
pitiscarf Nov 18, 2026
d57757e
Add SYSTEM_PROFILE_IDS environment variable
pitiscarf Nov 4, 2026
9ab2f8f
Create command create_system_events_caduc
pitiscarf Nov 19, 2026
2f00be8
Create command create_system_events_opposable
pitiscarf Nov 4, 2026
2e0cec0
Add tally popup
pitiscarf Nov 24, 2026
be6b490
Remove unknown function
celine-m-s Nov 19, 2026
039d897
Django tests: stop using Collectivite.code_insee_unique
celine-m-s Nov 20, 2026
080ec2e
Django: link CollectiviteProcedure missing communes
celine-m-s Nov 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions django/bin/clock.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,12 @@ while true; do
echo "☕ Il est ${current_time} ! C'est l'heure de la sauvegarde !"
/usr/bin/bash scripts/backup_database.sh "${DATABASE_URL}"
fi
if [[ "$current_time" == "03:03" ]]; then
date_pivot=$(date -I)
echo "Synchronize procedure status and opposability using events until $date_pivot"
django-admin update_event_date_by_impact --wet-run
django-admin synchronize_procedure_status --date_pivot="$date_pivot" --wet-run
django-admin synchronize_commune_procedure_opposability --date_pivot="$date_pivot" --wet-run
fi
sleep 1m
done
15 changes: 10 additions & 5 deletions django/docurba/core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,12 @@ class EventsInline(admin.TabularInline):
readonly_fields = (
"id",
"type",
"event_type",
"date_evenement",
"is_valid",
"visibility",
"is_valid",
"from_sudocuh",
"archived_at",
)
fields = [
*readonly_fields,
Expand All @@ -163,9 +165,9 @@ class EventsInline(admin.TabularInline):

def get_queryset(self, request) -> models.QuerySet:
queryset = super().get_queryset(request)
return queryset.select_related(
"procedure", "procedure__collectivite_porteuse"
).prefetch_related("procedure__perimetre")
return queryset.select_related("event_type").order_by(
"-date_evenement",
)

def has_add_permission(self, *args: list, **kwargs: dict) -> bool:
return False
Expand Down Expand Up @@ -441,7 +443,7 @@ class EventAdmin(admin.ModelAdmin):
raw_id_fields = ("event_type", "procedure")
list_display = (
"id",
"event_type__name",
"event_type",
"type",
"date_evenement",
"is_valid",
Expand All @@ -456,6 +458,9 @@ class EventAdmin(admin.ModelAdmin):
"procedure__id",
"profile__email",
"archived_by__email",
"event_type__name",
"event_type__sudocuh_name",
"event_type__sudocuh_code",
)
autocomplete_fields = (
"profile",
Expand Down
3 changes: 3 additions & 0 deletions django/docurba/core/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ class ProcedureStatusChoices(models.TextChoices):
CADUC = "caduc", "Caduc"
ABANDON = "abandon", "Abandon"
OPPOSABLE = "opposable", "Opposable"
EN_PROJET = "en projet", "En projet"
APPROUVE = "approuve", "Approuvé"
ABROGE = "abroge", "Abrogé"


class ProcedureType(models.TextChoices):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import csv

from django.core.management.base import BaseCommand
from django.db import connection

DIFF_QUERY = """
WITH impactful_events AS (
SELECT DISTINCT ON (e.procedure_id) e.procedure_id, e.project_id, e.date_iso, et.document_type AS document_type, et.impact as impact
FROM doc_frise_events e
JOIN core_eventtype et ON e.event_type_id = et.id
JOIN procedures p ON p.id = e.procedure_id
WHERE p.secondary_procedure_of IS NULL
AND p.base_doc_type IN ('POS', 'SD')
AND e.is_valid IS TRUE
AND e.archived_at IS NULL
AND e.date_iso IS NOT NULL
AND et.impact != ''
ORDER BY e.procedure_id, e.date_iso DESC
), inserts AS (
SELECT e.procedure_id, e.project_id, e.date_iso + '1 hour'::INTERVAL AS date_iso, et.id AS event_type_id, et.name AS "type", et.sudocuh_code AS code,
'private' AS visibility,
TRUE AS is_valid,
%(profile_id)s::uuid AS created_by_id,
%(profile_id)s::uuid AS profile_id,
%(description)s AS description
FROM impactful_events e
JOIN core_eventtype et ON e.document_type = et.document_type AND et.name = 'Caducité'
WHERE e.impact != 'caduc'
)
"""

LIST_QUERY = (
DIFF_QUERY
+ """
SELECT * FROM inserts
"""
)

UPDATE_QUERY = (
DIFF_QUERY
+ """
INSERT INTO doc_frise_events
(procedure_id, project_id, date_iso, event_type_id, type, code, visibility, is_valid, created_by_id, profile_id, description)
SELECT * FROM inserts
RETURNING procedure_id, project_id, date_iso, event_type_id, type, code, visibility, is_valid, created_by_id, profile_id, description
"""
)

DESCRIPTION = "Afin de mieux répondre à vos besoins et aux règles métier, nous faisons évoluer les règles de statut : cet événement a été ajouté pour rendre la procédure caduque. Pensez à renseigner la date réelle de la caducité et à changer la visibilité de l'événement. Si vous avez la moindre question, écrivez-nous à: contact@docurba.beta.gouv.fr"


class Command(BaseCommand):
help = "Add 'Caduc' system event to existing SD & POS procedures"

def add_arguments(self, parser: str) -> None:
parser.add_argument(
"profile_id",
help="ID of system profile owning the new events",
)
parser.add_argument(
"--wet-run",
dest="wet_run",
action="store_true",
help="Persists changes in database",
)

def handle(
self,
*args: list, # noqa: ARG002
profile_id: str,
wet_run: bool,
**options: dict, # noqa: ARG002
) -> None:
writer = csv.writer(self.stdout, lineterminator="\n")
writer.writerow(
[
"procedure_id",
"project_id",
"date_iso",
"event_type_id",
"type",
"code",
"visibility",
"is_valid",
"created_by_id",
"profile_id",
"description",
]
)
with connection.cursor() as cursor:
cursor.execute(
UPDATE_QUERY if wet_run else LIST_QUERY,
{"profile_id": profile_id, "description": DESCRIPTION},
)
for row in cursor.fetchall():
writer.writerow(row)
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import csv

from django.core.management.base import BaseCommand
from django.db import connection

DIFF_QUERY = """
WITH impactful_events AS (
SELECT DISTINCT ON (e.procedure_id) e.procedure_id, e.project_id, e.date_iso, et.document_type AS document_type, et.impact as impact
FROM doc_frise_events e
JOIN core_eventtype et ON e.event_type_id = et.id
JOIN procedures p ON p.id = e.procedure_id
WHERE p.secondary_procedure_of IS NULL
AND e.is_valid IS TRUE
AND e.archived_at IS NULL
AND e.date_iso IS NOT NULL
AND et.impact != ''
ORDER BY e.procedure_id, e.date_iso DESC
), inserts AS (
SELECT e.procedure_id, e.project_id, e.date_iso + '1 hour'::INTERVAL AS date_iso, et.id AS event_type_id, et.name AS "type", et.sudocuh_code AS code,
'private' AS visibility,
TRUE AS is_valid,
%(profile_id)s::uuid AS created_by_id,
%(profile_id)s::uuid AS profile_id,
%(description)s AS description
FROM impactful_events e
JOIN core_eventtype et ON e.document_type = et.document_type AND et.name = 'Caractère exécutoire'
WHERE e.impact = 'approuve'
)
"""

LIST_QUERY = (
DIFF_QUERY
+ """
SELECT * FROM inserts
"""
)

UPDATE_QUERY = (
DIFF_QUERY
+ """
INSERT INTO doc_frise_events
(procedure_id, project_id, date_iso, event_type_id, type, code, visibility, is_valid, created_by_id, profile_id, description)
SELECT * FROM inserts
RETURNING procedure_id, project_id, date_iso, event_type_id, type, code, visibility, is_valid, created_by_id, profile_id, description
"""
)

DESCRIPTION = "Afin de mieux répondre à vos besoins et aux règles métier, nous faisons évoluer les règles de statut : cet événement a été ajouté pour rendre la procédure opposable. Pensez à renseigner la date réelle du caractère exécutoire et à changer la visibilité de l'événement. Si vous avez la moindre question, écrivez-nous à: contact@docurba.beta.gouv.fr"


class Command(BaseCommand):
help = "Add 'Caractère exécutoire' system event to keep existing procedures 'opposable' since the addition of status 'approuve'"

def add_arguments(self, parser: str) -> None:
parser.add_argument(
"profile_id",
help="ID of system profile owning the new events",
)
parser.add_argument(
"--wet-run",
dest="wet_run",
action="store_true",
help="Persists changes in database",
)

def handle(
self,
*args: list, # noqa: ARG002
profile_id: str,
wet_run: bool,
**options: dict, # noqa: ARG002
) -> None:
writer = csv.writer(self.stdout, lineterminator="\n")
writer.writerow(
[
"procedure_id",
"project_id",
"date_iso",
"event_type_id",
"type",
"code",
"visibility",
"is_valid",
"created_by_id",
"profile_id",
"description",
]
)
with connection.cursor() as cursor:
cursor.execute(
UPDATE_QUERY if wet_run else LIST_QUERY,
{"profile_id": profile_id, "description": DESCRIPTION},
)
for row in cursor.fetchall():
writer.writerow(row)

This file was deleted.

Loading