def edit(post_id): post = Post.query.get(post_id) if post is not None: if post.user == current_user: form = EditPostForm(obj=post) if form.has_been_submitted(request) and form.validate_on_submit(): if post.title != form.title.data and not validate_post_title(form.title.data): form.title.errors.append("You already posted an article with the same title today.") return render_template("edit_post.html", form=form) post.title = form.title.data post.content = form.content.data post.set_title_slug() saved = post.save() if saved: flash("Successfully saved the post.") return redirect(url_for("blog.get", user_slug=current_user.blog_slug, post_slug=post.title_slug)) else: flash("Something went wrong...") return render_template("edit_post.html", form=form, syntax_highlighter_css=generate_syntax_highlighter_css(current_user)) else: # The user trying to edit is not the actual owner flash("Your are not authorized to do that.") return redirect(url_for('index')) else: # The post has not been found return render_template("blog/blog_page_404", post_id=post_id)
def edit_post(id): form = PostForm() edit_form = EditPostForm() delete_form = PostFormDelete() post = Post.query.get_or_404(id) if edit_form.validate_on_submit(): try: post.title = edit_form.title_post.data post.body = edit_form.body_post.data db.session.commit() flash('Your changes have been saved.') return render_template('article.html', post=post, delete_form=delete_form, edit_form=edit_form, form=form) except: flash('Слишком много букаф!') elif request.method == 'GET': edit_form.title_post.data = post.title edit_form.body_post.data = post.body return render_template('edit_post.html', post=post, delete_form=delete_form, edit_form=edit_form, form=form)
def update_post(post_id): post = Post.query.get_or_404(post_id) if post.author != current_user: flash('You cannot edit this post') print('NOOO') abort(403) form = EditPostForm(post.title, post.date, post.time, post.venue, post.body) if form.validate_on_submit(): post.title = form.title.data post.date = form.date.data post.time = form.time.data pot.venue = form.venue.data post.body = form.post.data file = request.files['eventphoto'] filename = form.title.data + '.png' file.save(os.path.join(app.root_path, 'static/event_pics', filename)) post.eventphoto = url_for('static', filename='event_pics/' + filename) db.session.commit() flash('Your post has been updated!') return redirect(url_for('post', post_id=post.id)) elif request.method == 'GET': form.title.data = post.title form.date.data = post.date form.time.data = post.time form.venue.data = post.venue form.post.data = post.body return render_template('update_post.html', form=form, post=post)
def edit_post(title): post = db.session.query(Post).filter_by(title=title).first_or_404() form = EditPostForm() if request.method == "GET": form.title.data = post.title form.body.data = post.body if form.validate_on_submit(): post.title = form.title.data post.body = form.body.data if form.featured_image.data is not None: post.featured_image = upload_file('featured_image', type="POSTS") db.session.add(post) db.session.commit() message = Markup( '<div class="alert alert-success alert-dismissible"><button type="button" class="close" data-dismiss="alert">×</button>Post {} updated.</div>' .format(post.title)) flash(message) return redirect(url_for('admin_posts')) return render_template('admin/post_edit.html', form=form, post=post)
def edit_post(post_id): """Funkcja wyświetlająca formularz edycji postów użytkownika.""" post = Post.query.filter_by(id=post_id).all() form = EditPostForm() if form.validate_on_submit(): post[0].body = form.body.data db.session.commit() flash(_('Your changes have been saved!')) return redirect(url_for('index')) elif request.method == 'GET': form.body.data = post[0].body return render_template('edit_post.html', title=_('Edit Post'), form=form)
def edit_post(id): post = Post.query.get_or_404(id) form = EditPostForm() if form.validate_on_submit(): post.header = form.header.data post.text = form.text.data post.add_comment = form.add_comment.data db.session.commit() flash('Изменения успешно сохранены') return redirect(url_for('edit_post', id=post.id, _anchor='edit_post')) form.add_comment.data = post.add_comment form.header.data = post.header form.text.data = post.text return render_template('edit_post.html', form=form, post=post)
def edit_post(id): user_id = current_user.get_id() # user_id = 1 user = User.query.get(user_id) form = EditPostForm() form['csrf_token'].data = request.cookies['csrf_token'] if form.validate_on_submit(): post = Post.query.get(id) post.title = form.data['title'], post.content = form.data['content'], post.last_modified = datetime.datetime.now() db.session.commit() return post.to_dict() return {'errors': validation_errors_to_error_messages(form.errors)}
def edit(title): form = EditPostForm() post = Post.query.filter_by(title=title).first() form.title.data = post.title form.author.data = post.user_id form.content.data = post.body if form.validate_on_submit(): post.title = form.title.data post.user_id = form.author.data post.body = form.content.data db.session.commit() flash('Post updated') return redirect(url_for('news')) return render_template('edit_news.html', title="Edit news", form=form)
def edit_post(id): post = Post.query.get_or_404(id) if post.author != current_user: return redirect(url_for('posts')) form = EditPostForm() if form.validate_on_submit(): post.title = form.title.data post.content = form.content.data db.session.commit() flash(f'Post updated!', category='success') return redirect(url_for('posts')) elif request.method == 'GET': form.title.data = post.title form.content.data = post.content return render_template('edit-post.html', title='Edit', form=form, id=id)
def update(id): post = Post.query.filter_by(id=id).first() form = EditPostForm() if form.validate_on_submit(): #Update when submit button is clicked post.title = form.title.data post.description = form.description.data post.body = form.body.data db.session.commit() flash('Changes have been saved') return redirect(url_for('all_posts')) elif request.method == 'GET': #Load the form with the data of the post we are trying to update form.title.data = post.title form.description.data = post.description form.body.data = post.body return render_template('update.html', title='Update post', form=form)
def edit_list(id): form = EditPostForm() post = PostForm() username = current_user.username post = Post.query.filter_by(id=id).first_or_404() if form.validate_on_submit(): post.title = form.title.data post.body = form.body.data db.session.commit() return redirect(url_for('user', username=username)) elif request.method == 'GET': form.title.data = post.title form.body.data = post.body return render_template('edit_list.html', title='Edit List', form=form)
def edit_post(request, id): from app.forms import EditPostForm if request.method == 'GET': try: postQuery = Post.objects.get( author__username=request.user.username, id=id, visible=True) except Post.DoesNotExist: return display_posts(request, err='Couldn\'t get post requested') categories = Category.objects.filter(post=postQuery) categories_pylist = [category.name.lower() for category in categories] categories_pylist = ', '.join(categories_pylist) return render( request, 'posts/edit_post.html', { 'post': postQuery, 'categories': categories_pylist, 'form': EditPostForm() }) else: # da cambiare alla posts page con messaggio from app.forms import EditPostForm body = request.POST.get('body', '') categories = request.POST.get('categories', '') try: postQuery = Post.objects.get( author__username=request.user.username, id=id) except Post.DoesNotExist: raise Http404('Cannot edit this post') postQuery.body = body _create_category(categories.split(','), postQuery) return redirect('display_post')
def edit_post(post): form = EditPostForm(post) idx_str = post.split("~")[1] idx_str = idx_str[0:len(idx_str) - 1] print("Values are:" + post.split("~")[1][0:len(post)]) print("Id: " + idx_str) if form.validate_on_submit(): tp = Post.query.filter_by(id=idx_str).first() print(tp) tp.body = form.post.data db.session.commit() flash('Your changes have been saved') return redirect(url_for('index')) elif request.method == 'GET': form.post.data = post return render_template('edit_post.html', title="Edit Post", form=form)
def edit_post(post_id): post = Post.query.filter_by(id=post_id).first_or_404() form = EditPostForm() form.body.default = post.body form.post_target_type.default = post.post_target_type form.post_title.default = post.post_title if form.validate_on_submit(): post.post_title = form.post_title.data post.body = form.body.data post.post_target_type = form.post_target_type.data db.session.commit() flash('Your changes have been saved.') return redirect(url_for('edit_post', post_id=post_id)) elif request.method == 'GET': form.post_target_type.data = post.post_target_type form.post_title.data = post.post_title form.body.data = post.body return render_template('edit_post.html', title='Edit Profile', form=form)
def post_detail(id): form = PostForm() delete_form = PostFormDelete() edit_form = EditPostForm() post = Post.query.get(id) return render_template('article.html', post=post, delete_form=delete_form, form=form, edit_form=edit_form)
def edit_post(id): username = request.args.get('username') post = Post.query.get_or_404(id) print(id) form = EditPostForm() if form.validate_on_submit(): post.body = form.body.data post.anonymous = form.anonymous.data post.author = current_user db.session.add(post) db.session.commit() flash('Your post has been updated.') return redirect(url_for('post', id=id, username=current_user.username)) if request.method == 'GET': post = Post.query.get_or_404(id) # form.id.data = post.id form.body.data = post.body form.image.data = post.image form.anonymous.data = post.anonymous return render_template('edit_post.html', title='Edit Post', post=post, user=user, username=username, form=form)
def edit(post_id): post = Post.query.get(post_id) if post is not None: if post.user == current_user: form = EditPostForm(obj=post) if form.has_been_submitted(request) and form.validate_on_submit(): if post.title != form.title.data and not validate_post_title( form.title.data): form.title.errors.append( "You already posted an article with the same title today." ) return render_template("edit_post.html", form=form) post.title = form.title.data post.content = form.content.data post.set_title_slug() saved = post.save() if saved: flash("Successfully saved the post.") return redirect( url_for("blog.get", user_slug=current_user.blog_slug, post_slug=post.title_slug)) else: flash("Something went wrong...") return render_template( "edit_post.html", form=form, syntax_highlighter_css=generate_syntax_highlighter_css( current_user)) else: # The user trying to edit is not the actual owner flash("Your are not authorized to do that.") return redirect(url_for('index')) else: # The post has not been found return render_template("blog/blog_page_404.html", post_id=post_id)
def editpost(post_id): form = EditPostForm() editing_post = Post.query.get(post_id) if form.validate_on_submit(): if not form.cover.data == None: os.remove(app.config['PC_PATH'] + '/' + post_id + '.jpg') c = form.cover.data c.save(os.path.join(app.config['PC_PATH'] + '/' + post_id + '.jpg')) if editing_post.video_id: if form.delete_video_or_not: os.remove(app.config['UPLOAD_PATH'] + '/' + editing_post.video_id) editing_post.video_id = None elif not form.video.data == None: os.remove(app.config['UPLOAD_PATH'] + '/' + editing_post.video_id) f = form.video.data filename = random_filename(f.filename) f.save(os.path.join(app.config['UPLOAD_PATH'], filename)) editing_post.video_id = filename elif not form.video.data == None: f = form.video.data filename = random_filename(f.filename) f.save(os.path.join(app.config['UPLOAD_PATH'], filename)) editing_post.video_id = filename editing_post.title = form.title.data editing_post.body = form.body.data db.session.commit() flash('你的提交已变更.') return redirect(url_for('post', post_id=post_id)) elif request.method == 'GET': form.title.data = editing_post.title form.body.data = editing_post.body return render_template('edit_post.html', form=form, user=current_user, post=editing_post)
def edit_posts(username, id): if (current_user.username != username): return redirect(url_for('index')) user = User.query.filter_by(username=username).first_or_404() posts = Post.query.filter_by(id=id).first_or_404() form = EditPostForm() if form.validate_on_submit(): posts.name = form.name.data posts.email = form.email.data posts.gender = form.gender.data posts.body = form.body.data db.session.commit() flash('Your changes have been saved.') return redirect(url_for('user', username=current_user.username)) elif request.method == 'GET': form.name.data = posts.name form.email.data = posts.email form.gender.data = posts.gender form.body.data = posts.body return render_template('edit_posts.html', user=user, posts=posts, form=form)
def post_delete(id): form = PostForm() edit_form = EditPostForm() delete_form = PostFormDelete() post = Post.query.get_or_404(id) if delete_form.validate_on_submit(): if current_user.id == post.user_id: try: db.session.delete(post) db.session.commit() flash('Ваша запись была успешно удалена') return redirect(url_for('index')) except: flash('При удалении произошла ошибка!') return render_template('index.html', post=post, delete_form=delete_form, edit_form=edit_form, form=form)
def edit_post(id): form = EditPostForm() if form.validate_on_submit(): post_edit(id_post=id, text=form.data.get('text')) return redirect('/index') return render_template('edit_post.html', title='ред.пост', form=form)