def post_edit(self, id): """ Post Route for Edit an item TODO: Ability to edit title/url for posts """ commentForm = self._commentForm(request) item = Item.query.get_or_404(id) if commentForm.validate_on_submit(): item.text = self._clean_text(commentForm.text.data) item.last_changed = datetime.utcnow() item = db.session.merge(item) db.session.commit() #TODO: Delete only necessary items cache.delete_memoized(Item.get_children) cache.delete_memoized(Item.get_item_and_children) key = make_template_fragment_key("item_text", vary_on=[item.__str__(), item.changed]) cache.delete(key) flash('Edit saved', 'info') response = make_response(render_template('item/item.html', item = item, form = commentForm, title=item.title, edit=True)) next_url = url_for('frontend.item_edit', id=item.id) response.headers['X-PJAX-URL'] = next_url return response else: return render_template('item/item.html', item = item, form = commentForm, title=item.title, edit=True)
def post(self, name): """ Submit changes for user. NOT used to create a new user (that is done via flask-security) """ user = User.find_user_by_name(name).first_or_404() form = UserForm() if user == current_user and form.validate_on_submit(): old_name = current_user.name if form.email.data != '': user.email = form.email.data user.name = form.name.data user.twitter_handle = form.twitter.data db.session.commit() key = make_template_fragment_key("user", vary_on=[old_name]) cache.delete(key) flash('Your edits are saved, thanks.', category = 'info') return redirect(url_for('.user', name=form.name.data))
def post(self, name): """ Submit changes for user. NOT used to create a new user (that is done via flask-security) """ user = User.find_user_by_name(name).first_or_404() form = UserForm() if user == current_user and form.validate_on_submit(): old_name = current_user.name if form.email.data != '': user.email = form.email.data user.name = form.name.data user.twitter_handle = form.twitter.data db.session.commit() key = make_template_fragment_key("user", vary_on=[old_name]) cache.delete(key) flash('Your edits are saved, thanks.', category='info') return redirect(url_for('.user', name=form.name.data))
def post_edit(self, id): """ Post Route for Edit an item TODO: Ability to edit title/url for posts """ commentForm = self._commentForm(request) item = Item.query.get_or_404(id) if commentForm.validate_on_submit(): item.text = self._clean_text(commentForm.text.data) item.last_changed = datetime.utcnow() item = db.session.merge(item) db.session.commit() #TODO: Delete only necessary items cache.delete_memoized(Item.get_children) cache.delete_memoized(Item.get_item_and_children) key = make_template_fragment_key( "item_text", vary_on=[item.__str__(), item.changed]) cache.delete(key) flash('Edit saved', 'info') response = make_response( render_template('item/item.html', item=item, form=commentForm, title=item.title, edit=True)) next_url = url_for('frontend.item_edit', id=item.id) response.headers['X-PJAX-URL'] = next_url return response else: return render_template('item/item.html', item=item, form=commentForm, title=item.title, edit=True)