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) db.session.add(post) db.session.commit() flash('You post is now live!') return redirect(url_for('index')) page = request.args.get('page', 1, type=int) posts = current_user.followed_post().paginate(page, app.config['POSTS_PER_PAGE'], False) next_url = url_for('index', page=posts.next_num) if posts.has_next else None prev_url = url_for('index', page=posts.prev_num) if posts.has_prev else None return render_template('index.html', title='Home Page', form=form, posts=posts.items, next_url=next_url, prev_url=prev_url)
def index(): posts = current_user.followed_post() pagination = paginate_posts(posts, redirect_to="index") form = PostForm() if form.validate_on_submit(): language = guess_language(form.post.data) language = language if language != "UNKNOWN" and len( language) <= 5 else "" post = Post(body=form.post.data, author=current_user, language=language) db.session.add(post) db.session.commit() flash(_l("Your post is now live!")) return redirect(url_for("main.index")) return render_template("index.html", title=_("Home"), user=current_user, form=form, **pagination)
def index(): form = PostForm() if form.validate_on_submit(): post = Post(body=form.body.data, author=current_user) db.session.add(post) db.session.commit() flash('Your post is now live!!!') return redirect(url_for('main.index')) page = request.args.get('page', 1, type=int) posts = current_user.followed_post().paginate( page, current_app.config['POST_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', posts=posts.items, form=form, title='Home page', next_url=next_url, prev_url=prev_url)
def index(): form = PostForm() if form.validate_on_submit(): # try: language = detect_lang(form.post.data) # except: # language = '' # 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) db.session.add(post) db.session.commit() flash(_('Ваш пост успешно опубликован!')) return redirect(url_for('main.index')) page = request.args.get('page', 1, type=int) posts = current_user.followed_post().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=_('Домашняя страница'), form=form, posts=posts.items, next_url=next_url, prev_url=prev_url)
def index(): form = PostForm() if form.validate_on_submit(): post = Post(body=form.post.data, author=current_user) db.session.add(post) db.session.commit() flash('Ваш пост теперь существует!') return redirect(url_for('index')) page = request.args.get('page', 1, type=int) posts = current_user.followed_post().paginate(page, app.config["POST_PER_PAGE"], False) next_url = url_for('index', page=posts.next_num) \ if posts.has_next else None prev_url = url_for('index', page=posts.prev_num) \ if posts.has_prev else None return render_template('index.html', title='Home Page', form=form, posts=posts.items, next_url=next_url, prev_url=prev_url)