Exemplo n.º 1
0
def makePosts():
    form = NewPost()
    if not session.get('logged_in'):
        return redirect(url_for('login'))
#If the user tries to post and is not logged in, redirects them to login.
    if form.validate_on_submit():
        body = form.body.data
        title = form.title.data
        user = User.objects(alias = session.get("alias")).get()
        p = Posts(author = user, title = title, content = body, postid=str(uuid.uuid4())[:8])
        p.save()
        return redirect(url_for('viewPost', pid=str(p.postid)))
    return render_template("submitPost.html", form=form)
Exemplo n.º 2
0
def newPost():
    form = NewPost()
    topic = request.args.get('topic')
    if form.validate_on_submit():
        data = request.form
        newPost = Post(content=data['content'],
                       topic=topic,
                       author=current_user.username)
        activity = Activity(name=current_user.username,
                            type='p',
                            topic=newPost.topic)
        db.session.add(newPost)
        db.session.add(activity)
        db.session.commit()
        return redirect(request.referrer)
    return redirect(request.referrer)
Exemplo n.º 3
0
def allTopics():
	form = NewTopic()
	form1 = NewPost()
	topic = request.args.get('topic')
	if topic:
		post = Post.query.filter_by(topic = topic)
		return render_template('Forum.html',form=form1,posts = post,topic = topic)
	Topics = Topic.query.all()
	return render_template('All Topics.html',form = form, Topics = Topics)
Exemplo n.º 4
0
def updateP():
    form = NewPost()
    id = request.args.get('id')
    if id:
        data = request.form
        post = Post.query.filter_by(id=id).first()
        post.content = data['content']
        topic = post.topic
        db.session.add(post)
        db.session.commit()
        return redirect("/forum?topic=%s" % topic)
    return redirect("/forum")
Exemplo n.º 5
0
def new_post():
    """Find coordinates for post"""

    form = NewPost()

    if form.validate_on_submit():
        # make new model

        title = form.title.data
        image = form.image.data
        description = form.description.data
        time = datetime.now()

        #return coordinates [lng, lat] format for db storage
        lat = float(request.form['coord_lat'])
        lng = float(request.form['coord_lng'])

        # get location name
        location_url = f"https://api.mapbox.com/geocoding/v5/mapbox.places/{lng},{lat}.json?access_token={MAPBOX_TOKEN}"

        res = requests.get(location_url).json()
        loc = res['features'][0]['place_name']

        user = g.user.id

        new_post = Post(title=title,
                        image=image,
                        description=description,
                        lat=lat,
                        lng=lng,
                        created_dt=time,
                        place_name=loc,
                        user_id=user)
        db.session.add(new_post)
        db.session.commit()
        return redirect(f"/users/{g.user.username}")
    else:
        return render_template('/posts/new_post.html', form=form)

    return render_template('/posts/new_post.html', form=form)
Exemplo n.º 6
0
def update():
    update = request.args.get('update')
    form = NewPost()
    if update:
        up = Post.query.filter_by(id=update).first()
        return render_template('update.html', update=up, form=form)