示例#1
0
def edit_post(id):
    """ Edit a post """
    p = Post.query.get(id)
    if p.author_id != current_user.id:
        return 'This isn\'t your post!!!'
    else:
        ### Text post
        if isinstance(p, TextPost):
            form = CreatePostForm(title=p.title,
                                  text=p.text,
                                  latitude=p.latitude,
                                  longitude=p.longitude)

            if form.validate_on_submit():
                p.title = form.title.data
                p.text = form.text.data
                p.latitude = form.latitude.data
                p.longitude = form.longitude.data
                db.session.commit()
                return redirect(url_for('.post', id=p.id))
            return render_template('user/text.html', form=form, pid=p.id)
        ### Image post
        if isinstance(p, ImagePost):
            form = CreateImageForm(title=p.title,
                                   caption=p.caption,
                                   latitude=p.latitude,
                                   longitude=p.longitude)

            if form.validate_on_submit():
                p.title = form.title.data
                p.text = form.caption.data
                p.latitude = form.latitude.data
                p.longitude = form.longitude.data
                p.loc = 'POINT({0} {1})'.format(form.longitude.data,
                                                form.latitude.data)
                db.session.commit()
                return redirect(url_for('.post', id=p.id))
            return render_template('user/image.html', form=form, pid=p.id)
示例#2
0
def edit_post(id):
  """ Edit a post """
  p = Post.query.get(id)
  if p.author_id != current_user.id:
    return 'This isn\'t your post!!!'
  else:
    ### Text post
    if isinstance(p, TextPost):
      form = CreatePostForm(title=p.title,
                            text=p.text,
                            latitude=p.latitude,
                            longitude=p.longitude)

      if form.validate_on_submit():
        p.title=form.title.data
        p.text=form.text.data
        p.latitude=form.latitude.data
        p.longitude=form.longitude.data
        db.session.commit()
        return redirect(url_for('.post', id=p.id))
      return render_template('user/text.html', form=form, pid=p.id)
    ### Image post
    if isinstance(p, ImagePost):
      form = CreateImageForm(title=p.title,
                            caption=p.caption,
                            latitude=p.latitude,
                            longitude=p.longitude)

      if form.validate_on_submit():
        p.title=form.title.data
        p.text=form.caption.data
        p.latitude=form.latitude.data
        p.longitude=form.longitude.data
        p.loc = 'POINT({0} {1})'.format(form.longitude.data,form.latitude.data)
        db.session.commit()
        return redirect(url_for('.post', id=p.id))
      return render_template('user/image.html', form=form, pid=p.id)
示例#3
0
def new_text():
  """ Write a new text post page """
  form = CreatePostForm()
  
  if form.validate_on_submit():
    t = datetime.utcnow()
    textpost = TextPost(author=current_user._get_current_object(),
              title=form.title.data,
              timestamp=t,
              text=form.text.data,
              latitude=form.latitude.data,
              longitude=form.longitude.data,
              loc='POINT({0} {1})'.format(form.longitude.data,form.latitude.data))

    db.session.add(textpost)
    db.session.commit()

    flash("You made a new post!")
    return redirect(url_for('.post', id=textpost.id))
  return render_template('user/text.html', form=form)
示例#4
0
def new_text():
    """ Write a new text post page """
    form = CreatePostForm()

    if form.validate_on_submit():
        t = datetime.utcnow()
        textpost = TextPost(author=current_user._get_current_object(),
                            title=form.title.data,
                            timestamp=t,
                            text=form.text.data,
                            latitude=form.latitude.data,
                            longitude=form.longitude.data,
                            loc='POINT({0} {1})'.format(
                                form.longitude.data, form.latitude.data))

        db.session.add(textpost)
        db.session.commit()

        flash("You made a new post!")
        return redirect(url_for('.post', id=textpost.id))
    return render_template('user/text.html', form=form)