def route(self, name, params={}, full=False): """Get a route URI by its name. Arguments: name {string} -- Name of the route. Keyword Arguments: params {dict} -- Dictionary of parameters to pass to the route for compilation. (default: {{}}) full {bool} -- Specifies whether the full application url should be returned or not. (default: {False}) Returns: masonite.routes.Route|None -- Returns None if the route cannot be found. """ if full: route = application.URL + self._get_named_route(name, params) else: try: route = self._get_named_route(name, params) except KeyError: params.update(self.url_params) route = self._get_named_route(name, params) if not route: raise RouteException( "Route with the name of '{}' was not found.".format(name)) return route
def __init__(self, method_type=['GET']): """Post constructor.""" if not isinstance(method_type, list): raise RouteException( "Method type needs to be a list. Got '{}'".format(method_type)) # Make all method types in list uppercase self.method_type = [x.upper() for x in method_type] self.list_middleware = []
def __init__(self, method_type=['GET'], route=None, output=None): """Match constructor.""" if not isinstance(method_type, list): raise RouteException("Method type needs to be a list. Got '{}'".format(method_type)) # Make all method types in list uppercase self.method_type = [x.upper() for x in method_type] self.list_middleware = [] if route is not None and output is not None: self.route(route, output)
def _get_named_route(self, name, params): """Search the list of routes and returns the route with the name passed. Arguments: name {string} -- Route name to search for (dashboard.user). params {dict} -- Dictionary of items to pass to the named route. Returns: string|None -- Returns None if the route was not found or returns the compiled URI. """ web_routes = self.container.make('WebRoutes') for route in web_routes: if route.named_route == name: return self.compile_route_to_url(route.route_url, params) raise RouteException("Could not find the route with the name of '{}'".format(name))