Exemplo n.º 1
0
def create_post():
  post = Post()
  if post.create(request.form['title'], request.form['description']):
    flash("New post was successfully published")
  else:
    flash("New post can't be published")

  return redirect(url_for('posts'))
Exemplo n.º 2
0
def post():
    post = Post()
    if request.method == "POST":
        text =  request.form["text"]
        if text != "":
            post.create(u"%s" % text)
            flash("created")
            return redirect("/posts")
    elif request.method == "GET":
        if session:
            admin = True
        else:
            admin = False
        return render_posts(admin)

    elif request.method == "DELETE":
        flash("destroyed")
        return render_posts()
    def exec(self, *args, **kwargs):
        try:
            bname = args[0]
            title = kwargs['title']
            content = kwargs['content']
        except (IndexError, KeyError):
            raise BadArgsException

        try:
            board = Board.get('name', bname)
        except ObjectNotExist:
            self.write('Board does not exist.')
            return

        uuid = 'post-{}'.format(gen_uuid())
        content = content.replace('<br>', '\n')

        Post.create(board.id, title, uuid, self.user)
        self.write(json.dumps({'uuid': uuid, 'content': content}))
Exemplo n.º 4
0
def post(user_id):
    sf = snowflake.generate(0, 0)
    data = request.get_json(force=True)

    # if user_id.id is not user_id.id:
    #     return make_response(jsonify(message='Unable to create new post, user id\'s did not match'), 401)

    new_post = Post.create(id=sf.__next__(),
                           author=user_id.id,
                           content=data['content'],
                           created_at=datetime.utcnow().strftime("%Y%m%d"),
                           updated_at=datetime.utcnow().strftime("%Y%m%d"),
                           likes=[])

    return jsonify(success=True,
                   message='New post was created successfully'), 200
Exemplo n.º 5
0
def create_post():
    # gets post data from client
    data = request.get_json()

    # creates the post
    post = Post.create(**data, user=current_user.id)

    # convert to dictionary and remove users password
    post_dict = model_to_dict(post)
    del post_dict['user']['password']

    return jsonify(data=post_dict,
                   status={
                       'code': 201,
                       'message': 'Successfully created post.'
                   })
Exemplo n.º 6
0
 def post(self):
     data = request.get_json()
     post = Post(**data)
     post.create()
     return post.json(), 201
Exemplo n.º 7
0
 def post(self):
     post = Post(**request.get_json())
     post.create()
     return post.json(), 201
Exemplo n.º 8
0
def store_post():
    Post.create(request.form)
    return redirect(url_for('posts.post_index'))
Exemplo n.º 9
0
def test_requests():
    response = requests.get('https://jsonplaceholder.typicode.com/posts')
    content = json.loads(response.text)
    for item in content:
        Post.create(item)
    return redirect('https://google.fr')