Exemple #1
0
def index():
    form = PostForm()
    if form.validate_on_submit():
        res = mysql.Add("post", [
            'NULL',
            "'%s'" % form.post.data,
            "'%s'" % current_user.id,
            "'%s'" % now()
        ])
        if res == 1:
            flash('Your post is now live!')
            return redirect(url_for('index'))
    page = request.args.get('page', 1, type=int)
    all_posts = current_user.followed_posts()
    post_per_page = app.config['POSTS_PER_PAGE']
    posts = all_posts[(page - 1) * post_per_page:page *
                      post_per_page if len(all_posts) >= page *
                      post_per_page else len(all_posts)]
    next_url = url_for('explore', page=page + 1) \
        if len(all_posts) > page * post_per_page else None
    prev_url = url_for('explore', page=page - 1) \
        if (page > 1 and len(all_posts) > page * post_per_page) else None
    usernames = []
    for i in posts:
        usernames.append(load_user(i[2]))
    return render_template('index.html',
                           title='Home',
                           form=form,
                           posts=posts,
                           next_url=next_url,
                           prev_url=prev_url,
                           usernames=usernames,
                           izip=izip,
                           avatars=avatar,
                           dt=datetime.strptime)
Exemple #2
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        res = mysql.Add("user", [
            "NULL",
            "'%s'" % form.username.data,
            "'%s'" % form.email.data,
            "'%s'" % generate_password_hash(form.password.data), "''",
            "'%s'" % now()
        ])
        if res == 1:
            flash('Congratulations, you are now a registered user!')
            return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Exemple #3
0
def before_request():
    if current_user.is_authenticated:
        mysql.Mod('user', {"id": current_user.id},
                  {"last_seen": "'%s'" % now()})