def deploy(): """Run deployment tasks.""" from flask.ext.migrate import upgrade # migrate database to latest revision upgrade() #add blogs Post.add_post() #add admin when no admin is presented if not Administrator.query.all(): pwd = os.environ.get('ADMIN_PWD') or '1111' admin = Administrator(pwd) db.session.add(admin) db.session.commit()
def index(): """ View function for home page of application. """ form = None if current_user.is_authenticated: form = PostForm() if form.validate_on_submit(): Post.add_post(body_=form.post.data, author_=current_user) flash('Your post is now live!') return redirect(url_for('main.index')) posts = current_user.followed_posts().limit( current_app.config['POSTS_PER_PAGE']) else: posts = Post.get_random_posts(current_app.config['POSTS_PER_PAGE']) return render_template('index.html', title='Home', posts=posts, form=form)
def index(): form = PostForm() if form.validate_on_submit(): language = guess_language(form.post.data) if language == ' UNKNOWN' or len(language) > 5: language = '' post_ = Post(body=form.post.data, author=current_user, language=language) Post.add_post(post_) flash(_('Your post is now live')) return redirect(url_for('main.index')) page = request.args.get('page', 1, type=int) posts = current_user.followed_posts().paginate(page, current_app.config['POSTS_PER_PAGE'], False) next_url = url_for('main.index', page=posts.next_num) if posts.has_next else None prev_url = url_for('main.index', page=posts.prev_num) if posts.has_prev else None return render_template('index.html', title='home', posts=posts.items, current_user=current_user, form=form, next_url=next_url, prev_url=prev_url)
def add_post(): Post.add_post()