Ejemplo n.º 1
0
Archivo: post.py Proyecto: hit9/zhiz
def update_post(id):
    body = request.form["body"]
    title = request.form["title"]
    title_pic = request.form["title_pic"]
    published = bool(int(request.form["published"]))

    post = Post.at(id).getone()

    published_old = bool(int(post.published))

    if not post.published:  # only non-published posts update this field
        post.published = published

    post.body = body
    post.title = title
    post.title_pic = title_pic

    rows_affected = post.save()

    if rows_affected >= 0:
        if not published_old and published:  # published
            flashx.success("Published successfully")
            return redirect(url_for("post", id=post.id))
        else:
            flashx.success("Saved successfully")
            if post.published:
                return redirect(url_for("post", id=post.id))

    else:
        flashx.error("Something wrong when updating post")
    return redirect(url_for("edit", id=post.id))
Ejemplo n.º 2
0
Archivo: post.py Proyecto: hit9/zhiz
def delete(id):
    query = Post.at(id).delete()
    rows_affected = query.execute()

    if rows_affected <= 0:
        flashx.error("Something wrong when deleting post")
        return redirect(url_for("edit", id=id))
    else:
        flashx.success("Delete post successfully")
        return redirect(url_for("write"))
Ejemplo n.º 3
0
Archivo: post.py Proyecto: hit9/zhiz
def create():
    body = request.form["body"]
    title = request.form["title"]
    title_pic = request.form["title_pic"]
    published = bool(int(request.form["published"]))

    if not title:
        flashx.warning("Empty title")
        return redirect(url_for("write"))

    post = Post.create(title=title, title_pic=title_pic, body=body, datetime=datetime.now(), published=published)
    if published:
        flashx.success("Published successfully")
        return redirect(url_for("post", id=post.id))
    else:
        flashx.success("Saved to drafts successfully")
        return redirect(url_for("edit", id=post.id))  # jump to edit url
Ejemplo n.º 4
0
def update_settings():

    name = request.form['name']
    description = request.form['description']
    disqus = request.form['disqus']

    blog = Blog.getone()

    if blog is None:  # insert
        blog = Blog.create(name=name, description=description, disqus=disqus)
        flashx.success('Create settings successfully')
    else:  # update
        blog.name = name
        blog.disqus = disqus
        blog.description = description
        blog.save()
        flashx.success('Save settings successfully')

    return redirect(url_for('settings'))
Ejemplo n.º 5
0
def update_password():
    password_now = request.form['password_now']
    password_new = request.form['password_new']
    password_new_repeat = request.form['password_new_repeat']

    if password_now and password_new and password_new_repeat:
        if password_new_repeat != password_new:
            flashx.warning('The two new passwords do not match')
        else:
            admin = Admin.getone()

            hashed_passwd_now = md5(password_now).hexdigest()

            if hashed_passwd_now != admin.passwd:
                flashx.warning('Incorrect password')
            else:
                admin.passwd = md5(password_new).hexdigest()
                admin.save()
                flashx.success('Save password successfully, please login again')
                return redirect(url_for('logout'))
    else:
        flashx.warning('Empty input!')
    return redirect(url_for('password'))
Ejemplo n.º 6
0
Archivo: author.py Proyecto: hit9/zhiz
def update_author():

    name = request.form['name']
    email = request.form['email']
    url = request.form['url']
    description = request.form['description']

    if not name or not email:
        flashx.warning('Empty input')

    else:
        author = Author.getone()

        if author is None:  # do a insert
            author = Author.create(name=name, email=email, url=url, description=description)
            flashx.success('Create author information successfully')
        else:  # do a save
            author.name = name
            author.email = email
            author.url = url
            author.description = description
            author.save()
            flashx.success('Save author information successfully')
    return redirect(url_for('author'))