Example #1
0
def add():
    name = request.form['name'].strip()
    summary = request.form['summary'].strip()
    content = request.form['content'].strip()
    if not name:
        raise Err('value:invalid', 'name', 'name cannot be empty.')
    if not summary:
        raise Err('value:invalid', 'summary', 'summary cannot be empty.')
    if not content:
        raise Err('value:invalid', 'content', 'content cannot be empty.')
    blog = Blog(name=name, summary=summary, content=content, user=user)
    blog.save()
    return redirect(url_for('blogs.list'))
Example #2
0
def add():
    name = request.form['name'].strip()
    summary = request.form['summary'].strip()
    content = request.form['content'].strip()
    if not name:
        raise Err('value:invalid', 'name', 'name cannot be empty.')
    if not summary:
        raise Err('value:invalid', 'summary', 'summary cannot be empty.')
    if not content:
        raise Err('value:invalid', 'content', 'content cannot be empty.')
    blog = Blog(name=name, summary=summary, content=content, user=user)
    blog.save()
    return redirect(url_for('blogs.list'))
Example #3
0
        raise Err('value:invalid', 'name', 'name cannot be empty.')
    if not summary:
        raise Err('value:invalid', 'summary', 'summary cannot be empty.')
    if not content:
        raise Err('value:invalid', 'content', 'content cannot be empty.')
    user = check_login()
    #if user is None:
        #raise Err('value:notfound', 'user', 'user not found.')
    blog = None
    try:
        blog = Query(Blog).get(blog_id)
    except LeanCloudError, e:
        pass
    try:
        if blog is None:
            blog = Blog(name=name, summary=summary, content=content, user=user)
        else:
            blog.set('name', name)
            blog.set('summary', summary)
            blog.set('content', content)
        blog.save()
    except LeanCloudError, e:
        raise e
    return blog

@api
def delete_blog(blog_id):
    blog = Query(Blog).get(blog_id)
    if blog is None:
        raise Err('value:notfound', 'blog', 'blog not found.')
    blog.destroy()
Example #4
0
        raise Err('value:invalid', 'name', 'name cannot be empty.')
    if not summary:
        raise Err('value:invalid', 'summary', 'summary cannot be empty.')
    if not content:
        raise Err('value:invalid', 'content', 'content cannot be empty.')
    user = check_login()
    #if user is None:
    #raise Err('value:notfound', 'user', 'user not found.')
    blog = None
    try:
        blog = Query(Blog).get(blog_id)
    except LeanCloudError, e:
        pass
    try:
        if blog is None:
            blog = Blog(name=name, summary=summary, content=content, user=user)
        else:
            blog.set('name', name)
            blog.set('summary', summary)
            blog.set('content', content)
        blog.save()
    except LeanCloudError, e:
        raise e
    return blog


@api
def delete_blog(blog_id):
    blog = Query(Blog).get(blog_id)
    if blog is None:
        raise Err('value:notfound', 'blog', 'blog not found.')