The second beta of the new routing logic is in the trunk. The example file 
isn't quite up to date as I write, but it will be shortly. The text below is 
taken from it.

The underlying logic hasn't changed significantly, but the format of the 
routes.py file is new. You now specify routers, a dict of dicts. Each member of 
routers is a router (this is simpler than it sounds).

There are three kinds of routers.

BASE is the base router that contains global routing configuration such as the 
default application.

DEFAULT is the default app-specific routing configuration that serves as the 
starting point for app-specific routers (and *is* the router for apps that 
aren't explicitly listed.

The other routers are named for individual applications, so you can have a 
configuration like this:

routers = dict(

    # base router
    BASE = dict(
        default_application = 'welcome',
    ),

    # default application router
    DEFAULT = dict(),

    welcome = dict(),
)

...except that you don't need the 'welcome' router, since it doesn't change the 
default. 

In Python terms, the "effective router" for the welcome app is a composite of 
the specified routers, something like BASE.update(DEFAULT).update(welcome), so 
you can override values set in the default(s).

In fact, BASE and DEFAULT are themselves updates to built-in base and 
default-app routers (see below for what they contain). 

Give it a try.

One more thing: there's a new function, 
gluon.rewrite.get_effective_router(appname) that will return to you a private 
copy of the effective router (hence the name) of the app whose name you 
specify, or None if routing is not enabled or the appname isn't recognized. You 
can specify "BASE" or "DEFAULT" as the appname to get a copy of the base or 
default routers.

#  router is a dictionary of URL routing parameters.
#
#  For each request, the effective router is the default router (below),
#  updated by the base router (if any) from routes.py,
#  updated by the relevant application-specific router (if any)
#  from applications/app/routes.py.
#
#  Optional members of base router:
#
#  default_application: default application name
#  applications: list of all recognized applications, or 'ALL' to use all 
currently installed applications
#      Names in applications are always treated as an application names when 
they appear first in an incoming URL.
#  domains: dict used to map domain names to application names
#
#  These values may be overridden by app-specific routers:
#
#  default_controller: name of default controller
#  default_function: name of default function (all controllers)
#  root_static: list of static files accessed from root
#       (mapped to the selected application's static/ directory)
#
#
#  Optional members of application-specific router:
#
#  These values override those in the base router:
#
#  default_controller
#  default_function
#  root_static
#
#  When these appear in the base router, they apply to the default application 
only:
#
#  domain: the domain that maps to this application (alternative to using 
domains in the base router)
#  languages: list of all supported languages
#      Names in controllers are always treated as language names when they 
appear in an incoming URL after
#      the (optional) application name. 
#  controllers: list of valid controllers in selected app
#       or "DEFAULT" to use all controllers in the selected app plus 'static'
#       or [] to disable controller-name omission
#      Names in controllers are always treated as controller names when they 
appear in an incoming URL after
#      the (optional) application and language names. 
#  default_language
#       The language code (for example: en, it-it) optionally appears in the 
URL following
#       the application (which may be omitted). For incoming URLs, the code is 
copied to
#       request.language; for outgoing URLs it is taken from request.language.
#       If languages=[], language support is disabled.
#       The default_language, if any, is omitted from the URL.
#  check_args: set to False to suppress arg checking
#       request.raw_args always contains a list of raw args from the URL, not 
unquoted
#       request.args are the same values, unquoted
#       By default (check_args=True), args are required to match args_match.
#  acfe_match: regex for valid application, controller, function, extension 
/a/c/f.e
#  file_match: regex for valid file (used for static file names)
#  args_match: regex for valid args (see also check_args flag)
#
#
#  The built-in default routers supply default values (undefined members are 
None):
#
#     base_router = dict(
#         default_application = 'init',
#             applications = 'ALL',
#         root_static = ['favicon.ico', 'robots.txt'],
#         domains = dict(),
#         acfe_match = r'\w+$',              # legal app/ctlr/fcn/ext
#         file_match = r'(\w+[-=./]?)+$',    # legal file (path) name
#     )
#
#     default_router = dict(
#         default_controller = 'default',
#             controllers = 'DEFAULT',
#         default_function = 'index',
#         languages = [],
#         default_language = None,
#         check_args = True,
#         map_hyphen = True,
#         args_match = r'([\w@ -]+[=.]?)+$', # legal arg in args
#     )
#
#  See rewrite.map_url_in() and rewrite.map_url_out() for implementation 
details.


#  This simple router set overrides only the default application name,
#  but provides full rewrite functionality.

routers = dict(

    # base router
    BASE = dict(
        default_application = 'welcome',
    ),

    # default application router
    DEFAULT = dict(),
)

Reply via email to