mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-12-26 20:25:11 -05:00
Fix/multiple bug fixes (#1015)
* test-case for #1011 * revert regressions for #1011 * update cache key on new image * lint * fix #1012 * typing * random_recipe fixture * remove delete button when no listeners are present * spacing * update copy to match settings value
This commit is contained in:
@@ -28,7 +28,7 @@ def get_valid_call(func: Callable, args_dict) -> dict:
|
||||
return {k: v for k, v in args_dict.items() if k in valid_args}
|
||||
|
||||
|
||||
def safe_call(func, dict_args, **kwargs) -> Any:
|
||||
def safe_call(func, dict_args: dict, **kwargs) -> Any:
|
||||
"""
|
||||
Safely calls the supplied function with the supplied dictionary of arguments.
|
||||
by removing any invalid arguments.
|
||||
|
||||
@@ -33,5 +33,5 @@ class RecipeInstruction(SqlAlchemyBase):
|
||||
}
|
||||
|
||||
@auto_init()
|
||||
def __init__(self, ingredient_references, **_) -> None:
|
||||
self.ingredient_references = [RecipeIngredientRefLink(**ref) for ref in ingredient_references]
|
||||
def __init__(self, ingredient_references, session, **_) -> None:
|
||||
self.ingredient_references = [RecipeIngredientRefLink(**ref, session=session) for ref in ingredient_references]
|
||||
|
||||
@@ -129,6 +129,7 @@ class RecipeModel(SqlAlchemyBase, BaseMixins):
|
||||
"notes",
|
||||
"nutrition",
|
||||
"recipe_ingredient",
|
||||
"recipe_instructions",
|
||||
"settings",
|
||||
}
|
||||
|
||||
@@ -146,10 +147,12 @@ class RecipeModel(SqlAlchemyBase, BaseMixins):
|
||||
notes: list[dict] = None,
|
||||
nutrition: dict = None,
|
||||
recipe_ingredient: list[dict] = None,
|
||||
recipe_instructions: list[dict] = None,
|
||||
settings: dict = None,
|
||||
**_,
|
||||
) -> None:
|
||||
self.nutrition = Nutrition(**nutrition) if nutrition else Nutrition()
|
||||
self.recipe_instructions = [RecipeInstruction(**step, session=session) for step in recipe_instructions]
|
||||
self.recipe_ingredient = [RecipeIngredient(**ingr, session=session) for ingr in recipe_ingredient]
|
||||
self.assets = [RecipeAsset(**a) for a in assets]
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ from mealie.core import exceptions
|
||||
from mealie.core.dependencies import temporary_zip_path
|
||||
from mealie.core.dependencies.dependencies import temporary_dir, validate_recipe_token
|
||||
from mealie.core.security import create_recipe_slug_token
|
||||
from mealie.pkgs import cache
|
||||
from mealie.repos.all_repositories import get_repositories
|
||||
from mealie.repos.repository_recipes import RepositoryRecipes
|
||||
from mealie.routes._base import BaseUserController, controller
|
||||
@@ -267,6 +268,9 @@ class RecipeController(BaseRecipeController):
|
||||
data_service = RecipeDataService(recipe.id)
|
||||
data_service.scrape_image(url.url)
|
||||
|
||||
recipe.image = cache.cache_key.new_key()
|
||||
self.service.update_one(recipe.slug, recipe)
|
||||
|
||||
@router.put("/{slug}/image", response_model=UpdateImageResponse, tags=["Recipe: Images and Assets"])
|
||||
def update_recipe_image(self, slug: str, image: bytes = File(...), extension: str = Form(...)):
|
||||
recipe = self.mixins.get_one(slug)
|
||||
@@ -286,7 +290,7 @@ class RecipeController(BaseRecipeController):
|
||||
file: UploadFile = File(...),
|
||||
):
|
||||
"""Upload a file to store as a recipe asset"""
|
||||
file_name = slugify(name) + "." + extension
|
||||
file_name = f"{slugify(name)}.{extension}"
|
||||
asset_in = RecipeAsset(name=name, icon=icon, file_name=file_name)
|
||||
|
||||
recipe = self.mixins.get_one(slug)
|
||||
|
||||
@@ -2,7 +2,7 @@ from typing import Optional
|
||||
from uuid import UUID, uuid4
|
||||
|
||||
from fastapi_camelcase import CamelModel
|
||||
from pydantic import Field
|
||||
from pydantic import UUID4, Field
|
||||
|
||||
|
||||
class IngredientReferences(CamelModel):
|
||||
@@ -10,7 +10,7 @@ class IngredientReferences(CamelModel):
|
||||
A list of ingredient references.
|
||||
"""
|
||||
|
||||
reference_id: UUID = None
|
||||
reference_id: Optional[UUID4]
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
|
||||
Reference in New Issue
Block a user