Merge branch 'mealie-next' into feat/filter-shopping-lists

This commit is contained in:
Michael Genson
2024-03-05 09:18:37 -06:00
committed by GitHub
57 changed files with 514 additions and 341 deletions

View File

@@ -101,7 +101,7 @@ class ShoppingListItemOut(ShoppingListItemBase):
update_at: datetime | None = None
@model_validator(mode="after")
def post_validate(self):
def populate_missing_label(self):
# if we're missing a label, but the food has a label, use that as the label
if (not self.label) and (self.food and self.food.label):
self.label = self.food.label

View File

@@ -184,13 +184,13 @@ class Recipe(RecipeSummary):
model_config = ConfigDict(from_attributes=True)
@model_validator(mode="after")
def post_validate(self):
# the ingredient disable_amount property is unreliable,
# so we set it here and recalculate the display property
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

View File

@@ -145,7 +145,7 @@ class RecipeIngredientBase(MealieModel):
"""
@model_validator(mode="after")
def post_validate(self):
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:
@@ -156,7 +156,10 @@ class RecipeIngredientBase(MealieModel):
self.is_food = bool(self.food)
self.disable_amount = not self.is_food
# format the display property
return self
@model_validator(mode="after")
def format_display(self):
if not self.display:
self.display = self._format_display()