Skip to content

Commit fd744ac

Browse files
authored
Merge pull request #853 from etchegom/feat/ds-sosp
[feat] Matching DS SOSP
2 parents 95c16ae + e22ef61 commit fd744ac

2 files changed

Lines changed: 54 additions & 1 deletion

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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

recoco/apps/demarches_simplifiees/admin.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from django_json_widget.widgets import JSONEditorWidget
55

66
from .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+
)

0 commit comments

Comments
 (0)