Пример #1
0
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 successfuly created', 'success')
        return redirect(url_for('home'))

    return render_template('create_post.html',title= 'New Post',form = form)
Пример #2
0
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')
Пример #3
0
def new_complaint():
    form = PostForm()
    if form.validate_on_submit():
        x = list()
        x.append(form.content.data)
        x = encode_docs(Tokenizer, 414, x)
        with graph.as_default():
            prediction = sentiment.predict(x)
        prediction = list(prediction[0])
        funny_string = ""
        if (prediction[0] > 0.6):
            senti_string = "Review: Negative"
        elif (prediction[2] > 0.6):
            senti_string = "Review: Positive"
        else:
            senti_string = "Review: Neutral"
        y = list()
        y.append(form.content.data)
        input_features = vectorizer.transform(extract_words(y))
        prediction = classifier_liblinear.predict(input_features)
        if (prediction[0] == 1):
            funny_string = "Funny!"
        else:
            funny_string = process_output(form.content.data, prediction)
        post = Complaint(title=form.title.data,
                         content=form.content.data,
                         date_posted=form.date.data,
                         author=current_user)
        post1 = NewComplaint(title=form.title.data,
                             senti=senti_string,
                             funny=funny_string,
                             content=form.content.data,
                             date_posted=form.date.data,
                             author=current_user)
        db.session.add(post1)
        db.session.add(post)
        db.session.commit()
        flash('Your complaint has been sucessfully added', 'success')
        return redirect(url_for('home'))
    return render_template('create_complaint.html',
                           title='Complaint Portal',
                           legend="New Complaint",
                           form=form)