示例#1
0
def create_post(form):
    """
	Creates and saves a new post.
	When a post is created, it's put at cache (by key) and the cache for all posts/drafts
	is cleaned.
	"""
    slug = slugify(form["slug"]) if (len(form["slug"]) > 0) else slugify(form["title"])
    tags = __strip_tags(form["tags"].split(",")) if (len(form["tags"]) > 0) else []
    striped = strip_html_code(form["content"])
    desc = form["desc"]
    as_draft = form.has_key("draft")
    html = bbcode_to_html(striped)
    post = Post(
        title=form["title"],
        slug=slug,
        tags=tags,
        desc=desc,
        author=users.get_current_user(),
        coded_content=striped,
        html_content=html,
        as_draft=as_draft,
    )
    post.put()
    memcache.set(str(post.key()), post)
    memcache.delete_multi(["all_posts_10", "all_drafts_10"])
    update_sitemap()
    twit_post(str(post.key()))
    return post
示例#2
0
def update_post(form):
    """
	Updates an existent post. Post is identified by it unique key
	When a post is updated, it's put at cache (by key) and the cache for all posts/drafts
	is cleaned.
	"""
    post = memcache.get(form["key"])
    if not post:
        post = Post.all().filter("__key__ =", Key(form["key"])).get()
    if post.slug != slugify(form["slug"]):
        memcache.delete(post.slug)
    post.title = form["title"]
    post.tags = __strip_tags(form["tags"].split(",")) if (len(form["tags"]) > 0) else []
    post.slug = slugify(form["slug"]) if (len(form["slug"]) > 0) else slugify(form["title"])
    post.desc = form["desc"]
    post.coded_content = strip_html_code(form["content"])
    post.html_content = bbcode_to_html(post.coded_content)
    post.as_draft = form.has_key("draft")
    post.put()  # todo: try, catch
    memcache.set(str(post.key()), post)
    memcache.delete_multi(["all_posts_10", "all_drafts_10", post.slug])
    update_sitemap()
    # remover memcache tag
    return post