Example #1
0
 def before(self):
     """Create a post in the DB."""
     self.new_post = Post()
     self.new_post.schema = 'https://tent.io/types/post/status/v0.1.0'
     self.new_post.content = {'text': 'test', 'location': None}
     self.new_post.entity = self.entity
     self.new_post.save()
Example #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