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)
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)
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()
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']
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
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
def find(cls, handler, object_id): if not handler: raise IcebergNoHandlerError() data = handler.get_element(cls.endpoint, object_id) return cls.findOrCreate(handler, data)
def me(cls, handler): if not handler: raise IcebergNoHandlerError() data = handler.request("%s/me/" % (cls.endpoint)) return cls.findOrCreate(handler, data)