snake case all recipes entries

This commit is contained in:
hay-kot 2021-04-28 20:50:57 -08:00
commit 4d98a18ff1
9 changed files with 84 additions and 84 deletions

View file

@ -41,7 +41,7 @@ class Category(SqlAlchemyBase):
id = sa.Column(sa.Integer, primary_key=True) id = sa.Column(sa.Integer, primary_key=True)
name = sa.Column(sa.String, index=True, nullable=False) name = sa.Column(sa.String, index=True, nullable=False)
slug = sa.Column(sa.String, index=True, unique=True, nullable=False) slug = sa.Column(sa.String, index=True, unique=True, nullable=False)
recipes = orm.relationship("RecipeModel", secondary=recipes2categories, back_populates="recipeCategory") recipes = orm.relationship("RecipeModel", secondary=recipes2categories, back_populates="recipe_category")
@validates("name") @validates("name")
def validate_name(self, key, name): def validate_name(self, key, name):

View file

@ -7,27 +7,27 @@ class Nutrition(SqlAlchemyBase):
id = sa.Column(sa.Integer, primary_key=True) id = sa.Column(sa.Integer, primary_key=True)
parent_id = sa.Column(sa.String, sa.ForeignKey("recipes.id")) parent_id = sa.Column(sa.String, sa.ForeignKey("recipes.id"))
calories = sa.Column(sa.String) calories = sa.Column(sa.String)
fatContent = sa.Column(sa.String) fat_content = sa.Column(sa.String)
fiberContent = sa.Column(sa.String) fiber_content = sa.Column(sa.String)
proteinContent = sa.Column(sa.String) protein_content = sa.Column(sa.String)
carbohydrateContent = sa.Column(sa.String) carbohydrate_content = sa.Column(sa.String)
sodiumContent = sa.Column(sa.String) sodium_content = sa.Column(sa.String)
sugarContent = sa.Column(sa.String) sugar_content = sa.Column(sa.String)
def __init__( def __init__(
self, self,
calories=None, calories=None,
fatContent=None, fat_content=None,
fiberContent=None, fiber_content=None,
proteinContent=None, protein_content=None,
sodiumContent=None, sodium_content=None,
sugarContent=None, sugar_content=None,
carbohydrateContent=None, carbohydrate_content=None,
) -> None: ) -> None:
self.calories = calories self.calories = calories
self.fatContent = fatContent self.fat_content = fat_content
self.fiberContent = fiberContent self.fiber_content = fiber_content
self.proteinContent = proteinContent self.protein_content = protein_content
self.sodiumContent = sodiumContent self.sodium_content = sodium_content
self.sugarContent = sugarContent self.sugar_content = sugar_content
self.carbohydrateContent = carbohydrateContent self.carbohydrate_content = carbohydrate_content

View file

