Пример #1
0
def admin_post_edit(post_id: int):
    try:
        categories = CategoriesService.get_all_categories()
        authors = AuthorsService.get_all_authors()
        post = PostsService.get_post_by_id(post_id)
        if request.method == "GET":
            # Отрендерить шаблон admin_post.html для редактирования существующего поста
            return render_template("admin_post.html",
                                   categories=categories,
                                   authors=authors,
                                   post=post)
        elif request.method == "POST":
            preview = None
            fs = request.files.get("preview")
            if fs:
                preview = FilesService.save_file(fs)
            # Редактируем существующий пост
            edited_post = PostsService.edit_post_by_id(
                post_id,
                request.form.get("title"),
                request.form.get("category_id"),
                request.form.get("author_id"),
                request.form.get("body"),
            )
            return redirect(url_for("admin.admin_posts"))
    except PostsServiceNotFoundException:
        abort(404)
Пример #2
0
def admin_post_edit(post_id: int):
    categories = CategoriesService.get_all_categories()
    authors = AuthorsService.get_all_authors()
    post = PostsService.get_post_by_id(post_id)
    if request.method == "GET":
        # Отрендерить шаблон admin_post.html для редактирования существующего поста
        return render_template("admin_post_edit.html",
                               categories=categories,
                               authors=authors,
                               post=post)
    elif request.method == "POST":
        # Редактируем существующий пост
        edited_post = PostsService.edit_post_by_id(
            post_id,
            request.form.get("title"),
            request.form.get("category_id"),
            request.form.get("author_id"),
            request.form.get("body"),
        )
        return redirect(url_for("admin_posts"))