def build_routers(self, prefix: str) -> List[Tuple[str, "Router"]]: internal_routes = [] for inter_prefix, inter_router in self._routers: _route = normalize_path("/".join((prefix, inter_prefix))).lstrip("/") internal_routes.extend(inter_router.build_routers(_route)) return [(prefix, self), *internal_routes]
def build_routers(self, prefix): internal_routes = [] for inter_prefix, inter_router in self._routers: _route = normalize_path("/".join( (prefix, inter_prefix))).lstrip("/") internal_routes = inter_router.build_routers(_route) return [(prefix, self), *internal_routes]
def get_paths(self): result = {} for prefix, router in self.api._routers: for path, path_view in router.operations.items(): full_path = "/".join([i for i in (prefix, path) if i]) full_path = "/" + self.path_prefix + full_path full_path = normalize_path(full_path) result[full_path] = self.methods(path_view.operations) return result
def urls_paths(self, prefix: str): for path, path_view in self.operations.items(): path = path.replace("{", "<").replace("}", ">") route = "/".join([i for i in (prefix, path) if i]) # to skip lot of checks we simply treat double slash as a mistake: route = normalize_path(route) route = route.lstrip("/") yield django_path(route, path_view.get_view())
def get_paths(self) -> DictStrAny: result = {} for prefix, router in self.api._routers: for path, path_view in router.path_operations.items(): full_path = "/".join([i for i in (prefix, path) if i]) full_path = "/" + self.path_prefix + full_path full_path = normalize_path(full_path) full_path = re.sub(r"{[^}:]+:", "{", full_path) # remove path converters path_methods = self.methods(path_view.operations) if path_methods: result[full_path] = path_methods return result
def build_routers(self, prefix: str) -> List[Tuple[str, "Router"]]: if self.api is not None: from ninja.main import debug_server_url_reimport if not debug_server_url_reimport(): raise ConfigError( f"Router@'{prefix}' has already been attached to API {self.api.title}:{self.api.version} " ) internal_routes = [] for inter_prefix, inter_router in self._routers: _route = normalize_path("/".join((prefix, inter_prefix))).lstrip("/") internal_routes.extend(inter_router.build_routers(_route)) return [(prefix, self), *internal_routes]
def urls_paths(self, prefix: str) -> Iterator[URLPattern]: prefix = replace_path_param_notation(prefix) for path, path_view in self.path_operations.items(): path = replace_path_param_notation(path) route = "/".join([i for i in (prefix, path) if i]) # to skip lot of checks we simply treat double slash as a mistake: route = normalize_path(route) route = route.lstrip("/") url_name = path_view.url_name or "" if not url_name and self.api: url_name = self.api.get_operation_url_name( path_view.operations[0], router=self ) yield django_path(route, path_view.get_view(), name=url_name)
def add_router( self, prefix: str, router: Router, *, auth: Any = NOT_SET, tags: Optional[List[str]] = None, parent_router: Router = None, ) -> None: if auth != NOT_SET: router.auth = auth if tags is not None: router.tags = tags if parent_router: parent_prefix = next( # pragma: no cover (path for path, r in self._routers if r is parent_router), None ) assert parent_prefix is not None prefix = normalize_path("/".join((parent_prefix, prefix))).lstrip("/") self._routers.extend(router.build_routers(prefix)) router.set_api_instance(self)