Example #1
0
  def post(self):
    '''
    Create new post
    '''
    post_id = None
    if 'id' in request.json:
      post_id = request.json['id']

    title = request.json['title']
    body = request.json['body']
    tags = request.json['tags']
    tags = [slugify(item) for item in tags]

    if (not title) or (not body):
      return jsonify({
        'error': 'title & body is required.',
        'data': {'title': title,
          'body': body,
          'slug': slugify(title)
           }
        })
    if post_id:
      post = Post.objects.get(id=post_id)
    else:
      post = Post(author=current_user.id)

    post.title = title
    post.body = body
    post.slug = slugify(title)
    post.tags = tags
    post.save()
    return jsonify({
        'success': 'success',
        'post' : post,
        'edit_url': post.get_edit_url()
        })