示例#1
0
文件: __init__.py 项目: setomits/mow
def load_values_for_side():
    g.recent_entries = Entry.fetch_recent_entries(
        max(g.items_for_side, g.entries_per_page))
    g.recent_comments = Comment.fetch_recent_comments(
        max(g.items_for_side, g.entries_per_page))
    g.tag_counts = Tag.fetch_tag_counts()
    g.archives = Entry.fetch_archives()
示例#2
0
文件: comment.py 项目: setomits/mow
def delete_comment():
    comment_id = request.form.get('comment_id', '').strip()

    if comment_id and comment_id.isdigit():
        comment = Comment.get_by_id(int(comment_id))
        if comment:
            comment.delete()
            return redirect(url_for('admin_top_page'))
        else:
            return abort(404)
    else:
        return abort(400)
示例#3
0
文件: admin.py 项目: setomits/mow
def admin_top_page():
    g.active = {"top": True}
    g.sqlalchemy_database_uri = app.config["SQLALCHEMY_DATABASE_URI"].replace("sqlite:///", "")
    g.n_total_comments = Comment.n_total_count()
    g.n_total_entries = Entry.n_total_count()
    g.n_total_tags = Tag.n_total_count()
    g.n_total_users = User.n_total_count()
    g.db_updated_at = datetime.fromtimestamp(getmtime(g.sqlalchemy_database_uri))
    g.db_bytes = getsize(g.sqlalchemy_database_uri)

    g.mc_stats = {}
    for server, stats in g.mc.get_stats():
        d = dict(
            cmd_get=int(stats[b"cmd_get"]), get_hits=int(stats[b"get_hits"]), total_items=int(stats[b"total_items"])
        )
        d["hit_ratio"] = "%5.2lf %%" % (d["get_hits"] / d["cmd_get"] * 100)
        g.mc_stats[server.decode("utf-8")] = d

    return render_template("admin/top.html")
示例#4
0
文件: comment.py 项目: setomits/mow
def comment_editing_page():
    g.active = {'comment': True}

    if request.method == 'GET':
        comment_id = request.args.get('comment_id', '').strip()
    else:
        comment_id = request.form.get('comment_id', '').strip()

    comment = Comment.get_by_id(int(comment_id)) if comment_id.isdigit() else None

    if request.method == 'POST':
        if comment is None:
            return abort(400)

        author_name = request.form.get('author_name', '').strip()
        title = request.form.get('title', '').strip()
        body = request.form.get('body', '').strip()

        to_save = False

        if author_name != comment.author_name:
            comment.author_name = author_name
            to_save = True

        if title != comment.title:
            comment.title = title
            to_save = True

        if body != comment.body:
            comment.body = body
            to_save = True

        if to_save:
            comment.save()

    g.comment = comment

    return render_template('admin/edit_comment_page.html')