@ -27,24 +27,24 @@ class RecipeModel(SqlAlchemyBase, BaseMixins):
name = sa.Column(sa.String, nullable=False) name = sa.Column(sa.String, nullable=False)
description = sa.Column(sa.String) description = sa.Column(sa.String)
image = sa.Column(sa.String) image = sa.Column(sa.String)
totalTime = sa.Column(sa.String) total_time = sa.Column(sa.String)
prepTime = sa.Column(sa.String) prep_time = sa.Column(sa.String)
performTime = sa.Column(sa.String) perform_time = sa.Column(sa.String)
cookTime = sa.Column(sa.String) cookTime = sa.Column(sa.String)
recipeYield = sa.Column(sa.String) recipe_yield = sa.Column(sa.String)
recipeCuisine = sa.Column(sa.String) recipeCuisine = sa.Column(sa.String)
tools: list[Tool] = orm.relationship("Tool", cascade="all, delete-orphan") tools: list[Tool] = orm.relationship("Tool", cascade="all, delete-orphan")
assets: list[RecipeAsset] = orm.relationship("RecipeAsset", cascade="all, delete-orphan") assets: list[RecipeAsset] = orm.relationship("RecipeAsset", cascade="all, delete-orphan")
nutrition: Nutrition = orm.relationship("Nutrition", uselist=False, cascade="all, delete-orphan") nutrition: Nutrition = orm.relationship("Nutrition", uselist=False, cascade="all, delete-orphan")
recipeCategory: list = orm.relationship("Category", secondary=recipes2categories, back_populates="recipes") recipe_category: list = orm.relationship("Category", secondary=recipes2categories, back_populates="recipes")
recipeIngredient: list[RecipeIngredient] = orm.relationship( recipe_ingredient: list[RecipeIngredient] = orm.relationship(
"RecipeIngredient", "RecipeIngredient",
cascade="all, delete-orphan", cascade="all, delete-orphan",
order_by="RecipeIngredient.position", order_by="RecipeIngredient.position",
collection_class=ordering_list("position"), collection_class=ordering_list("position"),
) )
recipeInstructions: list[RecipeInstruction] = orm.relationship( recipe_instructions: list[RecipeInstruction] = orm.relationship(
"RecipeInstruction", "RecipeInstruction",
cascade="all, delete-orphan", cascade="all, delete-orphan",
order_by="RecipeInstruction.position", order_by="RecipeInstruction.position",
@ -55,10 +55,10 @@ class RecipeModel(SqlAlchemyBase, BaseMixins):
slug = sa.Column(sa.String, index=True, unique=True) slug = sa.Column(sa.String, index=True, unique=True)
settings = orm.relationship("RecipeSettings", uselist=False, cascade="all, delete-orphan") settings = orm.relationship("RecipeSettings", uselist=False, cascade="all, delete-orphan")
tags: list[Tag] = orm.relationship("Tag", secondary=recipes2tags, back_populates="recipes") tags: list[Tag] = orm.relationship("Tag", secondary=recipes2tags, back_populates="recipes")
dateAdded = sa.Column(sa.Date, default=date.today) date_added = sa.Column(sa.Date, default=date.today)
notes: list[Note] = orm.relationship("Note", cascade="all, delete-orphan") notes: list[Note] = orm.relationship("Note", cascade="all, delete-orphan")
rating = sa.Column(sa.Integer) rating = sa.Column(sa.Integer)
orgURL = sa.Column(sa.String) org_url = sa.Column(sa.String)
extras: list[ApiExtras] = orm.relationship("ApiExtras", cascade="all, delete-orphan") extras: list[ApiExtras] = orm.relationship("ApiExtras", cascade="all, delete-orphan")
@validates("name") @validates("name")
@ -72,22 +72,22 @@ class RecipeModel(SqlAlchemyBase, BaseMixins):
name: str = None, name: str = None,
description: str = None, description: str = None,
image: str = None, image: str = None,
recipeYield: str = None, recipe_yield: str = None,
recipeIngredient: list[str] = None, recipe_ingredient: list[str] = None,
recipeInstructions: list[dict] = None, recipe_instructions: list[dict] = None,
recipeCuisine: str = None, recipeCuisine: str = None,
totalTime: str = None, total_time: str = None,
prepTime: str = None, prep_time: str = None,
nutrition: dict = None, nutrition: dict = None,
tools: list[str] = None, tools: list[str] = None,
performTime: str = None, perform_time: str = None,
slug: str = None, slug: str = None,
recipeCategory: list[str] = None, recipe_category: list[str] = None,
tags: list[str] = None, tags: list[str] = None,
dateAdded: datetime.date = None, date_added: datetime.date = None,
notes: list[dict] = None, notes: list[dict] = None,
rating: int = None, rating: int = None,
orgURL: str = None, org_url: str = None,
extras: dict = None, extras: dict = None,
assets: list = None, assets: list = None,
settings: dict = None, settings: dict = None,
@ -103,28 +103,28 @@ class RecipeModel(SqlAlchemyBase, BaseMixins):
self.tools = [Tool(tool=x) for x in tools] if tools else [] self.tools = [Tool(tool=x) for x in tools] if tools else []
self.recipeYield = recipeYield self.recipe_yield = recipe_yield
self.recipeIngredient = [RecipeIngredient(ingredient=ingr) for ingr in recipeIngredient] self.recipe_ingredient = [RecipeIngredient(ingredient=ingr) for ingr in recipe_ingredient]
self.assets = [RecipeAsset(**a) for a in assets] self.assets = [RecipeAsset(**a) for a in assets]
self.recipeInstructions = [ self.recipe_instructions = [
RecipeInstruction(text=instruc.get("text"), title=instruc.get("title"), type=instruc.get("@type", None)) RecipeInstruction(text=instruc.get("text"), title=instruc.get("title"), type=instruc.get("@type", None))
for instruc in recipeInstructions for instruc in recipe_instructions
] ]
self.totalTime = totalTime self.total_time = total_time
self.prepTime = prepTime self.prep_time = prep_time
self.performTime = performTime self.perform_time = perform_time
self.recipeCategory = [Category.create_if_not_exist(session=session, name=cat) for cat in recipeCategory] self.recipe_category = [Category.create_if_not_exist(session=session, name=cat) for cat in recipe_category]
# Mealie Specific # Mealie Specific
self.settings = RecipeSettings(**settings) if settings else RecipeSettings() self.settings = RecipeSettings(**settings) if settings else RecipeSettings()
print(self.settings) print(self.settings)
self.tags = [Tag.create_if_not_exist(session=session, name=tag) for tag in tags] self.tags = [Tag.create_if_not_exist(session=session, name=tag) for tag in tags]
self.slug = slug self.slug = slug
self.dateAdded = dateAdded self.date_added = date_added
self.notes = [Note(**note) for note in notes] self.notes = [Note(**note) for note in notes]
self.rating = rating self.rating = rating
self.orgURL = orgURL self.org_url = org_url
self.extras = [ApiExtras(key=key, value=value) for key, value in extras.items()] self.extras = [ApiExtras(key=key, value=value) for key, value in extras.items()]
def update(self, *args, **kwargs): def update(self, *args, **kwargs):

View file

@ -21,4 +21,4 @@ def get_shopping_list(
mealplan: MealPlanInDB mealplan: MealPlanInDB
slugs = [x.slug for x in mealplan.meals] slugs = [x.slug for x in mealplan.meals]
recipes: list[Recipe] = [db.recipes.get(session, x) for x in slugs] recipes: list[Recipe] = [db.recipes.get(session, x) for x in slugs]
return [{"name": x.name, "recipeIngredient": x.recipeIngredient} for x in recipes if x] return [{"name": x.name, "recipe_ingredient": x.recipe_ingredient} for x in recipes if x]

View file

@ -50,11 +50,11 @@ def get_all_recipes(
- description - description
- image - image
- recipeYield - recipeYield
- totalTime - total_time
- prepTime - prep_time
- performTime - perform_time
- rating - rating
- orgURL - org_url
**Note:** You may experience problems with with query parameters. As an alternative **Note:** You may experience problems with with query parameters. As an alternative
you may also use the post method and provide a body. you may also use the post method and provide a body.
@ -78,11 +78,11 @@ def get_all_recipes_post(body: AllRecipeRequest, session: Session = Depends(gene
- description - description
- image - image
- recipeYield - recipeYield
- totalTime - total_time
- prepTime - prep_time
- performTime - perform_time
- rating - rating
- orgURL - org_url
Refer to the body example for data formats. Refer to the body example for data formats.

View file

@ -43,27 +43,27 @@ class RecipeAsset(CamelModel):
orm_mode = True orm_mode = True
class Nutrition(BaseModel): class Nutrition(CamelModel):
calories: Optional[str] calories: Optional[str]
fatContent: Optional[str] fat_content: Optional[str]
proteinContent: Optional[str] protein_content: Optional[str]
carbohydrateContent: Optional[str] carbohydrate_content: Optional[str]
fiberContent: Optional[str] fiber_content: Optional[str]
sodiumContent: Optional[str] sodium_content: Optional[str]
sugarContent: Optional[str] sugar_content: Optional[str]
class Config: class Config:
orm_mode = True orm_mode = True
class RecipeSummary(BaseModel): class RecipeSummary(CamelModel):
id: Optional[int] id: Optional[int]
name: str name: str
slug: Optional[str] = "" slug: Optional[str] = ""
image: Optional[Any] image: Optional[Any]
description: Optional[str] description: Optional[str]
recipeCategory: Optional[list[str]] = [] recipe_category: Optional[list[str]] = []
tags: Optional[list[str]] = [] tags: Optional[list[str]] = []
rating: Optional[int] rating: Optional[int]
@ -74,28 +74,28 @@ class RecipeSummary(BaseModel):
def getter_dict(_cls, name_orm: RecipeModel): def getter_dict(_cls, name_orm: RecipeModel):
return { return {
**GetterDict(name_orm), **GetterDict(name_orm),
"recipeCategory": [x.name for x in name_orm.recipeCategory], "recipe_category": [x.name for x in name_orm.recipe_category],
"tags": [x.name for x in name_orm.tags], "tags": [x.name for x in name_orm.tags],
} }
class Recipe(RecipeSummary): class Recipe(RecipeSummary):
recipeYield: Optional[str] recipe_yield: Optional[str]
recipeIngredient: Optional[list[str]] recipe_ingredient: Optional[list[str]]
recipeInstructions: Optional[list[RecipeStep]] recipe_instructions: Optional[list[RecipeStep]]
nutrition: Optional[Nutrition] nutrition: Optional[Nutrition]
tools: Optional[list[str]] = [] tools: Optional[list[str]] = []
totalTime: Optional[str] = None total_time: Optional[str] = None
prepTime: Optional[str] = None prep_time: Optional[str] = None
performTime: Optional[str] = None perform_time: Optional[str] = None
# Mealie Specific # Mealie Specific
settings: Optional[RecipeSettings] settings: Optional[RecipeSettings]
assets: Optional[list[RecipeAsset]] = [] assets: Optional[list[RecipeAsset]] = []
dateAdded: Optional[datetime.date] date_added: Optional[datetime.date]
notes: Optional[list[RecipeNote]] = [] notes: Optional[list[RecipeNote]] = []
orgURL: Optional[str] org_url: Optional[str] = Field(None, alias="orgURL")
extras: Optional[dict] = {} extras: Optional[dict] = {}
class Config: class Config:
@ -105,8 +105,8 @@ class Recipe(RecipeSummary):
def getter_dict(_cls, name_orm: RecipeModel): def getter_dict(_cls, name_orm: RecipeModel):
return { return {
**GetterDict(name_orm), **GetterDict(name_orm),
"recipeIngredient": [x.ingredient for x in name_orm.recipeIngredient], "recipe_ingredient": [x.ingredient for x in name_orm.recipe_ingredient],
"recipeCategory": [x.name for x in name_orm.recipeCategory], "recipe_category": [x.name for x in name_orm.recipe_category],
"tags": [x.name for x in name_orm.tags], "tags": [x.name for x in name_orm.tags],
"tools": [x.tool for x in name_orm.tools], "tools": [x.tool for x in name_orm.tools],
"extras": {x.key_name: x.value for x in name_orm.extras}, "extras": {x.key_name: x.value for x in name_orm.extras},
@ -117,22 +117,22 @@ class Recipe(RecipeSummary):
"name": "Chicken and Rice With Leeks and Salsa Verde", "name": "Chicken and Rice With Leeks and Salsa Verde",
"description": "This one-skillet dinner gets deep oniony flavor from lots of leeks cooked down to jammy tenderness.", "description": "This one-skillet dinner gets deep oniony flavor from lots of leeks cooked down to jammy tenderness.",
"image": "chicken-and-rice-with-leeks-and-salsa-verde.jpg", "image": "chicken-and-rice-with-leeks-and-salsa-verde.jpg",
"recipeYield": "4 Servings", "recipe_yield": "4 Servings",
"recipeIngredient": [ "recipe_ingredient": [
"1 1/2 lb. skinless, boneless chicken thighs (4-8 depending on size)", "1 1/2 lb. skinless, boneless chicken thighs (4-8 depending on size)",
"Kosher salt, freshly ground pepper", "Kosher salt, freshly ground pepper",
"3 Tbsp. unsalted butter, divided", "3 Tbsp. unsalted butter, divided",
], ],
"recipeInstructions": [ "recipe_instructions": [
{ {
"text": "Season chicken with salt and pepper.", "text": "Season chicken with salt and pepper.",
}, },
], ],
"slug": "chicken-and-rice-with-leeks-and-salsa-verde", "slug": "chicken-and-rice-with-leeks-and-salsa-verde",
"tags": ["favorite", "yummy!"], "tags": ["favorite", "yummy!"],
"recipeCategory": ["Dinner", "Pasta"], "recipe_category": ["Dinner", "Pasta"],
"notes": [{"title": "Watch Out!", "text": "Prep the day before!"}], "notes": [{"title": "Watch Out!", "text": "Prep the day before!"}],
"orgURL": "https://www.bonappetit.com/recipe/chicken-and-rice-with-leeks-and-salsa-verde", "org_url": "https://www.bonappetit.com/recipe/chicken-and-rice-with-leeks-and-salsa-verde",
"rating": 3, "rating": 3,
"extras": {"message": "Don't forget to defrost the chicken!"}, "extras": {"message": "Don't forget to defrost the chicken!"},
} }

View file

@ -83,7 +83,7 @@ class ImportDatabase:
del recipe_dict["categories"] del recipe_dict["categories"]
try: try:
del recipe_dict["_id"] del recipe_dict["_id"]
del recipe_dict["dateAdded"] del recipe_dict["date_added"]
except: except:
pass pass
# Migration from list to Object Type Data # Migration from list to Object Type Data

View file

@ -144,7 +144,7 @@ class MigrationBase(BaseModel):
"""Calls the rewrite_alias function and the Cleaner.clean function on a """Calls the rewrite_alias function and the Cleaner.clean function on a
dictionary and returns the result unpacked into a Recipe object""" dictionary and returns the result unpacked into a Recipe object"""
recipe_dict = self.rewrite_alias(recipe_dict) recipe_dict = self.rewrite_alias(recipe_dict)
recipe_dict = Cleaner.clean(recipe_dict, url=recipe_dict.get("orgURL", None)) recipe_dict = Cleaner.clean(recipe_dict, url=recipe_dict.get("org_url", None))
return Recipe(**recipe_dict) return Recipe(**recipe_dict)

View file

@ -37,7 +37,7 @@ class NextcloudDir:
class NextcloudMigration(MigrationBase): class NextcloudMigration(MigrationBase):
key_aliases: Optional[list[MigrationAlias]] = [ key_aliases: Optional[list[MigrationAlias]] = [
MigrationAlias(key="tags", alias="keywords", func=helpers.split_by_comma), MigrationAlias(key="tags", alias="keywords", func=helpers.split_by_comma),
MigrationAlias(key="orgURL", alias="url", func=None), MigrationAlias(key="org_url", alias="url", func=None),
] ]