mirror of
https://github.com/hay-kot/mealie.git
synced 2025-08-22 14:33:33 -07:00
remove both flags from schema
This commit is contained in:
parent
8b48470f76
commit
1a1e837be0
5 changed files with 8 additions and 51 deletions
|
@ -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")
|
||||
|
|
|
@ -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): ...
|
||||
|
|
|
@ -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"):
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue