def edit_post(id): """ Edit a post """ p = Post.query.get(id) if p.author_id != current_user.id: return 'This isn\'t your post!!!' else: ### Text post if isinstance(p, TextPost): form = CreatePostForm(title=p.title, text=p.text, latitude=p.latitude, longitude=p.longitude) if form.validate_on_submit(): p.title = form.title.data p.text = form.text.data p.latitude = form.latitude.data p.longitude = form.longitude.data db.session.commit() return redirect(url_for('.post', id=p.id)) return render_template('user/text.html', form=form, pid=p.id) ### Image post if isinstance(p, ImagePost): form = CreateImageForm(title=p.title, caption=p.caption, latitude=p.latitude, longitude=p.longitude) if form.validate_on_submit(): p.title = form.title.data p.text = form.caption.data p.latitude = form.latitude.data p.longitude = form.longitude.data p.loc = 'POINT({0} {1})'.format(form.longitude.data, form.latitude.data) db.session.commit() return redirect(url_for('.post', id=p.id)) return render_template('user/image.html', form=form, pid=p.id)
def edit_post(id): """ Edit a post """ p = Post.query.get(id) if p.author_id != current_user.id: return 'This isn\'t your post!!!' else: ### Text post if isinstance(p, TextPost): form = CreatePostForm(title=p.title, text=p.text, latitude=p.latitude, longitude=p.longitude) if form.validate_on_submit(): p.title=form.title.data p.text=form.text.data p.latitude=form.latitude.data p.longitude=form.longitude.data db.session.commit() return redirect(url_for('.post', id=p.id)) return render_template('user/text.html', form=form, pid=p.id) ### Image post if isinstance(p, ImagePost): form = CreateImageForm(title=p.title, caption=p.caption, latitude=p.latitude, longitude=p.longitude) if form.validate_on_submit(): p.title=form.title.data p.text=form.caption.data p.latitude=form.latitude.data p.longitude=form.longitude.data p.loc = 'POINT({0} {1})'.format(form.longitude.data,form.latitude.data) db.session.commit() return redirect(url_for('.post', id=p.id)) return render_template('user/image.html', form=form, pid=p.id)
def new_text(): """ Write a new text post page """ form = CreatePostForm() if form.validate_on_submit(): t = datetime.utcnow() textpost = TextPost(author=current_user._get_current_object(), title=form.title.data, timestamp=t, text=form.text.data, latitude=form.latitude.data, longitude=form.longitude.data, loc='POINT({0} {1})'.format(form.longitude.data,form.latitude.data)) db.session.add(textpost) db.session.commit() flash("You made a new post!") return redirect(url_for('.post', id=textpost.id)) return render_template('user/text.html', form=form)
def new_text(): """ Write a new text post page """ form = CreatePostForm() if form.validate_on_submit(): t = datetime.utcnow() textpost = TextPost(author=current_user._get_current_object(), title=form.title.data, timestamp=t, text=form.text.data, latitude=form.latitude.data, longitude=form.longitude.data, loc='POINT({0} {1})'.format( form.longitude.data, form.latitude.data)) db.session.add(textpost) db.session.commit() flash("You made a new post!") return redirect(url_for('.post', id=textpost.id)) return render_template('user/text.html', form=form)