chore: remove unused jinja export option (#5631)

This commit is contained in:
Hayden
2025-07-04 19:45:56 -05:00
committed by GitHub
parent 50a986f331
commit da3271f33f
10 changed files with 8 additions and 137 deletions

View File

@@ -1,5 +0,0 @@
from pathlib import Path
CWD = Path(__file__).parent
recipes_markdown = CWD / "recipes.md"

View File

@@ -1,24 +0,0 @@
![Recipe Image](../../images/{{ recipe.slug }}/original.jpg)
# {{ recipe.name }}
{{ recipe.description }}
## Ingredients
{% for ingredient in recipe.recipeIngredient %}
- [ ] {{ ingredient }} {% endfor %}
## Instructions
{% for step in recipe.recipeInstructions %}
- [ ] {{ step.text }} {% endfor %}
{% for note in recipe.notes %}
**{{ note.title }}:** {{ note.text }}
{% endfor %}
---
Tags: {{ recipe.tags }}
Categories: {{ recipe.categories }}
Original URL: {{ recipe.orgURL }}

View File

@@ -1,8 +1,5 @@
import shutil
from pathlib import Path
from mealie.assets import templates
class AppDirectories:
def __init__(self, data_dir: Path) -> None:
@@ -38,9 +35,3 @@ class AppDirectories:
for dir in required_dirs:
dir.mkdir(parents=True, exist_ok=True)
# Bootstrap Templates
markdown_template = self.TEMPLATE_DIR.joinpath("recipes.md")
if not markdown_template.exists():
shutil.copyfile(templates.recipes_markdown, markdown_template)

View File

@@ -13,7 +13,7 @@ TRANSLATIONS = CWD / "messages"
class Translator(Protocol):
@abstractmethod
def t(self, key, default=None, **kwargs):
def t(self, key, default=None, **kwargs) -> str:
pass

View File

@@ -32,7 +32,6 @@ class JSONBytes(JSONResponse):
class FormatResponse(BaseModel):
jjson: list[str] = Field(..., alias="json")
zip: list[str]
jinja2: list[str]
class BaseRecipeController(BaseCrudController):

View File

@@ -1,4 +1,5 @@
import shutil
from uuid import uuid4
from fastapi import File, HTTPException, UploadFile, status
from pydantic import UUID4
@@ -24,7 +25,10 @@ class UserImageController(BaseUserController):
"""Updates a User Image"""
with get_temporary_path() as temp_path:
assert_user_change_allowed(id, self.user, self.user)
temp_img = temp_path.joinpath(profile.filename)
# use a generated uuid and ignore the filename so we don't
# need to worry about sanitizing user inputs.
temp_img = temp_path.joinpath(str(uuid4()))
with temp_img.open("wb") as buffer:
shutil.copyfileobj(profile.file, buffer)

View File

@@ -2,8 +2,6 @@ import enum
from pathlib import Path
from zipfile import ZipFile
from jinja2 import Template
from mealie.schema.recipe import Recipe
from mealie.schema.recipe.recipe_image_types import RecipeImageTypes
from mealie.services._base_service import BaseService
@@ -11,7 +9,6 @@ from mealie.services._base_service import BaseService
class TemplateType(str, enum.Enum):
json = "json"
jinja2 = "jinja2"
zip = "zip"
@@ -32,7 +29,6 @@ class TemplateService(BaseService):
Returns a list of all templates available to render.
"""
return {
TemplateType.jinja2.value: [x.name for x in self.directories.TEMPLATE_DIR.iterdir() if x.is_file()],
TemplateType.json.value: ["raw"],
TemplateType.zip.value: ["zip"],
}
@@ -65,16 +61,13 @@ class TemplateService(BaseService):
Args:
t_type (TemplateType): The type of template to render
recipe (Recipe): The recipe to render
template (str): The template to render **Required for Jinja2 Templates**
template (str): The template to render
"""
t_type = self.template_type(template)
if t_type == TemplateType.json:
return self._render_json(recipe)
if t_type == TemplateType.jinja2:
return self._render_jinja2(recipe, template)
if t_type == TemplateType.zip:
return self._render_zip(recipe)
@@ -96,41 +89,8 @@ class TemplateService(BaseService):
return save_path
def _render_jinja2(self, recipe: Recipe, j2_template: str | None = None) -> Path:
"""
Renders a Jinja2 Template in a temporary directory and returns
the path to the file.
"""
self.__check_temp(self._render_jinja2)
if j2_template is None:
raise ValueError("Template must be provided for method _render_jinja2")
j2_path: Path = self.directories.TEMPLATE_DIR / j2_template
if not j2_path.is_file():
raise FileNotFoundError(f"Template '{j2_path}' not found.")
with open(j2_path) as f:
template_text = f.read()
template = Template(template_text)
rendered_text = template.render(recipe=recipe.model_dump(by_alias=True))
save_name = f"{recipe.slug}{j2_path.suffix}"
if self.temp is None:
raise ValueError("Temporary directory must be provided for method _render_jinja2")
save_path = self.temp.joinpath(save_name)
with open(save_path, "w") as f:
f.write(rendered_text)
return save_path
def _render_zip(self, recipe: Recipe) -> Path:
self.__check_temp(self._render_jinja2)
self.__check_temp(self._render_zip)
image_asset = recipe.image_dir.joinpath(RecipeImageTypes.original.value)