Beispiel #1
0
    def post(self, entity):
        try:
            data = json.loads(request.data)
        except json.JSONDecodeError as e:
            raise APIBadRequest(str(e))
        new_post = Post()
        new_post.entity = entity
        new_post.schema = data['schema']
        new_post.content = data['content']

        new_post.save()

        for to_notify in entity.followers:
            notification_link = follow.get_notification_link(to_notify)
            requests.post(notification_link, data=jsonify(new_post.to_json()))
            #TODO Handle failled notifications somehow

        return jsonify(new_post.to_json()), 200
Beispiel #2
0
    def post(self, entity):
        try:
            data = json.loads(request.data)
        except json.JSONDecodeError as e:
            raise APIBadRequest(str(e))
        new_post = Post()
        new_post.entity = entity
        new_post.schema = data["schema"]
        new_post.content = data["content"]

        new_post.save()

        for to_notify in entity.followers:
            notification_link = follow.get_notification_link(to_notify)
            requests.post(notification_link, data=jsonify(new_post.to_json()))
            # TODO Handle failled notifications somehow

        return jsonify(new_post.to_json()), 200
Beispiel #3
0
    def post(self):
        """ Used by apps to create a new post.

        Used by other servers to notify of a mention from a non-followed
        entity.

        TODO: Separate between apps creating a new post and a notification
        from a non-followed entity.
        """
        new_post = Post()
        new_post.entity = g.entity
        new_post.schema = request.json['schema']
        new_post.content = request.json['content']

        new_post.save()

        # TODO: Do this asynchronously?
        for to_notify in g.entity.followers:
            notification_link = follow.get_notification_link(to_notify)
            requests.post(notification_link, data=jsonify(new_post.to_json()))
            # TODO: Handle failed notifications somehow

        return jsonify(new_post)
Beispiel #4
0
    def post(self):
        """ Used by apps to create a new post.

        Used by other servers to notify of a mention from a non-followed
        entity.

        TODO: Separate between apps creating a new post and a notification
        from a non-followed entity.
        """
        new_post = Post()
        new_post.entity = g.entity
        new_post.schema = request.json['schema']
        new_post.content = request.json['content']

        new_post.save()

        # TODO: Do this asynchronously?
        for to_notify in g.entity.followers:
            notification_link = follow.get_notification_link(to_notify)
            requests.post(notification_link, data=jsonify(new_post.to_json()))
            # TODO: Handle failed notifications somehow

        return jsonify(new_post)