def decorate(self, post_id=None):
     post = None
     if post_id:
         post = BlogPost.get_by_id(int(post_id))
         if not post:
             raise NotFound
     return fun(self, post)
Ejemplo n.º 2
0
def post_delete(request, post_id):
	post = BlogPost.get_by_id(int(post_id))
	user = users.get_current_user()
	if request.method == "POST" and post.author == user.email():
		post.key.delete()
		return redirect("home")
	else:
		return redirect("forbidden")
Ejemplo n.º 3
0
def post_delete(request, post_id):
    post = BlogPost.get_by_id(int(post_id))
    user = users.get_current_user()
    if request.method == "POST" and post.author == user.email():
        post.key.delete()
        return redirect("home")
    else:
        return redirect("forbidden")
 def generate_resource(cls, post, resource):
     from blog.models import BlogPost
     if not post:
         post = BlogPost.get_by_id(resource)
     else:
         assert resource == post.key().id()
     template_vals = {
         'post': post,
         'config': config,
     }
     template_name = "blog/themes/%s/post.html" % config.theme
     rendered = utils.render_template(template_name, template_vals)
     StaticContent.set(post.path, rendered, config.html_mime_type)
Ejemplo n.º 5
0
def post_edit(request, post_id):
	post = BlogPost.get_by_id(int(post_id))
	user = users.get_current_user()
	if request.method == "GET" and post.author == user.email():
		form = BlogPostForm({"title": post.title, "content": post.content})
		params = {"form": form, "post": post}
		return blog_render(request, "post_edit.html", params)
	elif request.method == "POST" and post.author == user.email():
		form = BlogPostForm(request.POST)

		if form.is_valid():
			BlogPost.edit(post_id=int(post_id),
			              title=form.cleaned_data["title"],
			              content=form.cleaned_data["content"])
		else:
			params = {"form": form}
			return blog_render(request, "post_add.html", params)

		return redirect("home")
	else:
		return redirect("forbidden")
Ejemplo n.º 6
0
def post_edit(request, post_id):
    post = BlogPost.get_by_id(int(post_id))
    user = users.get_current_user()
    if request.method == "GET" and post.author == user.email():
        form = BlogPostForm({"title": post.title, "content": post.content})
        params = {"form": form, "post": post}
        return blog_render(request, "post_edit.html", params)
    elif request.method == "POST" and post.author == user.email():
        form = BlogPostForm(request.POST)

        if form.is_valid():
            BlogPost.edit(post_id=int(post_id),
                          title=form.cleaned_data["title"],
                          content=form.cleaned_data["content"])
        else:
            params = {"form": form}
            return blog_render(request, "post_add.html", params)

        return redirect("home")
    else:
        return redirect("forbidden")
Ejemplo n.º 7
0
def post_view(request, post_id):
	post = BlogPost.get_by_id(int(post_id))
	params = {"post": post}
	return blog_render(request, "post_view.html", params)
Ejemplo n.º 8
0
def get_blog_post(blog_post_id):
    return BlogPost.get_by_id(int(blog_post_id))
Ejemplo n.º 9
0
def post_view(request, post_id):
    post = BlogPost.get_by_id(int(post_id))
    params = {"post": post}
    return blog_render(request, "post_view.html", params)