def on_get(self, req: falcon.Request, resp: falcon.Response): if req.params.get("store-name", None): raise falcon.HTTPPermanentRedirect( "/view/store/" + req.params.get("store-name", None)) else: resp.context = { "stores": self._controller.list_stores(auth_token=auth_token(req)) }
def on_post(self, req: falcon.Request, resp: falcon.Response, store_id: str, project_id: str, asset_id: str): def _get_tags(): result = req.params.get("tags[]", None) if isinstance(result, str): result = [result] return result asset = { "id": req.params.get("id", ""), "name": req.params.get("name", ""), "project": req.params.get("project", "") } for field in OveAssetMeta.EDITABLE_FIELDS: asset[field] = req.params.get(field, "") asset["tags"] = _get_tags() resp.context = { "store_id": store_id, "project_id": project_id, "asset_id": asset_id, "create": False, "asset": asset } if asset_id == "new": resp.context["create"] = True resp.context["asset"] = self._controller.create_asset( store_id=store_id, project_id=project_id, asset=asset, auth_token=auth_token(req)) raise falcon.HTTPPermanentRedirect( location="/view/store/{}/project/{}/asset/{}".format( store_id, project_id, asset.get("id"))) else: resp.context["asset"] = self._controller.edit_asset( store_id=store_id, project_id=project_id, asset=asset, auth_token=auth_token(req))
def handle_api_exceptions(ex: Exception, req: falcon.Request, _resp: falcon.Response, _params): logging.debug("Handling api exception: %s", repr(ex)) if isinstance(ex, falcon.HTTPNotFound): logging.debug("%s. %s", ex.title, req.url) raise ex if isinstance(ex, (falcon.HTTPNotFound, falcon.HTTPNotImplemented)): raise falcon.HTTPPermanentRedirect(location="/404") if isinstance(ex, (falcon.HTTPPermanentRedirect, falcon.HTTPTemporaryRedirect, falcon.HTTPSeeOther)): raise ex if isinstance(ex, falcon.HTTPError): raise ex if isinstance(ex, ValidationError): raise falcon.HTTPBadRequest(title=ex.title, description=ex.description) raise falcon.HTTPBadRequest(title="Internal Server error", description=str(ex))
def on_head(self, req, resp): raise falcon.HTTPPermanentRedirect('/perm/redirect')
def on_head(self, req, resp): raise falcon.HTTPPermanentRedirect('/perm/redirect', headers={'foo': 'bar'})
def on_get(self, req: falcon.request.Request, resp: falcon.response.Response): raise falcon.HTTPPermanentRedirect(self.__location)