From 1a1e837be00c008af5fd75507dcca2b58a670a10 Mon Sep 17 00:00:00 2001 From: Michael Genson <71845777+michael-genson@users.noreply.github.com> Date: Fri, 11 Jul 2025 16:19:17 +0000 Subject: [PATCH] remove both flags from schema --- .../schema/household/group_shopping_list.py | 1 - .../schema/household/household_preferences.py | 1 - mealie/schema/recipe/recipe.py | 14 +------ mealie/schema/recipe/recipe_ingredient.py | 42 ++++--------------- mealie/schema/recipe/recipe_settings.py | 1 - 5 files changed, 8 insertions(+), 51 deletions(-) diff --git a/mealie/schema/household/group_shopping_list.py b/mealie/schema/household/group_shopping_list.py index 2063b6909..de3aa9878 100644 --- a/mealie/schema/household/group_shopping_list.py +++ b/mealie/schema/household/group_shopping_list.py @@ -66,7 +66,6 @@ class ShoppingListItemBase(RecipeIngredientBase): label_id: UUID4 | None = None unit_id: UUID4 | None = None - is_food: bool = False extras: dict | None = {} @field_validator("extras", mode="before") diff --git a/mealie/schema/household/household_preferences.py b/mealie/schema/household/household_preferences.py index 5cbc80440..e744ab69d 100644 --- a/mealie/schema/household/household_preferences.py +++ b/mealie/schema/household/household_preferences.py @@ -18,7 +18,6 @@ class UpdateHouseholdPreferences(MealieModel): recipe_show_assets: bool = False recipe_landscape_view: bool = False recipe_disable_comments: bool = False - recipe_disable_amount: bool = True class CreateHouseholdPreferences(UpdateHouseholdPreferences): ... diff --git a/mealie/schema/recipe/recipe.py b/mealie/schema/recipe/recipe.py index b6c96e098..ffc62d112 100644 --- a/mealie/schema/recipe/recipe.py +++ b/mealie/schema/recipe/recipe.py @@ -6,7 +6,7 @@ from pathlib import Path from typing import Annotated, Any, ClassVar from uuid import uuid4 -from pydantic import UUID4, BaseModel, ConfigDict, Field, field_validator, model_validator +from pydantic import UUID4, BaseModel, ConfigDict, Field, field_validator from pydantic_core.core_schema import ValidationInfo from slugify import slugify from sqlalchemy import Select, desc, func, or_, select, text @@ -228,18 +228,6 @@ class Recipe(RecipeSummary): model_config = ConfigDict(from_attributes=True) - @model_validator(mode="after") - def calculate_missing_food_flags_and_format_display(self): - disable_amount = self.settings.disable_amount if self.settings else True - for ingredient in self.recipe_ingredient: - ingredient.disable_amount = disable_amount - ingredient.is_food = not ingredient.disable_amount - - # recalculate the display property, since it depends on the disable_amount flag - ingredient.display = ingredient._format_display() - - return self - @field_validator("slug", mode="before") def validate_slug(slug: str, info: ValidationInfo): if not info.data.get("name"): diff --git a/mealie/schema/recipe/recipe_ingredient.py b/mealie/schema/recipe/recipe_ingredient.py index db3107a23..25b859010 100644 --- a/mealie/schema/recipe/recipe_ingredient.py +++ b/mealie/schema/recipe/recipe_ingredient.py @@ -157,8 +157,6 @@ class RecipeIngredientBase(MealieModel): food: IngredientFood | CreateIngredientFood | None = None note: str | None = "" - is_food: bool | None = None - disable_amount: bool | None = None display: str = "" """ How the ingredient should be displayed @@ -166,20 +164,6 @@ class RecipeIngredientBase(MealieModel): Automatically calculated after the object is created, unless overwritten """ - @model_validator(mode="after") - def calculate_missing_food_flags(self): - # calculate missing is_food and disable_amount values - # we can't do this in a validator since they depend on each other - if self.is_food is None and self.disable_amount is not None: - self.is_food = not self.disable_amount - elif self.disable_amount is None and self.is_food is not None: - self.disable_amount = not self.is_food - elif self.is_food is None and self.disable_amount is None: - self.is_food = bool(self.food) - self.disable_amount = not self.is_food - - return self - @model_validator(mode="after") def format_display(self): if not self.display: @@ -266,28 +250,17 @@ class RecipeIngredientBase(MealieModel): def _format_display(self) -> str: components = [] - use_food = True - if self.is_food is False: - use_food = False - elif self.disable_amount is True: - use_food = False - - # ingredients with no food come across with a qty of 1, which looks weird - # e.g. "1 2 tbsp of olive oil" - if self.quantity and (use_food or self.quantity != 1): + if self.quantity: components.append(self._format_quantity_for_display()) - if not use_food: - components.append(self.note or "") - else: - if self.quantity and self.unit: - components.append(self._format_unit_for_display()) + if self.quantity and self.unit: + components.append(self._format_unit_for_display()) - if self.food: - components.append(self._format_food_for_display()) + if self.food: + components.append(self._format_food_for_display()) - if self.note: - components.append(self.note) + if self.note: + components.append(self.note) return " ".join(components).strip() @@ -299,7 +272,6 @@ class IngredientUnitPagination(PaginationBase): class RecipeIngredient(RecipeIngredientBase): title: str | None = None original_text: str | None = None - disable_amount: bool = True # Ref is used as a way to distinguish between an individual ingredient on the frontend # It is required for the reorder and section titles to function properly because of how diff --git a/mealie/schema/recipe/recipe_settings.py b/mealie/schema/recipe/recipe_settings.py index 1d90c3397..760fbd615 100644 --- a/mealie/schema/recipe/recipe_settings.py +++ b/mealie/schema/recipe/recipe_settings.py @@ -9,6 +9,5 @@ class RecipeSettings(MealieModel): show_assets: bool = False landscape_view: bool = False disable_comments: bool = True - disable_amount: bool = True locked: bool = False model_config = ConfigDict(from_attributes=True)