mealie/mealie/services/exporter/recipe_exporter.py
Hayden 3c2744a3da
improve developer tooling (backend) (#1051)
* add basic pre-commit file

* add flake8

* add isort

* add pep585-upgrade (typing upgrades)

* use namespace for import

* add mypy

* update ci for backend

* flake8 scope

* fix version format

* update makefile

* disable strict option (temporary)

* fix mypy issues

* upgrade type hints (pre-commit)

* add vscode typing check

* add types to dev deps

* remote container draft

* update setup script

* update compose version

* run setup on create

* dev containers update

* remove unused pages

* update setup tips

* expose ports

* Update pre-commit to include flask8-print (#1053)

* Add in flake8-print to pre-commit

* pin version of flake8-print

* formatting

* update getting strated docs

* add mypy to pre-commit

* purge .mypy_cache on clean

* drop mypy

Co-authored-by: zackbcom <zackbcom@users.noreply.github.com>
2022-03-15 15:01:56 -08:00

42 lines
1.4 KiB
Python

from collections.abc import Iterator
from uuid import UUID
from mealie.repos.all_repositories import AllRepositories
from mealie.schema.recipe import Recipe
from ._abc_exporter import ABCExporter, ExportedItem
class RecipeExporter(ABCExporter):
def __init__(self, db: AllRepositories, group_id: UUID, recipes: list[str]) -> None:
"""
RecipeExporter is used to export a list of recipes to a zip file. The zip
file is then saved to a temporary directory and then available for a one-time
download.
Args:
db (Database):
group_id (int):
recipes (list[str]): Recipe Slugs
"""
super().__init__(db, group_id)
self.recipes = recipes
@property
def destination_dir(self) -> str:
return "recipes"
def items(self) -> Iterator[ExportedItem]:
for slug in self.recipes:
yield ExportedItem(
name=slug,
model=self.db.recipes.multi_query({"slug": slug, "group_id": self.group_id}, limit=1)[0],
)
def _post_export_hook(self, item: Recipe) -> None:
"""Copy recipe directory contents into the zip folder"""
recipe_dir = item.directory
if recipe_dir.exists() and self.write_dir_to_zip:
self.write_dir_to_zip(recipe_dir, f"{self.destination_dir}/{item.slug}", {".json"})