Skip to content

Commit

Permalink
push project url instead of moulinette
Browse files Browse the repository at this point in the history
  • Loading branch information
pyDez committed Nov 18, 2024
1 parent f045daf commit 3952524
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
8 changes: 6 additions & 2 deletions envergo/moulinette/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,8 @@ class ConfigHaie(ConfigBase):
blank=True,
null=True,
help_text="Vous trouverez ce numéro en haut à droite de la carte de votre démarche dans la liste suivante : "
"https://www.demarches-simplifiees.fr/admin/procedures",
'<a href="https://www.demarches-simplifiees.fr/admin/procedures" target="_blank" rel="noopener">'
"https://www.demarches-simplifiees.fr/admin/procedures</a>",
)

demarche_simplifiee_pre_fill_config = models.JSONField(
Expand Down Expand Up @@ -864,7 +865,10 @@ def get_demarche_simplifiee_value_sources(cls):
* the results of the regulations
"""
moulinette_instance = MoulinetteHaie({}, {})
identified_sources = {("moulinette_url", "Url de la simulation")}
identified_sources = {
("moulinette_url", "Url de la simulation"),
("project_url", "Url du projet de pétition"),
}
main_form_fields = {
(key, field.label)
for key, field in MoulinetteHaie.main_form_class.base_fields.items()
Expand Down
17 changes: 12 additions & 5 deletions envergo/petitions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def pre_fill_demarche_simplifiee(self, project):
continue

body[f"champ_{field['id']}"] = self.get_value_from_source(
moulinette_url,
project,
moulinette,
field["value"],
field.get("mapping", {}),
Expand All @@ -124,7 +124,7 @@ def pre_fill_demarche_simplifiee(self, project):
return redirect_url

def get_value_from_source(
self, moulinette_url, moulinette, source, mapping, config
self, petition_project, moulinette, source, mapping, config
):
"""Get the value to pre-fill a dossier on demarches-simplifiees.fr from a source.
Expand All @@ -133,7 +133,14 @@ def get_value_from_source(
Then it will map the value if a mapping is provided.
"""
if source == "moulinette_url":
value = moulinette_url
value = petition_project.moulinette_url
elif source == "project_url":
value = self.request.build_absolute_uri(
reverse(
"petition_project",
kwargs={"reference": petition_project.reference},
)
)
elif source.endswith(".result"):
regulation_slug = source[:-7]
regulation_result = getattr(moulinette, regulation_slug, None)
Expand All @@ -142,7 +149,7 @@ def get_value_from_source(
"Unable to get the regulation result to pre-fill a démarche simplifiée",
extra={
"regulation_slug": regulation_slug,
"moulinette_url": moulinette_url,
"moulinette_url": petition_project.moulinette_url,
"haie config": config.id,
},
)
Expand All @@ -160,7 +167,7 @@ def get_value_from_source(
extra={
"source": source,
"mapping": mapping,
"moulinette_url": moulinette_url,
"moulinette_url": petition_project.moulinette_url,
"haie config": config.id,
},
)
Expand Down

0 comments on commit 3952524

Please sign in to comment.