Skip to content

Commit

Permalink
Merge pull request #443 from MTES-MCT/bug/js-errors
Browse files Browse the repository at this point in the history
Variables de configuration manquantes dans le formulaires de haie
  • Loading branch information
pyDez authored Oct 8, 2024
2 parents 4e5acdf + 34f2eda commit bc4ae56
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 55 deletions.
10 changes: 10 additions & 0 deletions envergo/moulinette/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,14 @@ def get_template(self, template_key):

return self.templates.get(template_key, None)

@classmethod
def get_home_template(cls):
"""Return the template to display the result page."""

if not hasattr(cls, "home_template"):
raise AttributeError("No result template found.")
return cls.home_template

def get_result_template(self):
"""Return the template to display the result page."""

Expand Down Expand Up @@ -1194,6 +1202,7 @@ def get_extra_context(cls, request):

class MoulinetteAmenagement(Moulinette):
REGULATIONS = ["loi_sur_leau", "natura2000", "eval_env", "sage"]
home_template = "amenagement/moulinette/home.html"
result_template = "amenagement/moulinette/result.html"
debug_result_template = "amenagement/moulinette/result_debug.html"
result_available_soon = "amenagement/moulinette/result_available_soon.html"
Expand Down Expand Up @@ -1420,6 +1429,7 @@ def get_triage_params(cls):

class MoulinetteHaie(Moulinette):
REGULATIONS = HAIE_REGULATIONS
home_template = "haie/moulinette/home.html"
result_template = "haie/moulinette/result.html"
debug_result_template = "haie/moulinette/result.html"
result_available_soon = "haie/moulinette/result_non_disponible.html"
Expand Down
11 changes: 7 additions & 4 deletions envergo/moulinette/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,9 @@ def log_moulinette_event(self, moulinette, **kwargs):


class MoulinetteHome(MoulinetteMixin, FormView):
template_name = "moulinette/home.html"
def get_template_names(self):
MoulinetteClass = get_moulinette_class_from_site(self.request.site)
return MoulinetteClass.get_home_template()

def get(self, request, *args, **kwargs):
context = self.get_context_data()
Expand Down Expand Up @@ -325,19 +327,20 @@ def get_template_names(self):
is_admin = self.request.user.is_staff

if moulinette is None and triage_form is None:
template_name = "moulinette/home.html"
MoulinetteClass = get_moulinette_class_from_site(self.request.site)
template_name = MoulinetteClass.get_home_template()
elif moulinette is None:
template_name = "haie/moulinette/triage_result.html"
elif is_debug:
template_name = moulinette.get_debug_result_template()
elif is_edit:
template_name = "moulinette/home.html"
template_name = moulinette.get_home_template()
elif not moulinette.has_config():
template_name = moulinette.get_result_non_disponible_template()
elif not (moulinette.is_evaluation_available() or is_admin):
template_name = moulinette.get_result_available_soon_template()
elif moulinette.has_missing_data():
template_name = "moulinette/home.html"
template_name = moulinette.get_home_template()
else:
template_name = moulinette.get_result_template()

Expand Down
2 changes: 1 addition & 1 deletion envergo/pages/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def post(self, request, *args, **kwargs):


class GeometriciansView(MoulinetteMixin, FormView):
template_name = "pages/geometricians.html"
template_name = "amenagement/pages/geometricians.html"

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
{% load static l10n %}

<script>
var ADDRESS_AUTOCOMPLETE_FIELD_NAME = 'address';
var DISPLAY_MARKER = {{ display_marker|yesno:'true,false' }};
var CENTER_MAP = {lng: {{ center_map.0|unlocalize }}, lat: {{ center_map.1|unlocalize }}};
var DEFAULT_ZOOM = {{ default_zoom }};
var LAT_FIELD_ID = 'id_lat';
var LNG_FIELD_ID = 'id_lng';
var IS_MAP_STATIC = {{ is_map_static|yesno:'true,false' }};
var SIMULATION_FORM_ID = "moulinette-form";
var MAP_TYPE = "Form"; // This is only for analytics purpose
</script>

<script defer src="{% static 'leaflet/dist/leaflet.js' %}"></script>
<script defer src="{% static 'leaflet/draw/leaflet.draw.js' %}"></script>
<script defer src="{% static 'js/libs/leaflet-icon-fix.js' %}"></script>
Expand Down
10 changes: 10 additions & 0 deletions envergo/templates/amenagement/moulinette/home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% extends "moulinette/home.html" %}

{% load l10n %}

{% block extra_css %}
{% include 'amenagement/moulinette/_form_styles.html' %}
{% endblock %}
{% block extra_js %}
{% include 'amenagement/moulinette/_form_scripts.html' %}
{% endblock %}
4 changes: 4 additions & 0 deletions envergo/templates/amenagement/moulinette/result.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ <h2>
{% include 'amenagement/moulinette/_actions_banner.html' %}
{% endblock %}

