def delete(self): """Delete this model """ res = utils.json_request(requests.delete, self._id_url()) if res.status_code // 100 != 2: raise errors.TalusApiError("Could not delete model", error=res.text) self._fields = {}
def save(self): """Save this model's fields """ files = None data = json.dumps(self._filtered_fields()) if "id" in self._fields: res = utils.json_request(requests.put, self._id_url(), data=data) else: res = utils.json_request(requests.post, self.api_url(self.api_base), data=data) # yes, that's intentional (the //) - look it up if res.status_code // 100 != 2: raise errors.TalusApiError("Could not save model", error=res.text) self._populate(res.json())
def save(self): """Save this model's fields """ files = None data = json.dumps(self._filtered_fields()) if "id" in self._fields: res = utils.json_request( requests.put, self._id_url(), data=data ) else: res = utils.json_request( requests.post, self.api_url(self.api_base), data=data ) # yes, that's intentional (the //) - look it up if res.status_code // 100 != 2: raise errors.TalusApiError("Could not save model", error=res.text) self._populate(res.json())
def objects_raw(cls, api_base=None, **search): """Return a list of json objects :api_base: The base of the api url. If none, models.API_BASE will be used :**search: search params :returns: A list of models as json objects (raw) """ r = utils.json_request(requests.get, cls.api_url(api_base), params=search) try: res = r.json() return res # TODO maybe there should be better error handling here?? except: return []