feat: adding the rest ofthe nutrition properties from schema.org (#4301)

This commit is contained in:
Tom Brennan
2024-10-13 09:04:29 -04:00
committed by GitHub
parent 3aea229f2d
commit 02c0fe993b
16 changed files with 279 additions and 57 deletions

View File

@@ -9,28 +9,52 @@ class Nutrition(SqlAlchemyBase):
__tablename__ = "recipe_nutrition"
id: Mapped[int] = mapped_column(sa.Integer, primary_key=True)
recipe_id: Mapped[GUID | None] = mapped_column(GUID, sa.ForeignKey("recipes.id"), index=True)
calories: Mapped[str | None] = mapped_column(sa.String)
carbohydrate_content: Mapped[str | None] = mapped_column(sa.String)
cholesterol_content: Mapped[str | None] = mapped_column(sa.String)
fat_content: Mapped[str | None] = mapped_column(sa.String)
fiber_content: Mapped[str | None] = mapped_column(sa.String)
protein_content: Mapped[str | None] = mapped_column(sa.String)
carbohydrate_content: Mapped[str | None] = mapped_column(sa.String)
saturated_fat_content: Mapped[str | None] = mapped_column(sa.String)
# `serving_size` is not a scaling factor, but a per-serving volume or mass
# according to schema.org. E.g., "2 L", "500 g", "5 cups", etc.
#
# Ignoring for now because it's too difficult to work around variable units
# in translation for the frontend. Also, it causes cognitive dissonance wrt
# "servings" (i.e., "serves 2" etc.), which is an unrelated concept that
# might cause confusion.
#
# serving_size: Mapped[str | None] = mapped_column(sa.String)
sodium_content: Mapped[str | None] = mapped_column(sa.String)
sugar_content: Mapped[str | None] = mapped_column(sa.String)
trans_fat_content: Mapped[str | None] = mapped_column(sa.String)
unsaturated_fat_content: Mapped[str | None] = mapped_column(sa.String)
def __init__(
self,
calories=None,
carbohydrate_content=None,
cholesterol_content=None,
fat_content=None,
fiber_content=None,
protein_content=None,
saturated_fat_content=None,
sodium_content=None,
sugar_content=None,
carbohydrate_content=None,
trans_fat_content=None,
unsaturated_fat_content=None,
) -> None:
self.calories = calories
self.carbohydrate_content = carbohydrate_content
self.cholesterol_content = cholesterol_content
self.fat_content = fat_content
self.fiber_content = fiber_content
self.protein_content = protein_content
self.saturated_fat_content = saturated_fat_content
self.sodium_content = sodium_content
self.sugar_content = sugar_content
self.carbohydrate_content = carbohydrate_content
self.trans_fat_content = trans_fat_content
self.unsaturated_fat_content = unsaturated_fat_content

View File

@@ -187,7 +187,7 @@ class RecipeModel(SqlAlchemyBase, BaseMixins):
settings: dict | None = None,
**_,
) -> None:
self.nutrition = Nutrition(**nutrition) if nutrition else Nutrition()
self.nutrition = Nutrition(**(nutrition or {}))
if recipe_instructions is not None:
self.recipe_instructions = [RecipeInstruction(**step, session=session) for step in recipe_instructions]
@@ -198,7 +198,7 @@ class RecipeModel(SqlAlchemyBase, BaseMixins):
if assets:
self.assets = [RecipeAsset(**a) for a in assets]
self.settings = RecipeSettings(**settings) if settings else RecipeSettings()
self.settings = RecipeSettings(**(settings or {}))
if notes:
self.notes = [Note(**n) for n in notes]