mirror of
https://github.com/hay-kot/mealie.git
synced 2025-07-05 12:36:54 -07:00
chore: remove unused jinja export option (#5631)
This commit is contained in:
parent
50a986f331
commit
da3271f33f
10 changed files with 8 additions and 137 deletions
|
@ -1,24 +0,0 @@
|
|||
|
||||
|
||||

|
||||
|
||||
# {{ 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 }}
|
|
@ -1,5 +0,0 @@
|
|||
from pathlib import Path
|
||||
|
||||
CWD = Path(__file__).parent
|
||||
|
||||
recipes_markdown = CWD / "recipes.md"
|
|
@ -1,24 +0,0 @@
|
|||
|
||||
|
||||

|
||||
|
||||
# {{ 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 }}
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -18,28 +18,9 @@ def test_get_available_exports(api_client: TestClient, unique_user: TestUser) ->
|
|||
|
||||
as_json = response.json()
|
||||
|
||||
assert "recipes.md" in as_json["jinja2"]
|
||||
assert "raw" in as_json["json"]
|
||||
|
||||
|
||||
def test_render_jinja_template(api_client: TestClient, unique_user: TestUser) -> None:
|
||||
# Create Recipe
|
||||
recipe_name = random_string()
|
||||
response = api_client.post(api_routes.recipes, json={"name": recipe_name}, headers=unique_user.token)
|
||||
assert response.status_code == 201
|
||||
slug = response.json()
|
||||
|
||||
# Render Template
|
||||
response = api_client.get(
|
||||
api_routes.recipes_slug_exports(slug) + "?template_name=recipes.md", headers=unique_user.token
|
||||
)
|
||||
assert response.status_code == 200
|
||||
|
||||
# Assert Template is Rendered Correctly
|
||||
# TODO: More robust test
|
||||
assert f"# {recipe_name}" in response.text
|
||||
|
||||
|
||||
def test_get_recipe_as_zip(api_client: TestClient, unique_user: TestUser) -> None:
|
||||
# Create Recipe
|
||||
recipe_name = random_string()
|
||||
|
@ -61,13 +42,3 @@ def test_get_recipe_as_zip(api_client: TestClient, unique_user: TestUser) -> Non
|
|||
with zipfile.ZipFile(zip_file, "r") as zip_fp:
|
||||
with zip_fp.open(f"{slug}.json") as json_fp:
|
||||
assert json.loads(json_fp.read())["name"] == recipe_name
|
||||
|
||||
|
||||
# TODO: Allow users to upload templates to their own directory
|
||||
# def test_upload_template(api_client: TestClient, unique_user: TestUser) -> None:
|
||||
# assert False
|
||||
|
||||
|
||||
# # TODO: Allow users to upload templates to their own directory
|
||||
# def test_delete_template(api_client: TestClient, unique_user: TestUser) -> None:
|
||||
# assert False
|
||||
|
|
|
@ -3,6 +3,5 @@ from mealie.services.recipe.template_service import TemplateService, TemplateTyp
|
|||
|
||||
def test_recipe_export_types() -> None:
|
||||
ts = TemplateService()
|
||||
assert ts.template_type("recipes.md") == TemplateType.jinja2.value
|
||||
assert ts.template_type("raw") == TemplateType.json.value
|
||||
assert ts.template_type("zip") == TemplateType.zip.value
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue