Ejemplo n.º 1
0
def index():
    form_post = PostForm()
    if request.method == 'GET':
        if current_user.is_authenticated == True:
            posts = Post.query.filter_by(
                user_id=current_user.get_id()).order_by(
                    Post.date.desc()).all()
            return render_template('index.html', form=form_post, posts=posts)
        else:
            return redirect(url_for("login"))

    else:
        if form_post.validate_on_submit():
            id = current_user.get_id()
            user = User.query.filter_by(id=id).first()
            date = datetime.now().strftime('%d/%m/%Y %H:%M')
            NewPost = Post(content=form_post.content.data,
                           title=form_post.title.data,
                           date=date,
                           user=user.name,
                           nick=user.username,
                           user_id=id)
            db.session.add(NewPost)
            db.session.commit()
            print(NewPost)
            return redirect(url_for("index"))
        else:
            return "ERRO!!"
Ejemplo n.º 2
0
def index():
    postform = PostForm()
    post_list = Post.query.order_by(Post.id.desc()).all()
    if current_user.is_authenticated:
        following_post_list = Post.query.join(
            Follow, Follow.user_id == Post.user_id).filter(
                Follow.follower_id == current_user.id).order_by(
                    Post.id.desc()).all()
        print(following_post_list)
        my_post_list = Post.query.filter_by(user_id=current_user.id).order_by(
            Post.id.desc()).all()
        users = User.query.filter(User.id != current_user.id).all()
    else:
        following_post_list = []
        my_post_list = []
        users = User.query.all()
    if postform.validate_on_submit():
        p = Post(postform.text.data, current_user.id)
        db.session.add(p)
        db.session.commit()
        return redirect(url_for("index"))
    return render_template("index.html",
                           postform=postform,
                           post_list=post_list,
                           following_post_list=following_post_list,
                           my_post_list=my_post_list,
                           users=users)
Ejemplo n.º 3
0
def chamado():
    a = False
    form = CallForm()
    l = []
    l.append(form.category2.data)
    l.append(form.category3.data)
    l.append(form.category4.data)
    l.append(form.category5.data)
    if form.category.data == 'None' or form.category.data == None:
        pass
    else:
        for x in l:
            if form.category.data != None and x != 'None' and x != None:

                c = Post(form.category.data, x, form.obs.data,
                         User.get_name(current_user), 1)
                db.session.add(c)
                db.session.commit()
                aux = Post.query.filter_by(id=c.id).first()
                flash("Chamado número " + str(aux) + " efetuado com sucesso! ")
                #flash(str(aux))
                return redirect(url_for("index"))
                break

    return render_template('chamado.html', form=form)
Ejemplo n.º 4
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('Sua postagem foi criada!', 'success')
        return redirect(url_for('main.index'))
    return render_template('create_post.html', title='New Post',
                           form=form, legend='New Post')
Ejemplo n.º 5
0
def index():
    form = PostForm()
    post = Post.query.order_by(Post.id.desc())
    like = Like.query.order_by(Like.id.desc())
    if form.validate_on_submit():
        content = form.content.data
        user = current_user.id
        i = Post(content, user)
        db.session.add(i)
        db.session.commit()
    return render_template('index.html', form=form, post=post, like=like)
Ejemplo n.º 6
0
def echo_post():
    form = PostForm(request.form)
    user = current_user
    if request.method == 'POST':
        post = Post(form.content.data, user.id, form.matter_field.data)
        db.session.add(post)
        db.session.flush()
        db.session.refresh(post)
        mention_plate(form.content.data, post.id)
        db.session.commit()

    return (redirect(url_for('home')))
Ejemplo n.º 7
0
def chamado():
    form = CallForm()
    if form.category.data == 'None' or form.category.data == None:
        pass
    else:
        c = Post(form.category.data, form.subcategory.data, form.obs.data,
                 form.reward.data, User.get_name(current_user), 1)
        db.session.add(c)
        db.session.commit()
        aux = Post.query.filter_by(id=c.id).first()
        flash("Chamado número " + str(aux) + " efetuado com sucesso! ")
        return redirect(url_for("index"))

    return render_template('chamado.html', form=form)
Ejemplo n.º 8
0
def create_post():
    post = {
        'legend': request.json['legend'],
        'post_date': request.json['post_date'],
        'profile_id': request.json['profile_id'],
    }
    legend = post['legend']
    post_date = post['post_date']
    profile_id = post['profile_id']
    po = Post(legend, post_date, profile_id)

    db.session.add(po)
    db.session.commit()

    return jsonify({'post': post}), 201
Ejemplo n.º 9
0
def dashboard():
    form = TwitForm()
    if form.validate_on_submit():
        new_twit = Post(content=form.content.data, user_id=current_user.id)
        db.session.add(new_twit)
        db.session.commit()


    following = Follow.query.filter_by(follower_id=current_user.id).all()
    twits = []
    for follow in following:
        t = Post.query.filter_by(user_id=follow.user.id).all()
        twits.extend(t)
    my_twits = Post.query.filter_by(user_id=current_user.id).all()
    twits.extend(my_twits)
    return render_template('dashboard.html', twits=twits, form=form)
Ejemplo n.º 10
0
def upload_file():
    form = PostForm()
    if request.method == 'POST':
        if 'image' not in request.files:
            flash('No file part')
            return redirect(request.url)
        file = request.files['image']
        if file.filename == '':
            flash('No selected image')
            return redirect(request.url)
        if file:
            filename = secure_filename(file.filename)
            file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
            form.image_path = filename
            posted = Post(image_path=str(form.image_path),
                          content=str(form.local.data))
            db.session.add(posted)
            db.session.commit()
            return redirect(url_for('upload_file'))
    return render_template('upload.html', form=form)
Ejemplo n.º 11
0
def post():
    form = PostForm()
    filename = ''
    if form.validate_on_submit():
        file = request.files['file']
        if file and allowed_file(file.filename):
            filename = secure_filename(file.filename)
            file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
        else:
            flash('Arquivo não permitido')
            return redirect(url_for("index"))

        post = Post(title=form.title.data,
                    content=form.content.data,
                    user_id=current_user.id,
                    image=filename)
        db.session.add(post)
        db.session.commit()
        flash("Post enviado com sucesso")

    return redirect(url_for("index"))
Ejemplo n.º 12
0
def add():
    i = Post("novo post", 3)
    db.session.add(i)
    db.session.commit()
    return "Ok"