mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-12-10 12:25:14 -05:00
fix(backend): 🐛 Fix CI/CD Linting Failures
This commit is contained in:
@@ -4,9 +4,10 @@ from mealie.db.data_access_layer.group_access_model import GroupDataAccessModel
|
||||
from mealie.db.models.event import Event, EventNotification
|
||||
from mealie.db.models.group import Group
|
||||
from mealie.db.models.mealplan import MealPlan
|
||||
from mealie.db.models.recipe.category import Category
|
||||
from mealie.db.models.recipe.comment import RecipeComment
|
||||
from mealie.db.models.recipe.ingredient import IngredientFoodModel, IngredientUnitModel
|
||||
from mealie.db.models.recipe.recipe import Category, RecipeModel, Tag
|
||||
from mealie.db.models.recipe.recipe import RecipeModel, Tag
|
||||
from mealie.db.models.settings import CustomPage, SiteSettings
|
||||
from mealie.db.models.shopping_list import ShoppingList
|
||||
from mealie.db.models.sign_up import SignUp
|
||||
@@ -82,5 +83,5 @@ class DatabaseAccessLayer:
|
||||
self.users = UserDataAccessModel(DEFAULT_PK, User, UserInDB)
|
||||
self.api_tokens = BaseAccessModel(DEFAULT_PK, LongLiveToken, LongLiveTokenInDB)
|
||||
self.groups = GroupDataAccessModel(DEFAULT_PK, Group, GroupInDB)
|
||||
self.meals = BaseAccessModel("uid", MealPlan, MealPlanOut)
|
||||
self.meals = BaseAccessModel(DEFAULT_PK, MealPlan, MealPlanOut)
|
||||
self.shopping_lists = BaseAccessModel(DEFAULT_PK, ShoppingList, ShoppingListOut)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
|
||||
from mealie.db.db_setup import SessionLocal
|
||||
from sqlalchemy import Column, DateTime, Integer
|
||||
from sqlalchemy.ext.declarative import as_declarative
|
||||
from sqlalchemy.orm import declarative_base
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import sqlalchemy.orm as orm
|
||||
from mealie.db.models.group import Group
|
||||
from mealie.db.models._model_base import BaseMixins, SqlAlchemyBase
|
||||
from mealie.db.models.group import Group
|
||||
from mealie.db.models.recipe.recipe import RecipeModel
|
||||
from mealie.db.models.shopping_list import ShoppingList
|
||||
from sqlalchemy import Column, Date, ForeignKey, Integer, String
|
||||
@@ -33,7 +33,7 @@ class Meal(SqlAlchemyBase):
|
||||
class MealDay(SqlAlchemyBase, BaseMixins):
|
||||
__tablename__ = "mealdays"
|
||||
id = Column(Integer, primary_key=True)
|
||||
parent_id = Column(Integer, ForeignKey("mealplan.uid"))
|
||||
parent_id = Column(Integer, ForeignKey("mealplan.id"))
|
||||
date = Column(Date)
|
||||
meals: list[Meal] = orm.relationship(
|
||||
Meal,
|
||||
@@ -49,7 +49,7 @@ class MealDay(SqlAlchemyBase, BaseMixins):
|
||||
|
||||
class MealPlan(SqlAlchemyBase, BaseMixins):
|
||||
__tablename__ = "mealplan"
|
||||
uid = Column(Integer, primary_key=True, unique=True)
|
||||
# TODO: Migrate to use ID as PK
|
||||
start_date = Column(Date)
|
||||
end_date = Column(Date)
|
||||
plan_days: list[MealDay] = orm.relationship(MealDay, cascade="all, delete, delete-orphan")
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
from functools import lru_cache
|
||||
|
||||
import sqlalchemy as sa
|
||||
import sqlalchemy.orm as orm
|
||||
from mealie.core import root_logger
|
||||
from mealie.db.db_setup import SessionLocal
|
||||
from mealie.db.models._model_base import BaseMixins, SqlAlchemyBase
|
||||
from slugify import slugify
|
||||
from sqlalchemy import inspect
|
||||
from sqlalchemy.orm import validates
|
||||
|
||||
logger = root_logger.get_logger()
|
||||
@@ -64,7 +60,9 @@ class Category(SqlAlchemyBase, BaseMixins):
|
||||
if not session or not match_value:
|
||||
return None
|
||||
|
||||
result = session.query(Category).filter(Category.name == match_value).one_or_none()
|
||||
slug = slugify(match_value)
|
||||
|
||||
result = session.query(Category).filter(Category.slug == slug).one_or_none()
|
||||
if result:
|
||||
logger.debug("Category exists, associating recipe")
|
||||
return result
|
||||
|
||||
@@ -10,7 +10,7 @@ from .._model_base import BaseMixins, SqlAlchemyBase
|
||||
from .._model_utils import auto_init
|
||||
from .api_extras import ApiExtras
|
||||
from .assets import RecipeAsset
|
||||
from .category import Category, recipes2categories
|
||||
from .category import recipes2categories
|
||||
from .ingredient import RecipeIngredient
|
||||
from .instruction import RecipeInstruction
|
||||
from .note import Note
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import sqlalchemy as sa
|
||||
import sqlalchemy.orm as orm
|
||||
from mealie.core import root_logger
|
||||
from mealie.db.db_setup import SessionLocal
|
||||
from mealie.db.models._model_base import BaseMixins, SqlAlchemyBase
|
||||
from slugify import slugify
|
||||
from sqlalchemy.orm import validates
|
||||
@@ -35,15 +34,17 @@ class Tag(SqlAlchemyBase, BaseMixins):
|
||||
self.name = name.strip()
|
||||
self.slug = slugify(self.name)
|
||||
|
||||
@staticmethod
|
||||
def create_if_not_exist(name: str = None):
|
||||
test_slug = slugify(name)
|
||||
with SessionLocal() as session:
|
||||
result = session.query(Tag).filter(Tag.slug == test_slug).one_or_none()
|
||||
@classmethod
|
||||
def get_ref(cls, match_value: str, session=None):
|
||||
if not session or not match_value:
|
||||
return None
|
||||
|
||||
if result:
|
||||
logger.debug("Tag exists, associating recipe")
|
||||
return result
|
||||
else:
|
||||
logger.debug("Tag doesn't exists, creating tag")
|
||||
return Tag(name=name)
|
||||
slug = slugify(match_value)
|
||||
|
||||
result = session.query(Tag).filter(Tag.slug == slug).one_or_none()
|
||||
if result:
|
||||
logger.debug("Category exists, associating recipe")
|
||||
return result
|
||||
else:
|
||||
logger.debug("Category doesn't exists, creating Category")
|
||||
return Tag(name=match_value)
|
||||
|
||||
@@ -69,7 +69,7 @@ def get_meal_plan(
|
||||
):
|
||||
""" Returns a single Meal Plan from the Database """
|
||||
|
||||
return db.meals.get(session, id, "uid")
|
||||
return db.meals.get(session, id)
|
||||
|
||||
|
||||
@router.post("/create", status_code=status.HTTP_201_CREATED)
|
||||
@@ -97,7 +97,7 @@ def update_meal_plan(
|
||||
):
|
||||
""" Updates a meal plan based off ID """
|
||||
set_mealplan_dates(meal_plan)
|
||||
processed_plan = MealPlanOut(uid=plan_id, **meal_plan.dict())
|
||||
processed_plan = MealPlanOut(id=plan_id, **meal_plan.dict())
|
||||
try:
|
||||
db.meals.update(session, plan_id, processed_plan.dict())
|
||||
background_tasks.add_task(
|
||||
|
||||
@@ -44,6 +44,6 @@ def get_shopping_list(
|
||||
|
||||
mealplan.shopping_list = created_list.id
|
||||
|
||||
db.meals.update(session, mealplan.uid, mealplan)
|
||||
db.meals.update(session, mealplan.id, mealplan)
|
||||
|
||||
return created_list
|
||||
|
||||
@@ -48,7 +48,7 @@ class MealPlanIn(CamelModel):
|
||||
|
||||
|
||||
class MealPlanOut(MealPlanIn):
|
||||
uid: int
|
||||
id: int
|
||||
shopping_list: Optional[int]
|
||||
|
||||
class Config:
|
||||
|
||||
@@ -140,15 +140,18 @@ class MigrationBase(BaseModel):
|
||||
return recipe_dict
|
||||
|
||||
def clean_recipe_dictionary(self, recipe_dict) -> Recipe:
|
||||
"""Calls the rewrite_alias function and the Cleaner.clean function on a
|
||||
dictionary and returns the result unpacked into a Recipe object"""
|
||||
"""
|
||||
Calls the rewrite_alias function and the Cleaner.clean function on a
|
||||
dictionary and returns the result unpacked into a Recipe object
|
||||
"""
|
||||
recipe_dict = self.rewrite_alias(recipe_dict)
|
||||
recipe_dict = cleaner.clean(recipe_dict, url=recipe_dict.get("org_url", None))
|
||||
|
||||
return Recipe(**recipe_dict)
|
||||
|
||||
def import_recipes_to_database(self, validated_recipes: list[Recipe]) -> None:
|
||||
"""Used as a single access point to process a list of Recipe objects into the
|
||||
"""
|
||||
Used as a single access point to process a list of Recipe objects into the
|
||||
database in a predictable way. If an error occurs the session is rolled back
|
||||
and the process will continue. All import information is appended to the
|
||||
'migration_report' attribute to be returned to the frontend for display.
|
||||
@@ -166,6 +169,7 @@ class MigrationBase(BaseModel):
|
||||
|
||||
except Exception as inst:
|
||||
exception = inst
|
||||
logger.error(inst)
|
||||
self.session.rollback()
|
||||
|
||||
import_status = MigrationImport(slug=recipe.slug, name=recipe.name, status=status, exception=str(exception))
|
||||
|
||||
Reference in New Issue
Block a user