{% block extra_css %}
{% include 'amenagement/moulinette/_form_styles.html' %}
{% endblock %}

{% block extra_js %}
{{ block.super }}
<script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,22 +168,11 @@ <h2 class="fr-h3 fr-mb-2w">EnvErgo, un service…</h2>
{% endblock %}

{% block extra_css %}
{% include 'moulinette/_form_styles.html' %}
{% include 'amenagement/moulinette/_form_styles.html' %}
{% endblock %}

{% block extra_js %}
<script>
var CSRF_TOKEN = '{{ csrf_token }}';
var ADDRESS_AUTOCOMPLETE_FIELD_NAME = 'address';
var DISPLAY_MARKER = {{ display_marker|yesno:'true,false' }};
var CENTER_MAP = {lng: {{ center_map.0|unlocalize }}, lat: {{ center_map.1|unlocalize }}};
var DEFAULT_ZOOM = {{ default_zoom }};
var LAT_FIELD_ID = 'id_lat';
var LNG_FIELD_ID = 'id_lng';
var IS_MAP_STATIC = {{ is_map_static|yesno:'true,false' }};
var SIMULATION_FORM_ID = "moulinette-form";
var MAP_TYPE = "Form"; // This is only for analytics purpose
</script>
{% include 'moulinette/_form_scripts.html' %}
<script>var CSRF_TOKEN = '{{ csrf_token }}';</script>
{% include 'amenagement/moulinette/_form_scripts.html' %}
<script defer src="{% static 'js/libs/data_event_attributes_analytics.js' %}"></script>
{% endblock %}
17 changes: 3 additions & 14 deletions envergo/templates/amenagement/pages/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -169,22 +169,11 @@ <h2>
{% endblock %}

{% block extra_css %}
{% include 'moulinette/_form_styles.html' %}
{% include 'amenagement/moulinette/_form_styles.html' %}
{% endblock %}

{% block extra_js %}
<script>
var CSRF_TOKEN = '{{ csrf_token }}';
var ADDRESS_AUTOCOMPLETE_FIELD_NAME = 'address';
var DISPLAY_MARKER = {{ display_marker|yesno:'true,false' }};
var CENTER_MAP = {lng: {{ center_map.0|unlocalize }}, lat: {{ center_map.1|unlocalize }}};
var DEFAULT_ZOOM = {{ default_zoom }};
var LAT_FIELD_ID = 'id_lat';
var LNG_FIELD_ID = 'id_lng';
var IS_MAP_STATIC = {{ is_map_static|yesno:'true,false' }};
var SIMULATION_FORM_ID = "moulinette-form";
var MAP_TYPE = "Form"; // This is only for analytics purpose
</script>
{% include 'moulinette/_form_scripts.html' %}
<script>var CSRF_TOKEN = '{{ csrf_token }}';</script>
{% include 'amenagement/moulinette/_form_scripts.html' %}
<script defer src="{% static 'js/libs/data_event_attributes_analytics.js' %}"></script>
{% endblock %}
8 changes: 8 additions & 0 deletions envergo/templates/haie/moulinette/home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% extends "moulinette/home.html" %}

{% load static %}

{% block extra_js %}
<script>var SIMULATION_FORM_ID = "moulinette-form";</script>
<script defer src="{% static 'js/libs/form_submit_feedback.js' %}"></script>
{% endblock %}
22 changes: 0 additions & 22 deletions envergo/templates/moulinette/base.html
Original file line number Diff line number Diff line change
@@ -1,25 +1,3 @@
{% extends 'base.html' %}

{% load evaluations static l10n %}

{% block title %}Simulation réglementaire du projet{% endblock %}

{% block extra_css %}
{% include 'moulinette/_form_styles.html' %}
{% endblock %}

{% block extra_js %}
<script>
var ADDRESS_AUTOCOMPLETE_FIELD_NAME = 'address';
var DISPLAY_MARKER = {{ display_marker|yesno:'true,false' }};
var CENTER_MAP = {lng: {{ center_map.0|unlocalize }}, lat: {{ center_map.1|unlocalize }}};
var DEFAULT_ZOOM = {{ default_zoom }};
var LAT_FIELD_ID = 'id_lat';
var LNG_FIELD_ID = 'id_lng';
var IS_MAP_STATIC = {{ is_map_static|yesno:'true,false' }};
var SIMULATION_FORM_ID = "moulinette-form";
var MAP_TYPE = "Form"; // This is only for analytics purpose
</script>
{% include 'moulinette/_form_scripts.html' %}

{% endblock %}

0 comments on commit bc4ae56

Please sign in to comment.