def on_post(self, req, resp): try: obj = rest_objects.from_http_req(objects.Organization, req) self.store.save(obj) resp.body = helpers.serialize(req, obj) resp.status = falcon.HTTP_201 resp.location = "/organizations/{0}".format(obj.uuid) except exc.BadInput as e: self._handle_400(resp, e)
def on_post(self, req, resp): try: obj = rest_objects.from_http_req(objects.User, req) self.store.save(obj) resp.body = helpers.serialize(req, obj) resp.status = falcon.HTTP_201 resp.location = "/users/{0}".format(obj.uuid) except exc.BadInput as e: resp.body = "Bad input: {0}".format(e) resp.status = falcon.HTTP_400
def on_put(self, req, resp, user_id): try: obj = rest_objects.from_http_req(objects.User, req) self.store.save(obj) resp.body = helpers.serialize(req, obj) resp.status = falcon.HTTP_200 resp.location = "/users/{0}".format(obj.uuid) except exc.BadInput as e: self._handle_400(resp, user_id, e) except exc.NotFound: self._handle_404(resp, user_id)
def on_post(self, req, resp, org_id): try: group = rest_objects.from_http_req( objects.Group, req, root_organization_uuid=org_id ) self.store.save(group) resp.body = helpers.serialize(req, group) resp.status = falcon.HTTP_201 resp.location = "/groups/{0}".format(group.id) except exc.NotFound: msg = "An organization with ID or slug {0} could not be found." msg = msg.format(org_id) resp.body = msg resp.status = falcon.HTTP_404 except exc.BadInput as e: resp.body = "Bad input: {0}".format(e) resp.status = falcon.HTTP_400
def on_post(self, req, resp, user_id): try: search_spec = search.SearchSpec.from_http_req(req) user = self.store.get_by_slug_or_key(objects.User, user_id, search_spec) except exc.NotFound: self._handle_404(resp, user_id) return try: obj = rest_objects.from_http_req(objects.UserPublicKey, req, user_uuid=user.uuid) self.store.save(obj) resp.body = helpers.serialize(req, obj) resp.status = falcon.HTTP_201 resp.location = "/users/{0}/keys/{1}".format(user.uuid, obj.fingerprint) except exc.BadInput as e: resp.body = "Bad input: {0}".format(e) resp.status = falcon.HTTP_400