Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(Structures): quelques cleanup #1267

Merged
merged 2 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions lemarche/siaes/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lemarche/templates/dashboard/siae_edit_contact.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{% bootstrap_form_errors form type="all" %}

<div class="row mb-3 mb-lg-5">
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo : retirer le mb-lg-5 pour gagner quelques px

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

en fait c'est dans pas mal de templates :

  • mb-3 mb-lg-5
  • p-3 p-lg-5

<div class="col-12 col-lg-8">
<div class="col-12">
<h3>Contacts affichés sur votre fiche commerciale</h3>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions lemarche/templates/dashboard/siae_edit_offer.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{% csrf_token %}

{% bootstrap_form_errors form type="all" %}

<div class="row mb-3 mb-lg-5">
<div class="col-12 col-lg-8">
<div class="bg-white d-block rounded-lg shadow-lg p-3 p-lg-5">
Expand Down Expand Up @@ -46,7 +46,7 @@
</div>
</div>
</div>

<div class="row mb-3 mb-lg-5">
<div class="col-12 col-lg-8">
<div class="bg-white d-block rounded-lg shadow-lg p-3 p-lg-5">
Expand Down
7 changes: 3 additions & 4 deletions lemarche/templates/dashboard/siae_edit_search.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{% bootstrap_form_errors form type="all" %}

<div class="row mb-3 mb-lg-5">
<div class="col-12 col-lg-8">
<div class="col-12">
<h3>Réferencez efficacement votre structure dans les résultats de recherche</h3>
</div>
</div>
Expand All @@ -33,7 +33,7 @@ <h3>Réferencez efficacement votre structure dans les résultats de recherche</h
</div>
</div>
</div>

<div class="row mb-3 mb-lg-5">
<div class="col-12 col-lg-8">
<div class="bg-white d-block rounded-lg shadow-lg p-3 p-lg-5">
Expand All @@ -57,7 +57,7 @@ <h3>Réferencez efficacement votre structure dans les résultats de recherche</h
</div>
</div>
</div>

<div class="row mb-3 mb-lg-5">
<div class="col-12 col-lg-8">
<div class="bg-white d-block rounded-lg shadow-lg p-3 p-lg-5">
Expand Down Expand Up @@ -88,7 +88,6 @@ <h3>Réferencez efficacement votre structure dans les résultats de recherche</h
</div>
<div class="col-12 col-lg-4"></div>
</div>

</form>
{% endblock %}

Expand Down
11 changes: 11 additions & 0 deletions lemarche/utils/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)

Expand Down
5 changes: 2 additions & 3 deletions lemarche/utils/templatetags/array_choices_display.py
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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":
Expand Down
Loading