def post_view(request): user = check_validation(request) if user: if request.method == "POST": form = PostForm(request.POST, request.FILES) if form.is_valid(): image = form.cleaned_data.get('image') caption = form.cleaned_data.get('caption') post = PostModel(user=user, image=image, caption=caption) post.save() path = str(BASE_DIR +'/'+ post.image.url) client=ImgurClient(Client_ID, Client_secret) post.image_url = client.upload_from_path(path, anon=True)['link'] post.save() return redirect('/feed/') else: form= PostForm() return render(request, 'post.html', {'form': form}) else: return redirect('/login/')
def edit_post(id): if request.method == 'POST': form = PostForm() form.tag.choices = [(str(tag.id), str(tag.tag)) for tag in Tag.query.all()] if form.validate() == False: return render_template('editpost.html', form=form) else: tags = [ Tag.query.filter_by(id=tag_id).first() for tag_id in form.tag.data ] post = Post.query.filter_by(id=id).first() post.title = form.title.data post.text = form.text.data post.tags = tags db.session.merge(post) db.session.commit() flash('Post updated successfully') return render_template('index.html') elif request.method == 'GET': post = Post.query.filter_by(id=id).first() form = PostForm(id=post.id, title=post.title, text=post.text) form.tag.choices = [(str(tag.id), str(tag.tag)) for tag in Tag.query.all()] return render_template('editpost.html', post_id=post.id, form=form)
def post(): form = PostForm() if form.validate_on_submit(): post = BlogPost(description=form.body.data, author_id=current_user._get_current_object()) db.session.add(post) return redirect(url_for('welcome')) posts = BlogPost.query.order_by(BlogPost.title).all() return render_template('index.html', form=form, posts=posts)
def post(): form = PostForm() if form.validate_on_submit(): post = Post( description=form.description.data, location=form.location.data) db.session.add(post) db.session.commit() flash('The party has been posted!') return render_template('post.html ', form=form)
def new_post(): form = PostForm() if form.validate_on_submit(): print("yes") blogpost = Blogpost() blogpost.title = form.title.data print(form.title.data) blogpost.content = form.text.data db.session.add(blogpost) db.session.commit() flash('success') return redirect(url_for('index')) return render_template('new.html',form=form)
def addpost(): form = PostForm(csrf_enabled=False) form.tag.choices = [(str(tag.id), str(tag.tag)) for tag in Tag.query.all()] if request.method == "POST": if form.validate() == False: return render_template('addpost.html', form = form) else: tags = [ Tag.query.filter_by(id=tag_id).first() for tag_id in form.tag.data ] post = Post(form.title.data, form.text.data, tags) db.session.add(post) db.session.commit() flash('Posted successfully') return render_template('index.html') return render_template("addpost.html", form = form)
def user(): postForm = PostForm() postError = None userlog = current_user if postForm.validate_on_submit(): post = Post(postForm.body.data, datetime.utcnow(), userlog.id) db.session.add(post) db.session.commit() flash("Posted") else: postError = "Write something!" return render_template( "user.html", userlog=userlog, postForm=postForm, error=postError, showPost=posted(), updateForm=UpdateForm() )
def admin(): form = PostForm(csrf_enabled=False) if form.validate_on_submit(): title = form.title.data summary = form.summary.data content = form.content.data article = Article(title=title, summary=summary, content=content) db.session.add(article) db.session.commit() article_id = Article.query.filter_by(title=title).first().id return redirect(url_for('index', id=article_id)) return render_template('admin.html', form=form)
def home(): if request.method == 'POST': form = PostForm(request.form) user_input = PostModel(form.data) if form.validate_on_submit(): user_input.save_text() user_input.get_qr() if form.data['download_file']: return redirect('/get_file') else: return redirect('/qr') else: form = PostForm() return render_template('index.html', form=form)
def home(): error = None form = PostForm(request.form) if form.validate_on_submit(): post = BlogPost( form.title.data, form.description.data, current_user.id) db.session.add(post) db.session.commit() # render a template flash('New entry was successfully posted. Thanks.') return redirect(url_for('home.home')) else: posts = db.session.query(BlogPost).all() return render_template('index.html', posts=posts, form = form, error = error)
def home(): error = None form = PostForm(request.form) if form.validate_on_submit(): post = BlogPost(form.title.data, form.description.data, current_user.id) db.session.add(post) db.session.commit() # render a template flash('New entry was successfully posted. Thanks.') return redirect(url_for('home.home')) else: posts = db.session.query(BlogPost).all() return render_template('index.html', posts=posts, form=form, error=error)
def addpost(): form = PostForm(csrf_enabled=False) form.tag.choices = [(str(tag.id), str(tag.tag)) for tag in Tag.query.all()] if request.method == "POST": if form.validate() == False: return render_template('addpost.html', form=form) else: tags = [ Tag.query.filter_by(id=tag_id).first() for tag_id in form.tag.data ] post = Post(form.title.data, form.text.data, tags) db.session.add(post) db.session.commit() flash('Posted successfully') return render_template('index.html') return render_template("addpost.html", form=form)
def admin_nouveau(): form = PostForm() if form.validate_on_submit(): titre = form.title.data identifiant = form.identifiant.data auteur = form.auteur.data date_parution = form.date.data paragraphe = form.content.data params = (titre, identifiant, auteur, date_parution, paragraphe) cursor.execute( "INSERT INTO article(titre, identifiant, auteur, " "date_publication, paragraphe) VALUES( ?, ?, ?, ?, ?)", params) flash('Post cree avec succes!', 'success') return redirect(url_for('admin')) return render_template('creation_post.html', title='Nouveau poste', form=form)
def post(): form = PostForm() if form.validate_on_submit(): title = form.title.data post = form.post.data location = form.location.data db.execute( "INSERT INTO post('post','title','location','id') values(:post, :title, :location, :id)", post=post, title=title, location=location, id=session.get("id")) form.title.data = '' form.post.data = '' form.location.data = '' return render_template('post.html', form=form) else: return render_template('post.html', form=form)
def new_post(): form = PostForm() topic = Topic.query.filter(Topic.tid == form.topic.data).first() if form.validate_on_submit(): post = Post(title=form.title.data, content=form.content.data, post_time=datetime.utcnow(), uid=current_user.uid, tid=form.topic.data) current_user.posts.append(post) topic.posts.append(post) db.session.add(post) db.session.commit() flash('Your post has been created!', 'success') posts = Post.query.filter(Post.pid == post.pid).order_by( Post.pid.desc()) return redirect("/viewpost?post=" + str(post.pid)) return render_template('create_post.html', title='New Post', form=form)
def add_post(request): # Check if it's a 'POST' request if request.method == 'POST': form = PostForm(request.POST) user = request.user if form.is_valid(): if user: post = form.save(commit=False) post.user = user post.save() # Now call the index() view. # The user will be shown the homepage. return redirect('/reddit/') else: print form.errors else: # Not a post request, just show/render the page form = PostForm() context_dict = {'form': form} return render(request, 'reddit/add_post.html', context_dict)
def edit_post(id): if request.method == 'POST': form = PostForm() form.tag.choices = [(str(tag.id), str(tag.tag)) for tag in Tag.query.all()] if form.validate() == False: return render_template('editpost.html', form=form) else: tags = [ Tag.query.filter_by(id=tag_id).first() for tag_id in form.tag.data ] post = Post.query.filter_by(id=id).first() post.title = form.title.data post.text = form.text.data post.tags = tags db.session.merge(post) db.session.commit() flash('Post updated successfully') return render_template('index.html') elif request.method == 'GET': post = Post.query.filter_by(id=id).first() form = PostForm(id=post.id, title=post.title, text=post.text) form.tag.choices = [(str(tag.id), str(tag.tag)) for tag in Tag.query.all()] return render_template('editpost.html', post_id= post.id, form=form)
def edit(id=0): form = PostForm() # 表单实例化 if id == 0: post = Post(author=current_user) # 模型实例化 else: post = Post.query.get_or_404(id) if form.validate_on_submit(): post.body = form.body.data post.title = form.title.data db.session.add(post) db.session.commit() # 保存到库中 return redirect(url_for('.post', id=post.id)) title = _(u'添加新文章') if id > 0: title = _(u'编辑 - %(title)', title=post.title) # 如果是post,则是编辑 return render_template('posts/edit.html', title=title, form=form, post=post)
def post_view(request): user = check_validation(request) if user: if request.method == "GET": form = PostForm() return render(request, 'post.html', {'form' : form}) elif request.method == 'POST': form = PostForm(request.POST, request.FILES) if form.is_valid(): image = form.cleaned_data.get('image') caption = form.cleaned_data.get('caption') post = PostModel(user=user, image=image, caption=caption) path = str(BASE_DIR +"/" +post.image.url) client = ImgurClient("a6aafcb28ec79df","d080ec60896f82ded7822335c1e42ecda3170efa") post.image_url = client.upload_from_path(path, anon=True)['link'] # clarifai_response = get_keywords(post.image_url) # array_dictionary = clarifai_response['outputs'][0]['data']['concept'] # for i in range(0,len(array_dictionary)): # key_word = array_dictionary[i]['name'] # value = array_dictionary[i]['value'] # if (key_word == "summer" or "outdoor pool" or "garden" or "mountains" and value >0.5): post.save() return redirect('/feed/') else: return redirect('/login/')
def adminer(): postform = PostForm() if postform.validate_on_submit(): post = Post(title=postform.title.data, body=postform.body.data) db.session.add(post) db.session.commit() return redirect(url_for('.adminer')) labelform = LabelForm() if labelform.validate_on_submit(): label = Label(name=labelform.name.data) print label db.session.add(label) db.session.commit() return redirect(url_for('.adminer')) posts = Post.query.all() page = request.args.get('page',1,type=int) pagination = Post.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('admin/admin.html',postform=postform,labelform=labelform,posts=posts)