Ejemplo n.º 1
0
    def get(self, username):
        user = User.get_or_none(username=username)
        pagination = ap_pagination(self)
        if user:
            user = user.profile.get()

            # Retrive statuses
            objects = []
            for k in TimelineManager(user).query():
                try:
                    objects.append(
                        Status.get(
                            Status.identifier == status).to_activitystream())
                except:
                    pass

            print(objects)
            # create collection page
            collectionPage = activities.OrderedCollectionPage(
                map(activities.Note, objects), **pagination)

            # create collection
            collection = activities.OrderedCollection([collectionPage])
            self.write(json.dumps(collectionPage.to_json(context=True)))
            self.set_status(200)
Ejemplo n.º 2
0
    def on_get(self, req, resp, username):
        user = User.get_or_none(username == username)
        objects = user.photos.select().order_by(Status.created_at.desc())

        collectionPage = activities.OrderedCollectionPage(
            map(activities.Note, objects))
        collection = activities.OrderedCollection([collectionPage])
        resp.body = json.dumps(collection.to_json(context=True))
        resp.status = falcon.HTTP_200
Ejemplo n.º 3
0
 def on_get(self, req, resp, username):
     user = UserProfile.get_or_none(username=username)
     if user:
         followers = [follower.uris.id for follower in user.followers()]
         resp.body = json.dumps(
             activities.OrderedCollection(followers).to_json(), default=str)
         resp.status = falcon.HTTP_200
     else:
         resp.status = falcon.HTTP_404
Ejemplo n.º 4
0
    def on_get(self, req, resp, username):

        user = req.context['user']
        objects = user.activities.select().where(remote == True).order_by(
            created_at.desc())
        collection = activities.OrderedCollection(objects)

        resp.body = collection.to_json(context=True)
        resp.status = falcon.HTTP_200
Ejemplo n.º 5
0
    def on_get(self, req, resp, username):
        user = User.get_or_none(username=username)

        if user:
            user = user.profile.get()

            objects = [
                Status.get_by_id(int(status))
                for status in TimelineManager(user).query() if status
            ]
            collectionPage = activities.OrderedCollectionPage(
                map(activities.Note, objects))
            collection = activities.OrderedCollection([collectionPage])
            resp.body = json.dumps(collection.to_json(context=True))
            resp.status = falcon.HTTP_200
Ejemplo n.º 6
0
    async def get(self, username):
        user = User.get_or_none(username=username)
        pagination = ap_pagination(self)
        if user:
            user = user.profile.get()

            # Retrive statuses

            objects = await self.application.objects.execute(
                Status.select().where(Status.user == user).order_by(
                    Status.id).paginate(pagination['page'],
                                        pagination['default_pagination']))
            objects = map(lambda x: x.to_activitystream(), objects)
            # create collection page
            collectionPage = activities.OrderedCollectionPage(
                map(activities.Note, objects), **pagination)

            # create collection
            collection = activities.OrderedCollection([collectionPage])
            self.write(json.dumps(collectionPage.to_json(context=True)))
            self.set_status(200)
Ejemplo n.º 7
0
    def on_get(self, req, resp, username):
        user = User.get_or_none(username=username)

        if user:
            user = user.profile.get()
            page = req.context['pagination']['page']
            default_pagination = req.context['pagination'][
                'default_pagination']
            if page:
                # In this case the page params is given
                info = {
                    'id': req.context['pagination']['id'],
                    'partOf': req.context['pagination']['partOf'],
                }
                following = [
                    follower.uris.id for follower in user.following().paginate(
                        page, default_pagination)
                ]
                if followers:
                    info['next'] = req.context['pagination']['next']

                resp.body = json.dumps(activities.OrderedCollectionPage(
                    following, **info).to_json(),
                                       default=str)
                resp.status = falcon.HTTP_200
            else:
                # We return the 0 page
                info = {
                    'id': req.context['pagination']['id'],
                    'first': f"{req.context['pagination']['partOf']}?page=1",
                }
                resp.body = json.dumps(
                    activities.OrderedCollection(**info).to_json())

        else:
            logger.debug(f'User not found {username}. AcitivtyPub/following')
            raise falcon.HTTPNotFound(decription="User not found")