diff --git a/lemarche/siaes/models.py b/lemarche/siaes/models.py index b7ceb2dc2..9e1005ec1 100644 --- a/lemarche/siaes/models.py +++ b/lemarche/siaes/models.py @@ -13,7 +13,6 @@ from django.dispatch import receiver from django.urls import reverse from django.utils import timezone -from django.utils.encoding import force_str from django.utils.functional import cached_property from django.utils.text import slugify from phonenumber_field.modelfields import PhoneNumberField @@ -25,7 +24,7 @@ from lemarche.stats.models import Tracker from lemarche.users.models import User from lemarche.utils.constants import DEPARTMENTS_PRETTY, RECALCULATED_FIELD_HELP_TEXT, REGIONS_PRETTY -from lemarche.utils.data import phone_number_display, round_by_base +from lemarche.utils.data import choice_array_to_string, phone_number_display, round_by_base from lemarche.utils.fields import ChoiceArrayField from lemarche.utils.urls import get_object_admin_url from lemarche.utils.validators import validate_naf, validate_post_code, validate_siret @@ -1014,10 +1013,7 @@ def presta_type_display(self) -> str: if self.kind == siae_constants.KIND_AI: return "Mise à disposition du personnel" if self.presta_type: - presta_type_values = [ - force_str(dict(siae_constants.PRESTA_CHOICES).get(key, "")) for key in self.presta_type - ] - return ", ".join(filter(None, presta_type_values)) + return choice_array_to_string(siae_constants.PRESTA_CHOICES, self.presta_type) return "" @property diff --git a/lemarche/templates/dashboard/siae_edit_contact.html b/lemarche/templates/dashboard/siae_edit_contact.html index 3eda6980f..0a81c2e89 100644 --- a/lemarche/templates/dashboard/siae_edit_contact.html +++ b/lemarche/templates/dashboard/siae_edit_contact.html @@ -16,7 +16,7 @@ {% bootstrap_form_errors form type="all" %}
-
+

Contacts affichés sur votre fiche commerciale

diff --git a/lemarche/templates/dashboard/siae_edit_offer.html b/lemarche/templates/dashboard/siae_edit_offer.html index 51dc70f9d..e8a52a1f5 100644 --- a/lemarche/templates/dashboard/siae_edit_offer.html +++ b/lemarche/templates/dashboard/siae_edit_offer.html @@ -10,7 +10,7 @@ {% csrf_token %} {% bootstrap_form_errors form type="all" %} - +
@@ -46,7 +46,7 @@
- +
diff --git a/lemarche/templates/dashboard/siae_edit_search.html b/lemarche/templates/dashboard/siae_edit_search.html index c293e81ba..ddb675524 100644 --- a/lemarche/templates/dashboard/siae_edit_search.html +++ b/lemarche/templates/dashboard/siae_edit_search.html @@ -8,7 +8,7 @@ {% bootstrap_form_errors form type="all" %}
-
+

Réferencez efficacement votre structure dans les résultats de recherche

@@ -33,7 +33,7 @@

Réferencez efficacement votre structure dans les résultats de recherche

- +
@@ -57,7 +57,7 @@

Réferencez efficacement votre structure dans les résultats de recherche

- +
@@ -88,7 +88,6 @@

Réferencez efficacement votre structure dans les résultats de recherche

- {% endblock %} diff --git a/lemarche/utils/data.py b/lemarche/utils/data.py index 95a7dcb37..78f356ed1 100644 --- a/lemarche/utils/data.py +++ b/lemarche/utils/data.py @@ -3,6 +3,7 @@ import phonenumbers from django.core.management import call_command from django.db import connection +from django.utils.encoding import force_str def reset_app_sql_sequences(app_name): @@ -33,6 +34,16 @@ def get_choice(choices, key): return None +def choice_array_to_string(choices, array=[]): + """ + choices = [(1, 'One'), (2, 'Two'), (3, 'Three')] + array = [1, 3] + choice_array_to_string(choices, array) --> 'One, Three' + """ + choice_array_values = [force_str(dict(choices).get(key, "")) for key in array] + return ", ".join(filter(None, choice_array_values)) + + def round_by_base(x, base=5): return base * round(x / base) diff --git a/lemarche/utils/templatetags/array_choices_display.py b/lemarche/utils/templatetags/array_choices_display.py index 910c093c5..a53f6838a 100644 --- a/lemarche/utils/templatetags/array_choices_display.py +++ b/lemarche/utils/templatetags/array_choices_display.py @@ -1,8 +1,8 @@ from django import template -from django.utils.encoding import force_str from django.utils.html import mark_safe from lemarche.siaes import constants as siae_constants +from lemarche.utils.data import choice_array_to_string register = template.Library() @@ -22,8 +22,7 @@ def array_choices_display(obj, field, output_format="string"): except: # noqa keys = getattr(obj, field, []) - values = [force_str(choices_dict.get(key, "")) for key in (keys or [])] - values = filter(None, values) + values = choice_array_to_string(choices_dict, keys) # output format if output_format == "list":