コード例 #1
0
ファイル: recipe_crud_routes.py プロジェクト: wengtad/mealie
def delete_recipe(recipe_slug: str, db: Session = Depends(generate_session)):
    """ Deletes a recipe by slug """

    try:
        Recipe.delete(db, recipe_slug)
    except:
        raise HTTPException(
            status_code=404,
            detail=SnackResponse.error("Unable to Delete Recipe"))

    return SnackResponse.error(f"Recipe {recipe_slug} Deleted")
コード例 #2
0
def delete_backup(file_name: str):
    """ Removes a database backup from the file system """

    try:
        BACKUP_DIR.joinpath(file_name).unlink()
    except:
        HTTPException(
            status_code=400,
            detail=SnackResponse.error(
                "Unable to Delete Backup. See Log File"),
        )

    return SnackResponse.error(f"{file_name} Deleted")
コード例 #3
0
async def delete_migration_data(file_folder_name: str):
    """ Removes migration data from the file system """

    remove_path = MIGRATION_DIR.joinpath(file_folder_name)

    if remove_path.is_file():
        remove_path.unlink()
    elif remove_path.is_dir():
        shutil.rmtree(remove_path)
    else:
        SnackResponse.error("File/Folder not found.")

    return SnackResponse.info(f"Migration Data Remove: {remove_path.absolute()}")
コード例 #4
0
ファイル: tag_routes.py プロジェクト: thedeany/mealie
async def delete_recipe_tag(tag: str, session: Session = Depends(generate_session)):
    """Removes a recipe tag from the database. Deleting a
    tag does not impact a recipe. The tag will be removed
    from any recipes that contain it"""

    db.tags.delete(session, tag)

    return SnackResponse.error(f"Tag Deleted: {tag}")
コード例 #5
0
ファイル: backup_routes.py プロジェクト: richardmitic/mealie
def export_database(data: BackupJob):
    """Generates a backup of the recipe database in json format."""
    export_path = backup_all(data.tag, data.template)
    try:
        return SnackResponse.success("Backup Created at " + export_path)
    except:
        HTTPException(
            status_code=400,
            detail=SnackResponse.error("Error Creating Backup. See Log File"),
        )
コード例 #6
0
async def upload_nextcloud_zipfile(file_name: str):
    """ Upload a .zip File to later be imported into Mealie """
    file = BACKUP_DIR.joinpath(file_name)

    if file.is_file:
        return FileResponse(file,
                            media_type="application/octet-stream",
                            filename=file_name)
    else:
        return SnackResponse.error("No File Found")
コード例 #7
0
ファイル: setting_routes.py プロジェクト: djbr22/mealie
async def update_theme(theme_name: str, data: SiteTheme):
    """ Update a theme database entry """
    try:
        data.update_document()
    except:
        raise HTTPException(
            status_code=400,
            detail=SnackResponse.error("Unable to Update Theme"))

    return SnackResponse.success("Theme Updated")
コード例 #8
0
ファイル: setting_routes.py プロジェクト: sahlie1985/mealie
async def delete_theme(theme_name: str):
    """ Returns basic site Settings """
    try:
        SiteTheme.delete_theme(theme_name)
    except:
        raise HTTPException(
            status_code=400,
            detail=SnackResponse.error("Unable to Delete Theme"))

    return SnackResponse.success("Theme Deleted")
コード例 #9
0
ファイル: setting_routes.py プロジェクト: djbr22/mealie
async def delete_theme(theme_name: str):
    """ Deletes theme from the database """
    try:
        SiteTheme.delete_theme(theme_name)
    except:
        raise HTTPException(
            status_code=400,
            detail=SnackResponse.error("Unable to Delete Theme"))

    return SnackResponse.success("Theme Deleted")
コード例 #10
0
ファイル: setting_routes.py プロジェクト: djbr22/mealie
async def create_theme(data: SiteTheme):
    """ Creates a site color theme database entry """

    try:
        data.save_to_db()
    except:
        raise HTTPException(status_code=400,
                            detail=SnackResponse.error("Unable to Save Theme"))

    return SnackResponse.success("Theme Saved")
コード例 #11
0
async def delete_recipe_category(
    category: str, session: Session = Depends(generate_session)
):
    """Removes a recipe category from the database. Deleting a
    category does not impact a recipe. The category will be removed
    from any recipes that contain it"""

    db.categories.delete(session, category)

    return SnackResponse.error(f"Category Deleted: {category}")
コード例 #12
0
ファイル: recipe_routes.py プロジェクト: richardmitic/mealie
def delete_recipe(recipe_slug: str):
    """ Deletes a recipe by slug """

    try:
        Recipe.delete(recipe_slug)
    except:
        raise HTTPException(
            status_code=404, detail=SnackResponse.error("Unable to Delete Recipe")
        )

    return SnackResponse.success("Recipe Deleted")
