mirror of
https://github.com/mealie-recipes/mealie.git
synced 2026-02-04 15:03:10 -05:00
[Feat] ✨ Migrate from Pages to Cookbooks (#664)
* feat: ✨ Add Description to Cookbooks * feat(frontend): ✨ Cookbook view page * feat(frontend): 💄 Add final UI touches * fix(backend): 🐛 Add get by slug or id * fix linting issue * test(backend): ✅ Update tests from pages -> cookbooks * refactor(backend): 🔥 Delete old page files Co-authored-by: hay-kot <hay-kot@pm.me>
This commit is contained in:
@@ -108,7 +108,6 @@ def backup_all(
|
||||
templates=None,
|
||||
export_recipes=True,
|
||||
export_settings=True,
|
||||
export_pages=True,
|
||||
export_users=True,
|
||||
export_groups=True,
|
||||
export_notifications=True,
|
||||
@@ -136,10 +135,6 @@ def backup_all(
|
||||
all_settings = db.settings.get_all(session)
|
||||
db_export.export_items(all_settings, "settings")
|
||||
|
||||
if export_pages:
|
||||
all_pages = db.custom_pages.get_all(session)
|
||||
db_export.export_items(all_pages, "pages")
|
||||
|
||||
if export_notifications:
|
||||
all_notifications = db.event_notifications.get_all(session)
|
||||
db_export.export_items(all_notifications, "notifications")
|
||||
|
||||
@@ -11,8 +11,6 @@ from mealie.core.config import app_dirs
|
||||
from mealie.db.database import db
|
||||
from mealie.schema.admin import (
|
||||
CommentImport,
|
||||
CustomPageImport,
|
||||
CustomPageOut,
|
||||
GroupImport,
|
||||
NotificationImport,
|
||||
RecipeImport,
|
||||
@@ -189,19 +187,6 @@ class ImportDatabase:
|
||||
|
||||
return [import_status]
|
||||
|
||||
def import_pages(self):
|
||||
pages_file = self.import_dir.joinpath("pages", "pages.json")
|
||||
pages = ImportDatabase.read_models_file(pages_file, CustomPageOut)
|
||||
|
||||
page_imports = []
|
||||
for page in pages:
|
||||
import_stats = self.import_model(
|
||||
db_table=db.custom_pages, model=page, return_model=CustomPageImport, name_attr="name", search_key="slug"
|
||||
)
|
||||
page_imports.append(import_stats)
|
||||
|
||||
return page_imports
|
||||
|
||||
def import_groups(self):
|
||||
groups_file = self.import_dir.joinpath("groups", "groups.json")
|
||||
groups = ImportDatabase.read_models_file(groups_file, UpdateGroup)
|
||||
@@ -326,7 +311,6 @@ def import_database(
|
||||
archive,
|
||||
import_recipes=True,
|
||||
import_settings=True,
|
||||
import_pages=True,
|
||||
import_users=True,
|
||||
import_groups=True,
|
||||
import_notifications=True,
|
||||
@@ -343,10 +327,6 @@ def import_database(
|
||||
if import_settings:
|
||||
settings_report = import_session.import_settings()
|
||||
|
||||
page_report = []
|
||||
if import_pages:
|
||||
page_report = import_session.import_pages()
|
||||
|
||||
group_report = []
|
||||
if import_groups:
|
||||
group_report = import_session.import_groups()
|
||||
@@ -367,7 +347,6 @@ def import_database(
|
||||
return {
|
||||
"recipeImports": recipe_report,
|
||||
"settingsImports": settings_report,
|
||||
"pageImports": page_report,
|
||||
"groupImports": group_report,
|
||||
"userImports": user_report,
|
||||
"notificationImports": notification_report,
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from fastapi import HTTPException, status
|
||||
|
||||
from mealie.core.root_logger import get_logger
|
||||
from mealie.schema.cookbook.cookbook import CreateCookBook, ReadCookBook, SaveCookBook
|
||||
from mealie.schema.cookbook.cookbook import CreateCookBook, ReadCookBook, RecipeCookBook, SaveCookBook
|
||||
from mealie.services.base_http_service.base_http_service import BaseHttpService
|
||||
from mealie.services.events import create_group_event
|
||||
|
||||
logger = get_logger(module=__name__)
|
||||
|
||||
|
||||
class CookbookService(BaseHttpService[str, str]):
|
||||
class CookbookService(BaseHttpService[int, str]):
|
||||
"""
|
||||
Class Methods:
|
||||
`read_existing`: Reads an existing recipe from the database.
|
||||
@@ -39,8 +41,17 @@ class CookbookService(BaseHttpService[str, str]):
|
||||
if self.cookbook.group_id != self.group_id:
|
||||
raise HTTPException(status.HTTP_403_FORBIDDEN)
|
||||
|
||||
def populate_cookbook(self, id):
|
||||
self.cookbook = self.db.cookbooks.get(self.session, id)
|
||||
def populate_cookbook(self, id: int | str):
|
||||
try:
|
||||
id = int(id)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if isinstance(id, int):
|
||||
self.cookbook = self.db.cookbooks.get_one(self.session, id, override_schema=RecipeCookBook)
|
||||
|
||||
else:
|
||||
self.cookbook = self.db.cookbooks.get_one(self.session, id, key="slug", override_schema=RecipeCookBook)
|
||||
|
||||
def get_all(self) -> list[ReadCookBook]:
|
||||
items = self.db.cookbooks.get(self.session, self.group_id, "group_id", limit=999)
|
||||
|
||||
@@ -134,7 +134,9 @@ def insideParenthesis(token, tokens):
|
||||
return True
|
||||
else:
|
||||
line = " ".join(tokens)
|
||||
return re.match(r".*\(.*" + re.escape(token) + ".*\).*", line) is not None
|
||||
return (
|
||||
re.match(r".*\(.*" + re.escape(token) + ".*\).*", line) is not None # noqa: W605 - invalid dscape sequence
|
||||
)
|
||||
|
||||
|
||||
def displayIngredient(ingredient):
|
||||
@@ -222,7 +224,7 @@ def import_data(lines):
|
||||
|
||||
# turn B-NAME/123 back into "name"
|
||||
tag, confidence = re.split(r"/", columns[-1], 1)
|
||||
tag = re.sub("^[BI]\-", "", tag).lower()
|
||||
tag = re.sub("^[BI]\-", "", tag).lower() # noqa: W605 - invalid dscape sequence
|
||||
|
||||
# ---- DISPLAY ----
|
||||
# build a structure which groups each token by its tag, so we can
|
||||
|
||||
Reference in New Issue
Block a user