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
|
label_id: UUID4 | None = None
|
||||||
unit_id: UUID4 | None = None
|
unit_id: UUID4 | None = None
|
||||||
|
|
||||||
is_food: bool = False
|
|
||||||
extras: dict | None = {}
|
extras: dict | None = {}
|
||||||
|
|
||||||
@field_validator("extras", mode="before")
|
@field_validator("extras", mode="before")
|
||||||
|
|
|
@ -18,7 +18,6 @@ class UpdateHouseholdPreferences(MealieModel):
|
||||||
recipe_show_assets: bool = False
|
recipe_show_assets: bool = False
|
||||||
recipe_landscape_view: bool = False
|
recipe_landscape_view: bool = False
|
||||||
recipe_disable_comments: bool = False
|
recipe_disable_comments: bool = False
|
||||||
recipe_disable_amount: bool = True
|
|
||||||
|
|
||||||
|
|
||||||
class CreateHouseholdPreferences(UpdateHouseholdPreferences): ...
|
class CreateHouseholdPreferences(UpdateHouseholdPreferences): ...
|
||||||
|
|
|
@ -6,7 +6,7 @@ from pathlib import Path
|
||||||
from typing import Annotated, Any, ClassVar
|
from typing import Annotated, Any, ClassVar
|
||||||
from uuid import uuid4
|
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 pydantic_core.core_schema import ValidationInfo
|
||||||
from slugify import slugify
|
from slugify import slugify
|
||||||
from sqlalchemy import Select, desc, func, or_, select, text
|
from sqlalchemy import Select, desc, func, or_, select, text
|
||||||
|
@ -228,18 +228,6 @@ class Recipe(RecipeSummary):
|
||||||
|
|
||||||
model_config = ConfigDict(from_attributes=True)
|
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")
|
@field_validator("slug", mode="before")
|
||||||
def validate_slug(slug: str, info: ValidationInfo):
|
def validate_slug(slug: str, info: ValidationInfo):
|
||||||
if not info.data.get("name"):
|
if not info.data.get("name"):
|
||||||
|
|
|
@ -157,8 +157,6 @@ class RecipeIngredientBase(MealieModel):
|
||||||
food: IngredientFood | CreateIngredientFood | None = None
|
food: IngredientFood | CreateIngredientFood | None = None
|
||||||
note: str | None = ""
|
note: str | None = ""
|
||||||
|
|
||||||
is_food: bool | None = None
|
|
||||||
disable_amount: bool | None = None
|
|
||||||
display: str = ""
|
display: str = ""
|
||||||
"""
|
"""
|
||||||
How the ingredient should be displayed
|
How the ingredient should be displayed
|
||||||
|
@ -166,20 +164,6 @@ class RecipeIngredientBase(MealieModel):
|
||||||
Automatically calculated after the object is created, unless overwritten
|
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")
|
@model_validator(mode="after")
|
||||||
def format_display(self):
|
def format_display(self):
|
||||||
if not self.display:
|
if not self.display:
|
||||||
|
@ -266,28 +250,17 @@ class RecipeIngredientBase(MealieModel):
|
||||||
def _format_display(self) -> str:
|
def _format_display(self) -> str:
|
||||||
components = []
|
components = []
|
||||||
|
|
||||||
use_food = True
|
if self.quantity:
|
||||||
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):
|
|
||||||
components.append(self._format_quantity_for_display())
|
components.append(self._format_quantity_for_display())
|
||||||
|
|
||||||
if not use_food:
|
if self.quantity and self.unit:
|
||||||
components.append(self.note or "")
|
components.append(self._format_unit_for_display())
|
||||||
else:
|
|
||||||
if self.quantity and self.unit:
|
|
||||||
components.append(self._format_unit_for_display())
|
|
||||||
|
|
||||||
if self.food:
|
if self.food:
|
||||||
components.append(self._format_food_for_display())
|
components.append(self._format_food_for_display())
|
||||||
|
|
||||||
if self.note:
|
if self.note:
|
||||||
components.append(self.note)
|
components.append(self.note)
|
||||||
|
|
||||||
return " ".join(components).strip()
|
return " ".join(components).strip()
|
||||||
|
|
||||||
|
@ -299,7 +272,6 @@ class IngredientUnitPagination(PaginationBase):
|
||||||
class RecipeIngredient(RecipeIngredientBase):
|
class RecipeIngredient(RecipeIngredientBase):
|
||||||
title: str | None = None
|
title: str | None = None
|
||||||
original_text: 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
|
# 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
|
# 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
|
show_assets: bool = False
|
||||||
landscape_view: bool = False
|
landscape_view: bool = False
|
||||||
disable_comments: bool = True
|
disable_comments: bool = True
|
||||||
disable_amount: bool = True
|
|
||||||
locked: bool = False
|
locked: bool = False
|
||||||
model_config = ConfigDict(from_attributes=True)
|
model_config = ConfigDict(from_attributes=True)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue