Esempio n. 1
0
def post_request_impl(args):
    try:
        poster = user_from_token(args['token'])
        group = group_from_id(args['group_id'])

        user_is_a_approved_subscriber(poster, group)

        new_post = Post(args['content'], args['anon'])
        if args.has_key("picture") and args['picture'] is not None:
            output = s3_upload(args['picture'])
            url = 'https://{}.s3.amazonaws.com/{}'.format(os.environ['S3_BUCKET_NAME'], output)
            new_post.pic = url
        group.posts.append(new_post)
        poster.posts.append(new_post)
        db.session.add(new_post)
        db.session.commit()

        #notifications
        if new_post.anon == 1:
            post_auth_request_notification.delay(new_post)

        return Response(True, "Posted Successfully", PostSchema().dumps(new_post).data).output()
    except Exception as exception:
        return Response(False, str(exception), None).output()