コード例 #13
0
ファイル: migration_routes.py プロジェクト: wengtad/mealie
def import_nextcloud_directory(type: str,
                               file_name: str,
                               session: Session = Depends(generate_session)):
    """ Imports all the recipes in a given directory """
    file_path = MIGRATION_DIR.joinpath(type, file_name)
    if type == "nextcloud":
        return nextcloud_migrate(session, file_path)
    elif type == "chowdown":
        return chowdow_migrate(session, file_path)
    else:
        return SnackResponse.error("Incorrect Migration Type Selected")
コード例 #14
0
def upload_nextcloud_zipfile(archive: UploadFile = File(...)):
    """ Upload a .zip File to later be imported into Mealie """
    dest = MIGRATION_DIR.joinpath(archive.filename)

    with dest.open("wb") as buffer:
        shutil.copyfileobj(archive.file, buffer)

    if dest.is_file:
        return SnackResponse.success("Migration data uploaded")
    else:
        return SnackResponse.error("Failure uploading file")
コード例 #15
0
ファイル: backup_routes.py プロジェクト: grssmnn/mealie
async def export_database(data: BackupJob):

    try:
        export_path = export_db(data.tag, data.template)
    except:
        HTTPException(
            status_code=400,
            detail=SnackResponse.error("Error Creating Backup. See Log File"),
        )

    return SnackResponse.success("Backup Created at " + export_path)
コード例 #16
0
def upload_backup_zipfile(archive: UploadFile = File(...)):
    """ Upload a .zip File to later be imported into Mealie """
    dest = BACKUP_DIR.joinpath(archive.filename)

    with dest.open("wb") as buffer:
        shutil.copyfileobj(archive.file, buffer)

    if dest.is_file:
        return SnackResponse.success("Backup uploaded")
    else:
        return SnackResponse.error("Failure uploading file")
コード例 #17
0
ファイル: setting_routes.py プロジェクト: djbr22/mealie
async def update_settings(data: SiteSettings):
    """ Returns Site Settings """

    try:
        data.update()
    except:
        raise HTTPException(
            status_code=400,
            detail=SnackResponse.error("Unable to Save Settings"))

    scheduler.reschedule_webhooks()
    return SnackResponse.success("Settings Updated")
コード例 #18
0
async def export_database(data: BackupJob):
    """ Returns this weeks meal plan """

    try:
        export_db(data.tag, data.template)
    except:
        HTTPException(
            status_code=400,
            detail=SnackResponse.error("Error Creating Backup. See Log File"),
        )

    return SnackResponse.success("Backup Created in /data/backups")
コード例 #19
0
ファイル: backup_routes.py プロジェクト: grssmnn/mealie
async def delete_backup(backup_name: str):

    try:
        BACKUP_DIR.joinpath(backup_name).unlink()
    except:
        HTTPException(
            status_code=400,
            detail=SnackResponse.error(
                "Unable to Delete Backup. See Log File"),
        )

    return SnackResponse.success(f"{backup_name} Deleted")
コード例 #20
0
async def get_recipe_url(url: dict):
    """ Takes in a URL and Attempts to scrape data and load it into the database """

    url = url.get("url")

    try:
        slug = create_from_url(url)
    except:
        raise HTTPException(
            status_code=400, detail=SnackResponse.error("Unable to Parse URL")
        )

    return slug
コード例 #21
0
ファイル: meal_routes.py プロジェクト: djbr22/mealie
async def update_meal_plan(plan_id: str, meal_plan: MealPlan):
    """ Updates a meal plan based off ID """

    try:
        meal_plan.process_meals()
        meal_plan.update(plan_id)
    except:
        raise HTTPException(
            status_code=404,
            detail=SnackResponse.error("Unable to Update Mealplan"),
        )

    return SnackResponse.success("Mealplan Updated")
コード例 #22
0
def import_chowdown_recipes(repo: ChowdownURL):
    """ Import Chowsdown Recipes from Repo URL """
    try:
        report = chowdow_migrate(repo.url)
        return SnackResponse.success(
            "Recipes Imported from Git Repo, see report for failures.",
            additional_data=report,
        )
    except:
        return HTTPException(
            status_code=400,
            detail=SnackResponse.error(
                "Unable to Migrate Recipes. See Log for Details"),
        )
コード例 #23
0
def export_database(data: BackupJob,
                    session: Session = Depends(generate_session)):
    """Generates a backup of the recipe database in json format."""
    export_path = backup_all(
        session=session,
        tag=data.tag,
        templates=data.templates,
        export_recipes=data.options.recipes,
        export_settings=data.options.settings,
        export_themes=data.options.themes,
    )
    try:
        return SnackResponse.success("Backup Created at " + export_path)
    except:
        HTTPException(
            status_code=400,
            detail=SnackResponse.error("Error Creating Backup. See Log File"),
        )
コード例 #24
0
def delete_meal_plan(plan_id, session: Session = Depends(generate_session)):
    """ Removes a meal plan from the database """

    MealPlan.delete(session, plan_id)

    return SnackResponse.error("Mealplan Deleted")
コード例 #25
0
def delete_theme(theme_name: str,
                 session: Session = Depends(generate_session)):
    """ Deletes theme from the database """
    db.themes.delete(session, theme_name)

    return SnackResponse.error(f"Theme Deleted: {theme_name}")