Esempio n. 1
0
    def post(self, authorized, fields):
        """
        Endpoint for creating new Posts
        """
        post = Post(**fields)

        # Fetch location name if not present and valid lat lon exists
        if post.location_lon is not None and post.location_lat is not None and post.location_name is None:
            post._fetch_friendly_location()

        # Save post
        result = _save_post(post, 201)

        # Check if the post was saved OK
        if result[1] != 201:
            return result

        # Tweet if public post
        if post.public:
            try:
                tweet = post_post_as_tweet(post)
            except Exception as e:
                return result

            post.tweet_id = tweet.id_str

            # Over-write result to new save of tweet_id
            result = _save_post(post, 201)

        return result