Esempio n. 1
0
def entry_posting_page():
    if request.method == 'GET':
        g.active = {'post': True}
        return render_template('admin/entry_post_page.html')
    else:
        user_name = request.form.get('user_name', '').strip()
        title = request.form.get('title', '').strip()
        subtitle = request.form.get('subtitle', '').strip()
        body = request.form.get('body', '').strip()
        extend = request.form.get('extend', '').strip()
        s_tags = request.form.get('tags', '').strip()

        if body:
            user = User.get_by_name(user_name)

            entry = Entry(author_id = user.id if user else g.login_user.id,
                          body = body,
                          title = title,
                          subtitle = subtitle,
                          extend = extend).save(clear_cache = False)
            entry.previous_entry.clear_memcache()
            labels = set([tag.strip() for tag in s_tags.split(',')])
            for label in labels:
                Tag(entry.id, label).save(clear_cache = False)

            return redirect(url_for('entry_editing_page', entry_id = entry.id))
        else:
            return abort(400)
Esempio n. 2
0
def check_login_user():
    g.login_user = None

    if 'user_name' in session:
        login_user = User.get_by_name(session['user_name'])
        if login_user:
            g.login_user = login_user
        else:
            session.pop('username', None)
Esempio n. 3
0
File: user.py Progetto: setomits/mow
def login_page():
    error = None

    if request.method == 'POST':
        _user_name = request.form.get('user_name', '').strip()
        _password = request.form.get('password', '').strip()
        _next_url = request.form.get('next_url', url_for('top_page'))

        if _user_name and _password:
            user = User.get_by_name(_user_name)
            if user:
                if User.make_hash(_password) == user.password_hash:
                    session['user_name'] = user.name
                    return redirect(_next_url)
        return abort(403)
    else:
        _next_url = request.args.get('next_url', url_for('top_page'))
        return render_template('login.html', next_url = _next_url)
Esempio n. 4
0
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")