Move choices_length to shared folder

This commit is contained in:
Ludovic Stephan 2019-06-26 09:57:16 -07:00 committed by Martin Pépin
parent 730611039b
commit 4da5add25a
No known key found for this signature in database
GPG key ID: E7520278B1774448
4 changed files with 8 additions and 12 deletions

View file

@ -5,7 +5,7 @@ from django.dispatch import receiver
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from bda.models import Spectacle 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"))) TYPE_COMMENT_FIELD = (("text", _("Texte long")), ("char", _("Texte court")))

View file

@ -1,6 +1,5 @@
import re import re
from datetime import date from datetime import date
from functools import reduce
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core.validators import RegexValidator from django.core.validators import RegexValidator
@ -11,6 +10,7 @@ from django.utils import timezone
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from gestioncof.models import CofProfile from gestioncof.models import CofProfile
from shared.utils import choices_length
from . import KFET_DELETED_TRIGRAMME from . import KFET_DELETED_TRIGRAMME
from .auth import KFET_GENERIC_TRIGRAMME from .auth import KFET_GENERIC_TRIGRAMME
@ -19,10 +19,6 @@ from .config import kfet_config
from .utils import to_ukf from .utils import to_ukf
def choices_length(choices):
return reduce(lambda m, choice: max(m, len(choice[0])), choices, 0)
def default_promo(): def default_promo():
now = date.today() now = date.today()
return now.month <= 8 and now.year - 1 or now.year return now.month <= 8 and now.year - 1 or now.year

View file

@ -1,15 +1,10 @@
from functools import reduce
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.db import models from django.db import models
from django.db.models import Min from django.db.models import Min
from django.utils.functional import cached_property from django.utils.functional import cached_property
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from shared.utils import choices_length
def choices_length(choices):
return reduce(lambda m, choice: max(m, len(choice[0])), choices, 0)
LEVELS_CHOICES = ( LEVELS_CHOICES = (
("college", _("Collège")), ("college", _("Collège")),

5
shared/utils.py Normal file
View file

@ -0,0 +1,5 @@
from functools import reduce
def choices_length(choices):
return reduce(lambda m, choice: max(m, len(choice[0])), choices, 0)