Ejemplo n.º 1
0
def update_comment(comment_id, content=''):
    #if user is None:
    #raise Err('value:notfound', 'user', 'user not found.')
    content = content.strip()
    if not content:
        raise Err('value:invalid', 'content', 'content cannot be empty.')
    comment = Query(Comments).get(comment_id)
    if comment is None:
        raise Err('value:notfound', 'comment', 'comment not found.')
    comment.set('content', content)
    comment.save()
    return comment
Ejemplo n.º 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'))
Ejemplo n.º 3
0
def comment(blog_id, content=''):
    user = check_login()
    if user is None:
        raise Err('value:notfound', 'user', 'user not found.')
    content = content.strip()
    if not content:
        raise Err('value:invalid', 'content', 'content cannot be empty.')
    try:
        blog = Query(Blog).get(blog_id)
        comment = Comment(blog=blog, user=user, content=content)
        comment.save()
    except LeanCloudError, e:
        raise e
Ejemplo n.º 4
0
def update_blog(blog_id, name='', summary='', content=''):
    name = name.strip()
    summary = summary.strip()
    content = 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.')
    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
Ejemplo n.º 5
0
def sign_up(username, password, email):
    email = email.strip().lower()
    if not email or not _RE_EMAIL.match(email):
        raise Err('value:invalid', 'email', 'email cannot be empty.')
    user = User()
    user.set("username", username)
    user.set("password", password)
    user.set("email", email)
    try:
        user.sign_up()
    except LeanCloudError, e:
        raise e
Ejemplo n.º 6
0
def get_comments(blog_id):
    blog = None
    comments = None
    user = None
    try:
        blog = Query(Blog).equal_to("objectId", blog_id).first()
        if blog is None:
            raise Err('value:notfound', 'blog', 'blog not found.')
        try:
            comments = Query(Comments).equal_to(
                "blog", blog).descending('createdAt').find()
        except LeanCloudError, e:
            pass
    except LeanCloudError, e:
        if e.code == 101:  # 服务端对应的 Class 还没创建
            blog = {}
        else:
            raise e
Ejemplo n.º 7
0
def delete_comment(comment_id):
    comment = Query(Comments).get(comment_id)
    if comment is None:
        raise Err('value:notfound', 'comment', 'comment not found.')
    comment.destroy()
    return comment
Ejemplo n.º 8
0
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()
    return blog
Ejemplo n.º 9
0
def get_blog(blog_id):
    blog = Query(Blog).get(blog_id)
    if blog:
        return blog
    raise Err('value:notfound', 'blog', 'blog not found.')
Ejemplo n.º 10
0
def get_user(user_id):
    user = Query(User).get(user_id)
    if user:
        return user
    raise Err('value:notfound', 'user', 'user not found.')