Example #1
0
def user_del(id=None):
    user = User.query.get_or_404(int(id))
    db.session().delete(user)
    db.session().commit()
    flash("User has been deleted", "ok")
    oplog = Oplog(admin_id=session["admin_id"],
                  reason="deleted user %s" % user.name,
                  addtime=db.func.current_timestamp())
    db.session().add(oplog)
    db.session().commit()
    return redirect(url_for('admin.user_list', page=1))
Example #2
0
def comment_del(id=None):
    comment = Comment.query.get_or_404(int(id))
    db.session().delete(comment)
    db.session().commit()
    flash("Comment has been deleted", "ok")
    oplog = Oplog(admin_id=session["admin_id"],
                  reason="deleted comment %s" % comment.content,
                  addtime=db.func.current_timestamp())
    db.session().add(oplog)
    db.session().commit()
    return redirect(url_for('admin.comment_list', page=1))
Example #3
0
def art_del(id=None):
    art = Art.query.get_or_404(int(id))
    db.session().delete(art)
    db.session().commit()
    flash("Article is deleted", "ok")
    oplog = Oplog(admin_id=session["admin_id"],
                  reason="deleted article %s" % art.title,
                  addtime=db.func.current_timestamp())
    db.session().add(oplog)
    db.session().commit()
    return redirect(url_for('admin.art_list', page=1))
Example #4
0
def tag_del(id=None):
    art_count = Art.query.filter_by(tag_id=id).count()
    if art_count != 0:
        flash("Tag cannot be deleted, because it's related to an article",
              "err")
    else:
        tag = Tag.query.filter_by(id=id).first_or_404()
        db.session().delete(tag)
        db.session().commit()
        flash("Tag has been deleted successfully", "ok")
        oplog = Oplog(admin_id=session["admin_id"],
                      reason="deleted tag %s" % tag.name,
                      addtime=db.func.current_timestamp())
        db.session().add(oplog)
        db.session().commit()
    return redirect(url_for('admin.tag_list', page=1))
Example #5
0
def tag_add():
    form = TagForm()
    if form.validate_on_submit():
        data = form.data
        tag = Tag.query.filter_by(name=data["name"]).count()
        if tag > 0:
            flash("This tag is already existed", "err")
            return redirect(url_for('admin.tag_add'))
        tag = Tag(name=data["name"], addtime=db.func.current_timestamp())
        db.session().add(tag)
        db.session().commit()
        flash("Tag is saved successfully", "ok")
        oplog = Oplog(admin_id=session["admin_id"],
                      reason="added tag %s" % data["name"],
                      addtime=db.func.current_timestamp())
        db.session().add(oplog)
        db.session().commit()
        redirect(url_for('admin.tag_add'))
    return render_template("admin/tag_add.html", form=form)
Example #6
0
def art_add():
    form = ArtForm()
    if form.validate_on_submit():
        data = form.data
        art = Art(title=data["title"],
                  text=data["text"],
                  readnum=0,
                  commentnum=0,
                  tag_id=int(data["tag_id"]),
                  addtime=db.func.current_timestamp())
        db.session().add(art)
        db.session().commit()
        flash("The article has been added successfully", "ok")
        oplog = Oplog(admin_id=session["admin_id"],
                      reason="added article %s" % data["title"],
                      addtime=db.func.current_timestamp())
        db.session().add(oplog)
        db.session().commit()
        return redirect(url_for('admin.art_add'))
    return render_template("admin/art_add.html", form=form)
Example #7
0
def tag_edit(id=None):
    form = TagForm()
    tag = Tag.query.get_or_404(id)
    if form.validate_on_submit():
        data = form.data
        tag_count = Tag.query.filter_by(name=data["name"]).count()
        if tag.name != data["name"] and tag_count == 1:
            flash("This tag is already existed", "err")
            return redirect(url_for('admin.tag_edit', id=id))
        tag.name = data["name"]
        db.session().add(tag)
        db.session().commit()
        flash("Tag is edited successfully", "ok")
        oplog = Oplog(admin_id=session["admin_id"],
                      reason="edited tag %s" % data["name"],
                      addtime=datdb.func.current_timestamp())
        db.session().add(oplog)
        db.session().commit()
        redirect(url_for('admin.tag_edit', id=id))
    return render_template("admin/tag_edit.html", form=form, tag=tag)
Example #8
0
def art_edit(id=None):
    form = ArtForm()
    art = Art.query.get_or_404(int(id))
    if request.method == "GET":
        form.text.data = art.text
        form.tag_id.data = art.tag_id

    if form.validate_on_submit():
        data = form.data
        art.title = data["title"]
        art.tag_id = data["tag_id"]
        art.text = data["text"]
        db.session().add(art)
        db.session().commit()
        flash("The article has bee successfully edited", "ok")
        oplog = Oplog(admin_id=session["admin_id"],
                      reason="edited article %s" % data["title"],
                      addtime=db.func.current_timestamp())
        db.session().add(oplog)
        db.session().commit()
        return redirect(url_for('admin.art_edit', id=id))
    return render_template("admin/art_edit.html", form=form, art=art)