diff --git a/api/templatetags/diagnostic_extras.py b/api/templatetags/diagnostic_extras.py index 17c841f0f..e29490ff8 100644 --- a/api/templatetags/diagnostic_extras.py +++ b/api/templatetags/diagnostic_extras.py @@ -8,7 +8,7 @@ def menu_frequency(key): if not key: return None try: - return Diagnostic.MenuFrequency[key].label + return Diagnostic.VegetarianMenuFrequency[key].label except Exception: return None @@ -18,6 +18,6 @@ def menu_type(key): if not key: return None try: - return Diagnostic.MenuType[key].label + return Diagnostic.VegetarianMenuType[key].label except Exception: return None diff --git a/api/tests/test_canteen_statistics.py b/api/tests/test_canteen_statistics.py index 09295810b..c696a1c6b 100644 --- a/api/tests/test_canteen_statistics.py +++ b/api/tests/test_canteen_statistics.py @@ -53,7 +53,7 @@ def test_canteen_statistics(self): "value_egalim_others_ht": None, "has_waste_diagnostic": False, "waste_actions": [], - "vegetarian_weekly_recurrence": Diagnostic.MenuFrequency.DAILY, + "vegetarian_weekly_recurrence": Diagnostic.VegetarianMenuFrequency.DAILY, "plastic_tableware_substituted": False, "communicates_on_food_quality": False, }, @@ -64,7 +64,7 @@ def test_canteen_statistics(self): "value_sustainable_ht": 0, "value_externality_performance_ht": 0, "value_egalim_others_ht": 0, - "vegetarian_weekly_recurrence": Diagnostic.MenuFrequency.DAILY, + "vegetarian_weekly_recurrence": Diagnostic.VegetarianMenuFrequency.DAILY, }, ], }, @@ -84,7 +84,7 @@ def test_canteen_statistics(self): "has_waste_diagnostic": True, "waste_actions": ["action1", "action2"], "has_donation_agreement": True, - "vegetarian_weekly_recurrence": Diagnostic.MenuFrequency.LOW, + "vegetarian_weekly_recurrence": Diagnostic.VegetarianMenuFrequency.LOW, "cooking_plastic_substituted": True, "serving_plastic_substituted": True, "plastic_bottles_substituted": True, @@ -409,23 +409,27 @@ def test_diversification_badge_earned(self): high_canteen.sectors.remove(primaire) high_canteen.sectors.remove(secondaire) DiagnosticFactory.create( - canteen=high_canteen, vegetarian_weekly_recurrence=Diagnostic.MenuFrequency.HIGH.value + canteen=high_canteen, vegetarian_weekly_recurrence=Diagnostic.VegetarianMenuFrequency.HIGH.value ) low_canteen = CanteenFactory.create() low_canteen.sectors.add(primaire) - DiagnosticFactory.create(canteen=low_canteen, vegetarian_weekly_recurrence=Diagnostic.MenuFrequency.LOW.value) + DiagnosticFactory.create( + canteen=low_canteen, vegetarian_weekly_recurrence=Diagnostic.VegetarianMenuFrequency.LOW.value + ) # --- canteens which earn diversification badge: daily_vege = CanteenFactory.create() daily_vege.sectors.remove(primaire) daily_vege.sectors.remove(secondaire) - DiagnosticFactory.create(canteen=daily_vege, vegetarian_weekly_recurrence=Diagnostic.MenuFrequency.DAILY.value) + DiagnosticFactory.create( + canteen=daily_vege, vegetarian_weekly_recurrence=Diagnostic.VegetarianMenuFrequency.DAILY.value + ) scolaire_mid_vege = CanteenFactory.create() scolaire_mid_vege.sectors.add(secondaire) DiagnosticFactory.create( - canteen=scolaire_mid_vege, vegetarian_weekly_recurrence=Diagnostic.MenuFrequency.MID.value + canteen=scolaire_mid_vege, vegetarian_weekly_recurrence=Diagnostic.VegetarianMenuFrequency.MID.value ) badges = badges_for_queryset(Diagnostic.objects.all()) diff --git a/api/views/canteen.py b/api/views/canteen.py index 106a1c8b2..cc42ad617 100644 --- a/api/views/canteen.py +++ b/api/views/canteen.py @@ -828,7 +828,7 @@ def badges_for_queryset(diagnostic_year_queryset): diversification_badge_query = diagnostic_year_queryset.exclude(vegetarian_weekly_recurrence__isnull=True) diversification_badge_query = diversification_badge_query.exclude(vegetarian_weekly_recurrence="") diversification_badge_query = diversification_badge_query.exclude( - vegetarian_weekly_recurrence=Diagnostic.MenuFrequency.LOW + vegetarian_weekly_recurrence=Diagnostic.VegetarianMenuFrequency.LOW ) scolaire_sectors = Sector.objects.filter(category="education") if scolaire_sectors.count(): @@ -836,11 +836,11 @@ def badges_for_queryset(diagnostic_year_queryset): Q( canteen__sectors__in=scolaire_sectors, vegetarian_weekly_recurrence__in=[ - Diagnostic.MenuFrequency.MID, - Diagnostic.MenuFrequency.HIGH, + Diagnostic.VegetarianMenuFrequency.MID, + Diagnostic.VegetarianMenuFrequency.HIGH, ], ) - | Q(vegetarian_weekly_recurrence=Diagnostic.MenuFrequency.DAILY) + | Q(vegetarian_weekly_recurrence=Diagnostic.VegetarianMenuFrequency.DAILY) ).distinct() badge_querysets["diversification"] = diversification_badge_query diff --git a/api/views/teledeclaration.py b/api/views/teledeclaration.py index 8d00197fc..414775450 100644 --- a/api/views/teledeclaration.py +++ b/api/views/teledeclaration.py @@ -319,12 +319,12 @@ def _get_teledeclaration_override_data(teledeclaration_data): for x in (teledeclaration_data.get("diversification_plan_actions") or []) ], "vegetarian_weekly_recurrence": ( - Diagnostic.MenuFrequency(teledeclaration_data["vegetarian_weekly_recurrence"]).label + Diagnostic.VegetarianMenuFrequency(teledeclaration_data["vegetarian_weekly_recurrence"]).label if teledeclaration_data.get("vegetarian_weekly_recurrence") else None ), "vegetarian_menu_type": ( - Diagnostic.MenuType(teledeclaration_data["vegetarian_menu_type"]).label + Diagnostic.VegetarianMenuType(teledeclaration_data["vegetarian_menu_type"]).label if teledeclaration_data.get("vegetarian_menu_type") else None ), diff --git a/data/factories/diagnostic.py b/data/factories/diagnostic.py index 752c35606..37ff713f7 100644 --- a/data/factories/diagnostic.py +++ b/data/factories/diagnostic.py @@ -34,8 +34,8 @@ class Meta: has_donation_agreement = factory.Faker("boolean") has_diversification_plan = factory.Faker("boolean") - vegetarian_weekly_recurrence = fuzzy.FuzzyChoice(list(Diagnostic.MenuFrequency)) - vegetarian_menu_type = fuzzy.FuzzyChoice(list(Diagnostic.MenuType)) + vegetarian_weekly_recurrence = fuzzy.FuzzyChoice(list(Diagnostic.VegetarianMenuFrequency)) + vegetarian_menu_type = fuzzy.FuzzyChoice(list(Diagnostic.VegetarianMenuType)) cooking_plastic_substituted = factory.Faker("boolean") serving_plastic_substituted = factory.Faker("boolean") @@ -72,8 +72,8 @@ class Meta: has_donation_agreement = factory.Faker("boolean") has_diversification_plan = factory.Faker("boolean") - vegetarian_weekly_recurrence = fuzzy.FuzzyChoice(list(Diagnostic.MenuFrequency)) - vegetarian_menu_type = fuzzy.FuzzyChoice(list(Diagnostic.MenuType)) + vegetarian_weekly_recurrence = fuzzy.FuzzyChoice(list(Diagnostic.VegetarianMenuFrequency)) + vegetarian_menu_type = fuzzy.FuzzyChoice(list(Diagnostic.VegetarianMenuType)) cooking_plastic_substituted = factory.Faker("boolean") serving_plastic_substituted = factory.Faker("boolean") diff --git a/data/models/diagnostic.py b/data/models/diagnostic.py index d2e3d1154..f4dd23b63 100644 --- a/data/models/diagnostic.py +++ b/data/models/diagnostic.py @@ -71,14 +71,14 @@ class DiagnosticType(models.TextChoices): class CreationSource(models.TextChoices): TUNNEL = "TUNNEL", "Tunnel" - class MenuFrequency(models.TextChoices): + class VegetarianMenuFrequency(models.TextChoices): NEVER = "NEVER", "Jamais" LOW = "LOW", "Moins d'une fois par semaine" MID = "MID", "Une fois par semaine" HIGH = "HIGH", "Plus d'une fois par semaine" DAILY = "DAILY", "De façon quotidienne" - class MenuType(models.TextChoices): + class VegetarianMenuType(models.TextChoices): UNIQUE = "UNIQUE", "Un menu végétarien en plat unique, sans choix" SEVERAL = ( "SEVERAL", @@ -435,14 +435,14 @@ class PublicationStatus(models.TextChoices): ) vegetarian_weekly_recurrence = models.CharField( max_length=255, - choices=MenuFrequency.choices, + choices=VegetarianMenuFrequency.choices, null=True, blank=True, verbose_name="Menus végétariens par semaine", ) vegetarian_menu_type = models.CharField( max_length=255, - choices=MenuType.choices, + choices=VegetarianMenuType.choices, blank=True, null=True, verbose_name="Menu végétarien proposé", @@ -1740,9 +1740,12 @@ def waste_badge(self) -> bool | None: @property def diversification_badge(self) -> bool | None: - if self.vegetarian_weekly_recurrence == Diagnostic.MenuFrequency.DAILY: + if self.vegetarian_weekly_recurrence == Diagnostic.VegetarianMenuFrequency.DAILY: return True - elif self.vegetarian_weekly_recurrence in [Diagnostic.MenuFrequency.MID, Diagnostic.MenuFrequency.HIGH]: + elif self.vegetarian_weekly_recurrence in [ + Diagnostic.VegetarianMenuFrequency.MID, + Diagnostic.VegetarianMenuFrequency.HIGH, + ]: # if the canteen is in the education sector, it can have a lower recurrence if self.canteen.in_education: return True