Beispiel #1
0
    def mine(cls, handler):
        """
        Return current Cart for logged user
        """
        if not handler:
            raise IcebergNoHandlerError()

        data = handler.request("%s/mine/" % (cls.endpoint))
        return cls.findOrCreate(handler, data)
Beispiel #2
0
    def search(cls, handler, args=None):
        if not handler:
            raise IcebergNoHandlerError()

        data = handler.request("%s/" % cls.endpoint, args)
        res = []
        for element in data['objects']:
            res.append(cls.findOrCreate(handler, element))

        return res, data["meta"]  # cls.findOrCreate(data)
Beispiel #3
0
    def delete(self, handler=None):
        if not handler:
            if not self._handler:
                raise IcebergNoHandlerError()

            handler = self._handler

        handler.request(self.resource_uri, post_args={}, method="DELETE")
        # Clean
        self.__dict__ = {}
        self._unsaved_values = set()
Beispiel #4
0
    def mine(cls, handler, args=None):
        """
        Return administrable merchants for current user
        """
        if not handler:
            raise IcebergNoHandlerError()

        data = handler.request("%s/mine/" % (cls.endpoint), args)
        res = []
        for element in data['objects']:
            res.append(cls.findOrCreate(handler, element))

        return res, data['meta']
Beispiel #5
0
    def fetch(self, return_meta=False):
        """
        Resets the model's state from the server
        """
        if not self._handler:
            raise IcebergNoHandlerError()

        data = self._handler.request(self.resource_uri)
        meta = data.pop('meta', {})

        self._load_attributes_from_response(**data)

        if return_meta:
            return self, meta
        else:
            return self
Beispiel #6
0
    def save(self, handler=None):
        if not handler:
            if not self._handler:
                raise IcebergNoHandlerError()

            handler = self._handler

        if self.is_new():
            method = "POST"
            path = "%s/" % self.endpoint
        else:
            method = "PUT"
            path = self.resource_uri

        res = handler.request(path,
                              post_args=self.serialize(self),
                              method=method)
        self._load_attributes_from_response(**res)

        # Clean
        self._unsaved_values = set()

        return self
Beispiel #7
0
 def find(cls, handler, object_id):
     if not handler:
         raise IcebergNoHandlerError()
     data = handler.get_element(cls.endpoint, object_id)
     return cls.findOrCreate(handler, data)
Beispiel #8
0
    def me(cls, handler):
        if not handler:
            raise IcebergNoHandlerError()

        data = handler.request("%s/me/" % (cls.endpoint))
        return cls.findOrCreate(handler, data)