コード例 #1
0
    def one_child_resource(self, resource, field, *args, **kwargs):
        query = QueryBuffer(self.model, auto=False).one(self.key, resource)
        instance = query.one(self.key, resource).data
        path = field.split('/')
        prop = None

        if not instance:
            return self.exception(HTTPNotFound())

        if len(path) > 1:
            child = None
            data = query.data
            endpoint = path.pop()
            for idx, item in enumerate(path):
                if isinstance(data, int) or isinstance(data, str):
                    raise HTTPBadRequest(msg='Cannot query this data type')
                if isinstance(data, list):
                    child = data[int(item)]
                else:
                    child = getattr(instance, item)
            data = getattr(child, endpoint)
            prop = endpoint
        else:
            prop = field
            data = getattr(instance, field)

        return HTTPSuccess({prop: data}, path=field.split('/'))
コード例 #2
0
    def one(self, resource, *args, **kwargs):
        """
        The principal GET by ID handler for the RouteBuilder. All GET requests
        that are structured like so:

        `HTTP GET http://localhost:5000/<prefix>/<route-model>/<uuid>`

        (Where <your-blueprint> represents a particular resource mapping).

        (Where <uuid> represents an database instance ID).

        This will use the RouteBuilder DAO and then fetch data for the
        assigned model. In this case, selecting only one, by UUID.

        :return: response object with application/json content-type preset.
        :rtype: Type[JsonResponse]
        """

        if isinstance(resource, str) and resource.endswith('/'):
            resource = resource.split('/').pop(0)

        query = QueryBuffer(self.model)
        resp = query.one(self.key, resource)

        if not resp:
            return self.exception(HTTPNotFound())

        return self.response(HTTPSuccess(self.json(query.data, **query.queryargs.__dict__)))
コード例 #3
0
    def head(self, resource):
        query = QueryBuffer(self.model)
        resp = query.one(self.key, resource)

        if not resp:
            return self.exception(HTTPNotFound())
        return HTTPSuccess()
コード例 #4
0
ファイル: routes.py プロジェクト: kmjbyrne/flask-atomic
    def one_child_resource(self, resource, field, *args, **kwargs):
        query = QueryBuffer(self.model, auto=False).one(self.key, resource)
        modeltree = field.split('/')

        if len(modeltree):
            data = query.data
            for item in modeltree:
                if isinstance(data, list):
                    data = data[int(item)]
                else:
                    data = getattr(data, item)

        if resource in columns(self.model, strformat=True):
            return HTTPSuccess({resource: getattr(query.data, resource)})
        child = getattr(self.model, resource).comparator.entity.class_
        return HTTPSuccess(serialize(child, getattr(query.data, resource)))
コード例 #5
0
ファイル: routes.py プロジェクト: kmjbyrne/flask-atomic
    def one(self, resource, *args, **kwargs):
        """
        The principal GET by ID handler for the RouteBuilder. All GET requests
        that are structured like so:

        `HTTP GET http://localhost:5000/<prefix>/<route-model>/<uuid>`

        (Where <your-blueprint> represents a particular resource mapping).

        (Where <uuid> represents an database instance ID).

        This will use the RouteBuilder DAO and then fetch data for the
        assigned model. In this case, selecting only one, by UUID.

        :return: response object with application/json content-type preset.
        :rtype: Type[JsonResponse]
        """

        if resource == self.model.__tablename__:
            return self.get(*args, **kwargs)

        query = QueryBuffer(self.model)
        data = query.get(resource, self.key)
        if not data:
            return HTTPNotFound().pack()
        return HTTPSuccess(
            serialize(self.model, data, rels=query.queryargs.rels))
コード例 #6
0
    def get(self, *args, **kwargs):
        """
        The principal GET handler for the RouteBuilder. All GET requests that are
        structured like so:

        `HTTP GET http://localhost:5000/<prefix>/<route-model>`

        (Where your-blueprint represents a particular resource mapping).

        Will be routed to this function. This will use the RouteBuilder DAO
        and then fetch data for the assigned model. In this case, select all.

        :return: response object with application/json content-type preset.
        :rtype: HTTPSuccess
        """

        query = QueryBuffer(self.model).all()
        return self.response(HTTPSuccess(self.json(query.data, **query.queryargs.__dict__)))