Add optional subtitle to recipes, display under title, omit from TOC
This commit is contained in:
+26
-11
@@ -291,6 +291,13 @@ def init_db():
|
||||
if not cursor.fetchone():
|
||||
cursor.execute("ALTER TABLE recipes ADD COLUMN printed_at DATETIME NULL DEFAULT NULL AFTER image_url")
|
||||
|
||||
cursor.execute("""
|
||||
SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_SCHEMA = %s AND TABLE_NAME = 'recipes' AND COLUMN_NAME = 'subtitle'
|
||||
""", (MARIADB_NAME,))
|
||||
if not cursor.fetchone():
|
||||
cursor.execute("ALTER TABLE recipes ADD COLUMN subtitle VARCHAR(255) DEFAULT '' AFTER title")
|
||||
|
||||
cursor.execute("""
|
||||
SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_SCHEMA = %s AND TABLE_NAME = 'recipes' AND COLUMN_NAME = 'has_portion_table'
|
||||
@@ -375,6 +382,7 @@ def init_db():
|
||||
CREATE TABLE IF NOT EXISTS recipes (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
title TEXT NOT NULL,
|
||||
subtitle TEXT DEFAULT '',
|
||||
category TEXT NOT NULL,
|
||||
chapter_number INTEGER NOT NULL,
|
||||
effort TEXT NOT NULL DEFAULT 'mittel',
|
||||
@@ -395,6 +403,8 @@ def init_db():
|
||||
# Migration check for SQLite
|
||||
cursor.execute("PRAGMA table_info(recipes)")
|
||||
existing_cols = [c[1] for c in cursor.fetchall()]
|
||||
if "subtitle" not in existing_cols:
|
||||
cursor.execute("ALTER TABLE recipes ADD COLUMN subtitle TEXT DEFAULT ''")
|
||||
if "source" not in existing_cols:
|
||||
cursor.execute("ALTER TABLE recipes ADD COLUMN source TEXT DEFAULT ''")
|
||||
if "printed_at" not in existing_cols:
|
||||
@@ -713,9 +723,11 @@ def add_recipe(
|
||||
source: str = "",
|
||||
image_url: str = "",
|
||||
printed_at: Optional[str] = None,
|
||||
has_portion_table: int = 0
|
||||
has_portion_table: int = 0,
|
||||
subtitle: str = ""
|
||||
) -> Dict[str, Any]:
|
||||
title = title.strip()
|
||||
subtitle = (subtitle or "").strip()
|
||||
category = category.strip()
|
||||
effort = effort.strip().lower()
|
||||
source = source.strip()
|
||||
@@ -732,10 +744,10 @@ def add_recipe(
|
||||
|
||||
res = execute_query(
|
||||
"""
|
||||
INSERT INTO recipes (title, category, chapter_number, effort, prep_time, cook_time, portions, has_portion_table, ingredients, instructions, notes, source, image_url, printed_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
INSERT INTO recipes (title, subtitle, category, chapter_number, effort, prep_time, cook_time, portions, has_portion_table, ingredients, instructions, notes, source, image_url, printed_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
""",
|
||||
(title, category, chapter_number, effort, prep_time, cook_time, portions, int(bool(has_portion_table)), ingredients, instructions, notes, source, image_url, printed_at),
|
||||
(title, subtitle, category, chapter_number, effort, prep_time, cook_time, portions, int(bool(has_portion_table)), ingredients, instructions, notes, source, image_url, printed_at),
|
||||
fetch="none",
|
||||
commit=True
|
||||
)
|
||||
@@ -758,7 +770,8 @@ def update_recipe(
|
||||
source: str = "",
|
||||
image_url: Optional[str] = None,
|
||||
printed_at: Optional[str] = None,
|
||||
has_portion_table: Optional[int] = None
|
||||
has_portion_table: Optional[int] = None,
|
||||
subtitle: Optional[str] = None
|
||||
) -> Dict[str, Any]:
|
||||
title = title.strip()
|
||||
category = category.strip()
|
||||
@@ -772,6 +785,8 @@ def update_recipe(
|
||||
if not existing:
|
||||
raise KeyError(f"Rezept #{recipe_id} nicht gefunden.")
|
||||
|
||||
use_subtitle = (subtitle if subtitle is not None else existing.get("subtitle", "")).strip()
|
||||
|
||||
instructions = clean_instructions_text(instructions)
|
||||
|
||||
use_portion_table = int(bool(has_portion_table)) if has_portion_table is not None else existing.get("has_portion_table", 0)
|
||||
@@ -779,17 +794,17 @@ def update_recipe(
|
||||
if image_url is not None:
|
||||
query = """
|
||||
UPDATE recipes
|
||||
SET title = ?, category = ?, chapter_number = ?, effort = ?, prep_time = ?, cook_time = ?, portions = ?, has_portion_table = ?, ingredients = ?, instructions = ?, notes = ?, source = ?, image_url = ?, printed_at = ?
|
||||
SET title = ?, subtitle = ?, category = ?, chapter_number = ?, effort = ?, prep_time = ?, cook_time = ?, portions = ?, has_portion_table = ?, ingredients = ?, instructions = ?, notes = ?, source = ?, image_url = ?, printed_at = ?
|
||||
WHERE id = ?
|
||||
"""
|
||||
params = (title, category, chapter_number, effort, prep_time, cook_time, portions, use_portion_table, ingredients, instructions, notes, source, image_url, printed_at, recipe_id)
|
||||
params = (title, use_subtitle, category, chapter_number, effort, prep_time, cook_time, portions, use_portion_table, ingredients, instructions, notes, source, image_url, printed_at, recipe_id)
|
||||
else:
|
||||
query = """
|
||||
UPDATE recipes
|
||||
SET title = ?, category = ?, chapter_number = ?, effort = ?, prep_time = ?, cook_time = ?, portions = ?, has_portion_table = ?, ingredients = ?, instructions = ?, notes = ?, source = ?, printed_at = ?
|
||||
SET title = ?, subtitle = ?, category = ?, chapter_number = ?, effort = ?, prep_time = ?, cook_time = ?, portions = ?, has_portion_table = ?, ingredients = ?, instructions = ?, notes = ?, source = ?, printed_at = ?
|
||||
WHERE id = ?
|
||||
"""
|
||||
params = (title, category, chapter_number, effort, prep_time, cook_time, portions, use_portion_table, ingredients, instructions, notes, source, printed_at, recipe_id)
|
||||
params = (title, use_subtitle, category, chapter_number, effort, prep_time, cook_time, portions, use_portion_table, ingredients, instructions, notes, source, printed_at, recipe_id)
|
||||
|
||||
res = execute_query(query, params, fetch="none", commit=True)
|
||||
return get_recipe(recipe_id)
|
||||
@@ -826,9 +841,9 @@ def get_all_recipes(
|
||||
params.append(category.strip())
|
||||
|
||||
if search and search.strip():
|
||||
query += " AND (title LIKE ? OR ingredients LIKE ? OR instructions LIKE ?)"
|
||||
query += " AND (title LIKE ? OR subtitle LIKE ? OR ingredients LIKE ? OR instructions LIKE ?)"
|
||||
s = f"%{search.strip()}%"
|
||||
params.extend([s, s, s])
|
||||
params.extend([s, s, s, s])
|
||||
|
||||
if printed_status == "unprinted":
|
||||
query += " AND printed_at IS NULL"
|
||||
|
||||
Reference in New Issue
Block a user