def index(): form = PostForm() if current_user.can(Permission.WRITE_ARTICLES) and \ form.validate_on_submit(): post = Post(body=form.body.data, author=current_user._get_current_object()) db.session.add(post) return redirect(url_for('.index')) page = request.args.get('page', 1, type=int) show_followed = False if current_user.is_authenticated: show_followed = bool(request.cookies.get('show_followed', '')) if show_followed: query = current_user.followed_posts else: query = Post.query pagination = query.order_by(Post.timestamp.desc()).paginate( page, per_page=current_app.config['FLASKY_POSTS_PER_PAGE'], error_out=False) posts = pagination.items return render_template('index.html', form=form, posts=posts, show_followed=show_followed, pagination=pagination)
def index(): form = PostForm() if form.validate_on_submit(): if form.picture.data == None: flash("Select any image before submitting!", "danger") return redirect("/") imgname = save_picture(form.picture.data) cols = request.form.get('cols') scale = request.form.get('scale') if scale == None: scale = 0.43 else: scale = float(scale) if cols == None: cols = 500 else: cols = int(cols) result = convert_img_to_ascii(imgname, cols, scale) os.remove(imgname) if result != None: return render_template('index.html',form=form, result=result) else: return redirect("/") return render_template('index.html',form=form)
def add_post(): form = PostForm() if form.validate_on_submit(): post = Post(title=form.title.data, content=form.content.data) post.slug_(str(form.title.data)) db.session.add(post) db.session.commit() return redirect(url_for('index')) return render_template('add_post.html', form=form)
def new_post(): form = PostForm() if form.validate_on_submit(): post = Post(title = form.title.data, content=form.content.data, author=current_user) db.session.add(post) db.session.commit() flash('Your post has been created!', 'success') return redirect(url_for('home')) return render_template('create_post.html', title='New post', form = form, legend= 'New Post')
def new_post(): form = PostForm() if form.validate_on_submit(): post = Post(title=form.title.data, content=form.content.data, author=current_user) db.session.add(post) db.session.commit() flash('Blog added to community', 'success') return redirect(url_for('home')) return render_template('new_post.html', form=form, titlt="NEW BLOG")
def newpost(): form = PostForm() if form.validate_on_submit(): post = Post( title=form.title.data, content=form.content.data, author=current_user) #use author the backref to grab the user db.session.add(post) db.session.commit() flash('Post submitted successfully', 'success') return redirect(url_for('index')) return render_template('newpost.html', title='New Post', form=form)
def edit(id): post = Post.query.get_or_404(id) if current_user != post.author and \ not current_user.can(Permission.ADMINISTER): abort(403) form = PostForm() if form.validate_on_submit(): post.body = form.body.data db.session.add(post) db.session.commit() flash('The post has been updated.') # print(post.id) return redirect(url_for('main.post', id=post.id)) form.body.data = post.body return render_template('edit_post.html', form=form)
def update_post(post_id): post = Post.query.get_or_404(post_id) if post.author != current_user: abort(403) form = PostForm() if form.validate_on_submit(): post.title = form.title.data post.content = form.content.data db.session.commit() flash('Your post has been updated!', 'success') return redirect(url_for('post', post_id=post.id)) elif request.method == 'GET': form.title.data = post.title form.content.data = post.content return render_template('create_post.html', title='Update post', form=form, legend= 'Update Post')
def edit(id): post = Post.query.get_or_404(id) if current_user != post.author and \ not current_user.can(Permission.ADMINISTER): abort(403) form = PostForm() if form.validate_on_submit(): post.body = form.body.data db.session.add(post) db.session.commit() flash('The post has been updated.') # print(post.id) return redirect(url_for('main.post', id=post.id)) form.body.data = post.body return render_template('edit_post.html', form=form)
def update_post(post_id): form = PostForm() if request.method == 'GET': post = Post.query.get(post_id) form.title.data = post.title form.content.data = post.content return render_template('update.html', form=form) elif request.method == 'POST' and form.validate_on_submit(): post = Post.query.get(post_id) post.title = form.title.data post.content = form.content.data post.slug_(str(form.title.data)) db.session.commit() return redirect(url_for('index'))
def update(post_id): post = Post.query.get_or_404(post_id) if post.author != current_user: abort(403) form = PostForm() if form.validate_on_submit(): post.title = form.title.data post.content = form.content.data db.session.commit() flash('Blog updated successfully', 'success') return redirect(url_for('post', post_id=post_id)) elif request.method == 'GET': form.title.data = post.title form.content.data = post.content return render_template('update_post.html', form=form, post=post)
def index(): form = PostForm() if current_user.can(Permission.WRITE_ARTICLES) and \ form.validate_on_submit(): post = Post(body=form.body.data, author=current_user._get_current_object()) db.session.add(post) return redirect(url_for('.index')) page = request.args.get('page', 1, type=int) show_followed = False if current_user.is_authenticated: show_followed = bool(request.cookies.get('show_followed', '')) if show_followed: query = current_user.followed_posts else: query = Post.query pagination = query.order_by(Post.timestamp.desc()).paginate( page, per_page=current_app.config['FLASKY_POSTS_PER_PAGE'], error_out=False) posts = pagination.items return render_template('index.html', form=form, posts=posts, show_followed=show_followed, pagination=pagination)
def index(): form = PostForm() if form.validate_on_submit(): post = Post(body=form.post.data, title=form.title.data, author=current_user) db.session.add(post) db.session.commit() flash('Blog post successful.') return redirect(url_for('index')) page = request.args.get('page', 1, type=int) posts = current_user.followed_posts().paginate( page, blog.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', form=form, posts=posts.items, next_url=next_url, prev_url=prev_url)
def Topic(playlist_id=None, topic=None): if current_user.is_authenticated: print("Authenticated user") try: spotify.activate(current_user.access_token) me = spotify.active.me( ) #without this logout is not working properly. (verification for api access needed here) except Exception as e: print(e) logout_user() #try: # spotify.call_playlists(current=0, next=50) # spotify.insert_playlists(me['id']) #except Exception as e: # #print(e) # pass else: print("Non-authenticated user") form = PostForm() if form.validate_on_submit(): try: spotify.insert_current_playlist(me['id']) spotify.insert_songs(spotify.current_playlist['local_id']) except: pass post = Post(title='test', content=form.content.data, user_id=current_user.id, playlist_id=spotify.current_playlist['local_id']) db.session.add(post) db.session.commit() return redirect( url_for('Topic', playlist_id=spotify.current_playlist['local_id'])) return render_template('home.html', 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) 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_posts().paginate( page, current_app.config['POSTS_PER_PAGE'], False) comments = Comment.query.order_by(Comment.timestamp.desc()).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', form=form, posts=posts.items, next_url=next_url, prev_url=prev_url, comments=comments.items)