From 4da5add25ab9e1172900a022456e0980cb83a8dc Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Wed, 26 Jun 2019 09:57:16 -0700 Subject: [PATCH] Move `choices_length` to shared folder --- gestioncof/models.py | 2 +- kfet/models.py | 6 +----- petitscours/models.py | 7 +------ shared/utils.py | 5 +++++ 4 files changed, 8 insertions(+), 12 deletions(-) create mode 100644 shared/utils.py diff --git a/gestioncof/models.py b/gestioncof/models.py index e4975fc4..c2c71660 100644 --- a/gestioncof/models.py +++ b/gestioncof/models.py @@ -5,7 +5,7 @@ from django.dispatch import receiver from django.utils.translation import ugettext_lazy as _ from bda.models import Spectacle -from petitscours.models import choices_length +from shared.utils import choices_length TYPE_COMMENT_FIELD = (("text", _("Texte long")), ("char", _("Texte court"))) diff --git a/kfet/models.py b/kfet/models.py index 5d8ad3cb..a2d776b9 100644 --- a/kfet/models.py +++ b/kfet/models.py @@ -1,6 +1,5 @@ import re from datetime import date -from functools import reduce from django.contrib.auth.models import User from django.core.validators import RegexValidator @@ -11,6 +10,7 @@ from django.utils import timezone from django.utils.translation import ugettext_lazy as _ from gestioncof.models import CofProfile +from shared.utils import choices_length from . import KFET_DELETED_TRIGRAMME from .auth import KFET_GENERIC_TRIGRAMME @@ -19,10 +19,6 @@ from .config import kfet_config from .utils import to_ukf -def choices_length(choices): - return reduce(lambda m, choice: max(m, len(choice[0])), choices, 0) - - def default_promo(): now = date.today() return now.month <= 8 and now.year - 1 or now.year diff --git a/petitscours/models.py b/petitscours/models.py index cc518675..27b5e931 100644 --- a/petitscours/models.py +++ b/petitscours/models.py @@ -1,15 +1,10 @@ -from functools import reduce - from django.contrib.auth.models import User from django.db import models from django.db.models import Min from django.utils.functional import cached_property from django.utils.translation import ugettext_lazy as _ - -def choices_length(choices): - return reduce(lambda m, choice: max(m, len(choice[0])), choices, 0) - +from shared.utils import choices_length LEVELS_CHOICES = ( ("college", _("Collège")), diff --git a/shared/utils.py b/shared/utils.py new file mode 100644 index 00000000..ea4aa0dd --- /dev/null +++ b/shared/utils.py @@ -0,0 +1,5 @@ +from functools import reduce + + +def choices_length(choices): + return reduce(lambda m, choice: max(m, len(choice[0])), choices, 0)