Skip to content

Commit

Permalink
Merge pull request #853 from etchegom/feat/ds-sosp
Browse files Browse the repository at this point in the history
[feat] Matching DS SOSP
  • Loading branch information
glibersat authored Dec 3, 2024
2 parents 95c16ae + e22ef61 commit fd744ac
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
33 changes: 33 additions & 0 deletions recoco/apps/demarches_simplifiees/adapters/79838.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from typing import Any

from recoco.apps.projects.models import Project


def make(project: Project) -> dict[str, Any]:
d = {
"champ_Q2hhbXAtMzUyMTg1Mg": project.name,
}

if owner := project.owner:
d.update(
{
"identite_prenom": owner.first_name,
"identite_nom": owner.last_name,
"champ_Q2hhbXAtMzUyMTg0Ng": f"{owner.last_name} {owner.first_name}",
"champ_Q2hhbXAtMzUyMTg0OA": owner.email,
"champ_Q2hhbXAtMzUyMTg0Nw": owner.profile.organization_position,
"champ_Q2hhbXAtMzUyMTg0OQ": owner.profile.phone_no.as_international,
}
)

if commune := project.commune:
d.update(
{
"champ_Q2hhbXAtMzUzNTIxMA": commune.insee,
"champ_Q2hhbXAtMzUyMDc0NA": [commune.postal],
"champ_Q2hhbXAtMzUyMDc3OA": commune.department.code,
"champ_Q2hhbXAtMzUyMDc4MA": commune.department.region.code,
}
)

return d
22 changes: 21 additions & 1 deletion recoco/apps/demarches_simplifiees/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django_json_widget.widgets import JSONEditorWidget

from .models import DSFolder, DSResource
from .tasks import load_ds_resource_schema
from .tasks import load_ds_resource_schema, update_or_create_ds_folder


@admin.register(DSResource)
Expand Down Expand Up @@ -58,3 +58,23 @@ class DSFolderAdmin(admin.ModelAdmin):
formfield_overrides = {
JSONField: {"widget": JSONEditorWidget},
}

actions = ("update_matching",)

@admin.action(description="Mettre à jour le matching projet / démarche simplifiée")
def update_matching(self, request: HttpRequest, queryset: QuerySet[DSResource]):
for ds_folder in queryset:
if not ds_folder.recommendation_id:
self.message_user(
request,
f"Le dossier '{ds_folder.dossier_id}' n'a pas de recommandation liée.",
messages.ERROR,
)
continue

update_or_create_ds_folder.delay(ds_folder.recommendation_id)
self.message_user(
request,
f"Tâche déclenchée pour le dossier '{ds_folder.dossier_id}'.",
messages.SUCCESS,
)

0 comments on commit fd744ac

Please sign in to comment.