def get(self, slug): tag = find_or_fail(Tag, Tag.slug == slug) page = request.args.get("page") or 1 return render_template( "posts/tagged_posts.html", tag=tag, page=page, title=tag.name )
def patch(self, user_id): user = find_or_fail(User, user_id == User.id) if not self.has_permission(user): abort(403) form = UpdateAccountForm(user_being_edited=user) if form.validate_on_submit(): updated_user = self.update_user(user, form) return jsonify( { "success": True, "user": { "username": updated_user.username, "email": updated_user.email, "first_name": updated_user.first_name, "last_name": updated_user.last_name, }, } ) else: return jsonify(errors=form.errors), 422 return "true"
def patch(self, page_id): page = find_or_fail(Page, Page.id == page_id) form = SavePageForm(page) if form.validate_on_submit(): revision = PageRevision(page_id=page_id, revision=page.to_json()) db.session.add(revision) page.title = form.title.data page.slug = slugify(form.slug.data) page.body = form.body.data page.primary_image_id = form.primary_image_id.data page.images = Image.query.filter( Image.id.in_(form.uploaded_images.data)).all() db.session.commit() return jsonify({ "action": "edit", "success": True, "page": page, "images": form.uploaded_images.data, }) else: return jsonify(errors=form.errors), 422
def patch(self, page_id): page = find_or_fail(Page, Page.id == page_id) form = SavePageForm(page) if form.validate_on_submit(): revision = PageRevision(page_id=page_id, revision=page.to_json()) db.session.add(revision) page.title = form.title.data page.slug = slugify(form.slug.data) page.body = form.body.data page.primary_image_id = form.primary_image_id.data page.images = Image.query.filter( Image.id.in_(form.uploaded_images.data) ).all() db.session.commit() return jsonify( { "action": "edit", "success": True, "page": page, "images": form.uploaded_images.data, } ) else: return jsonify(errors=form.errors), 422
def get(self, post_id): post = find_or_fail(Post, Post.id == post_id) if not post.editable: abort(403) return render_template("posts/edit.html", post_id=post_id, title="Edit Post")
def get(self, slug): tag = find_or_fail(Tag, Tag.slug == slug) page = request.args.get("page") or 1 return render_template("posts/tagged_posts.html", tag=tag, page=page, title=tag.name)
def delete(self, page_id): page = find_or_fail(Page, Page.id == page_id) db.session.delete(page) db.session.commit() flash("Page successfully deleted.") return jsonify({"action": "delete", "success": True, "page": page})
def get(self, post_id): post = find_or_fail(Post, Post.id == post_id) if not post.editable: abort(403) revisions = [dejsonify_revision(revision) for revision in post.revisions] return jsonify({"status": "success", "data": revisions, "parent": post})
def delete(self, page_id): page = find_or_fail(Page, Page.id == page_id) db.session.delete(page) db.session.commit() flash("Page successfully deleted.") return jsonify({"action": "delete", "success": True, "page": page})
def get(self, post_id): post = find_or_fail(Post, Post.id == post_id) if not post.editable: abort(403) return render_template("posts/edit.html", post_id=post_id, title="Edit Post")
def get(self, page_id): page = find_or_fail(Page, Page.id == page_id) revisions = [ dejsonify_revision(revision) for revision in page.revisions ] return jsonify({ "status": "success", "data": revisions, "parent": page })
def delete(self, post_id): post = find_or_fail(Post, Post.id == post_id) if not post.editable: abort(403) db.session.delete(post) db.session.commit() flash("Post successfully deleted.") return jsonify({"action": "delete", "success": True, "post": post})
def delete(self, post_id): post = find_or_fail(Post, Post.id == post_id) if not post.editable: abort(403) db.session.delete(post) db.session.commit() flash("Post successfully deleted.") return jsonify({"action": "delete", "success": True, "post": post})
def get(self, slug): tag = find_or_fail(Tag, Tag.slug == slug) per_page = int(current_app.config["POSTS_PER_PAGE"]) page = int(request.args.get("page")) if request.args.get("page") else 1 query = (Post.query.filter(Post.published_at <= now()).filter( Post.tags.any(slug=slug)).order_by(desc("published_at"))) return paginated_json_response(query=query, per_page=per_page, page=page)
def get(self, slug): tag = find_or_fail(Tag, Tag.slug == slug) per_page = int(current_app.config["POSTS_PER_PAGE"]) page = int(request.args.get("page")) if request.args.get("page") else 1 query = ( Post.query.filter(Post.published_at <= now()) .filter(Post.tags.any(slug=slug)) .order_by(desc("published_at")) ) return paginated_json_response(query=query, per_page=per_page, page=page)
def get(self, post_id): post = find_or_fail(Post, Post.id == post_id) if not post.editable: abort(403) revisions = [ dejsonify_revision(revision) for revision in post.revisions ] return jsonify({ "status": "success", "data": revisions, "parent": post })
def delete(self, image_id): image = find_or_fail(Image, Image.id == image_id) db.session.delete(image) db.session.commit() try: if image.provider == "b2": delete_from_b2(image.path, image.bucket) elif image.provider == "s3": delete_from_s3(image.path, image.bucket) else: delete_from_local(image.path, image.bucket) except: pass return jsonify({"data": {"image": image}})
def patch(self, post_id): post = find_or_fail(Post, Post.id == post_id) if not post.editable: abort(403) form = SavePostForm(post) if form.validate_on_submit(): revision = PostRevision(post_id=post_id, revision=post.to_json()) db.session.add(revision) post.title = form.title.data post.body = form.body.data post.primary_image_id = form.primary_image_id.data if form.published_at.data and not post.published_at: post.published_at = datetime.now() elif form.published_at.data and post.published_at: post.published_at = form.published_at.data elif not form.published_at.data and post.published_at: post.published_at = None if not form.slug.data and post.published_at: post.slug = post.generate_slug(form.title.data, form.published_at.data) elif form.slug.data: post.slug = slugify(form.slug.data) post.images = Image.query.filter( Image.id.in_(form.uploaded_images.data) ).all() post.tags = Tag.query.filter(Tag.id.in_(form.tags.data)).all() db.session.commit() return jsonify( { "action": "edit", "success": True, "post": post, "images": form.uploaded_images.data, } ) else: return jsonify(errors=form.errors), 422
def patch(self, post_id): post = find_or_fail(Post, Post.id == post_id) if not post.editable: abort(403) form = SavePostForm(post) if form.validate_on_submit(): revision = PostRevision(post_id=post_id, revision=post.to_json()) db.session.add(revision) post.title = form.title.data post.body = form.body.data post.primary_image_id = form.primary_image_id.data if form.published_at.data and not post.published_at: post.published_at = datetime.now() elif form.published_at.data and post.published_at: post.published_at = form.published_at.data elif not form.published_at.data and post.published_at: post.published_at = None if not form.slug.data and post.published_at: post.slug = post.generate_slug(form.title.data, form.published_at.data) elif form.slug.data: post.slug = slugify(form.slug.data) post.images = Image.query.filter( Image.id.in_(form.uploaded_images.data)).all() post.tags = Tag.query.filter(Tag.id.in_(form.tags.data)).all() db.session.commit() return jsonify({ "action": "edit", "success": True, "post": post, "images": form.uploaded_images.data, }) else: return jsonify(errors=form.errors), 422
def patch(self, user_id): user = find_or_fail(User, user_id == User.id) if not self.has_permission(user): abort(403) form = UpdateAccountForm(user_being_edited=user) if form.validate_on_submit(): updated_user = self.update_user(user, form) return jsonify({ "success": True, "user": { "username": updated_user.username, "email": updated_user.email, "first_name": updated_user.first_name, "last_name": updated_user.last_name, }, }) else: return jsonify(errors=form.errors), 422 return "true"
def get(self, page_id): page = find_or_fail(Page, Page.id == page_id) revisions = [dejsonify_revision(revision) for revision in page.revisions] return jsonify({"status": "success", "data": revisions, "parent": page})
def get(self, slug): page = find_or_fail(Page, Page.slug == slug) return render_template("pages/show.html", title=page.title, page=page)