File tree Expand file tree Collapse file tree
recoco/apps/demarches_simplifiees Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ from typing import Any
2+
3+ from recoco .apps .projects .models import Project
4+
5+
6+ def make (project : Project ) -> dict [str , Any ]:
7+ d = {
8+ "champ_Q2hhbXAtMzUyMTg1Mg" : project .name ,
9+ }
10+
11+ if owner := project .owner :
12+ d .update (
13+ {
14+ "identite_prenom" : owner .first_name ,
15+ "identite_nom" : owner .last_name ,
16+ "champ_Q2hhbXAtMzUyMTg0Ng" : f"{ owner .last_name } { owner .first_name } " ,
17+ "champ_Q2hhbXAtMzUyMTg0OA" : owner .email ,
18+ "champ_Q2hhbXAtMzUyMTg0Nw" : owner .profile .organization_position ,
19+ "champ_Q2hhbXAtMzUyMTg0OQ" : owner .profile .phone_no .as_international ,
20+ }
21+ )
22+
23+ if commune := project .commune :
24+ d .update (
25+ {
26+ "champ_Q2hhbXAtMzUzNTIxMA" : commune .insee ,
27+ "champ_Q2hhbXAtMzUyMDc0NA" : [commune .postal ],
28+ "champ_Q2hhbXAtMzUyMDc3OA" : commune .department .code ,
29+ "champ_Q2hhbXAtMzUyMDc4MA" : commune .department .region .code ,
30+ }
31+ )
32+
33+ return d
Original file line number Diff line number Diff line change 44from django_json_widget .widgets import JSONEditorWidget
55
66from .models import DSFolder , DSResource
7- from .tasks import load_ds_resource_schema
7+ from .tasks import load_ds_resource_schema , update_or_create_ds_folder
88
99
1010@admin .register (DSResource )
@@ -58,3 +58,23 @@ class DSFolderAdmin(admin.ModelAdmin):
5858 formfield_overrides = {
5959 JSONField : {"widget" : JSONEditorWidget },
6060 }
61+
62+ actions = ("update_matching" ,)
63+
64+ @admin .action (description = "Mettre à jour le matching projet / démarche simplifiée" )
65+ def update_matching (self , request : HttpRequest , queryset : QuerySet [DSResource ]):
66+ for ds_folder in queryset :
67+ if not ds_folder .recommendation_id :
68+ self .message_user (
69+ request ,
70+ f"Le dossier '{ ds_folder .dossier_id } ' n'a pas de recommandation liée." ,
71+ messages .ERROR ,
72+ )
73+ continue
74+
75+ update_or_create_ds_folder .delay (ds_folder .recommendation_id )
76+ self .message_user (
77+ request ,
78+ f"Tâche déclenchée pour le dossier '{ ds_folder .dossier_id } '." ,
79+ messages .SUCCESS ,
80+ )
You can’t perform that action at this time.
0 commit comments