Пример #1
0
    def on_post(self, req, resp, album, user):
        photo = Status.get_or_none(Status.id == req.get_param('photo'))
        album = Album.get_or_none(Album.id == album)

        print(album, photo)

        if album and photo:
            RelationAlbumStatus.create(album=album, photo=photo)

            resp.body = json.dumps({"Result": "Status successfully modified"})
            resp.status = falcon.HTTP_200
        else:
            resp.body = json.dumps({"Error": "Error creating relation"})
            resp.status = falcon.HTTP_500
Пример #2
0
    def on_get(self, req, resp, pid):
        #photo = self.model.get_or_none(identifier=pid)
        album = Album.get_or_none(Album_id == pid)

        if album != None:
            if album.public or (album.private
                                and album.user == req.context['user']):
                result = json.dumps(album.json(), default=str)
            else:
                raise falcon.HTTPUnauthorized(
                    title='401 Unauthorized',
                    description='Invalid user or token missing',
                    challenges=None)

        else:
            result = json.dumps({"Error": 'Not found'})

        resp.body = result
        resp.set_header('Response by:', 'zinat')
        resp.status = falcon.HTTP_200