Skip to content

Commit

Permalink
Merge pull request #21 from dannon/ui_pref_routing
Browse files Browse the repository at this point in the history
Don't have the clientside mapper register itself
  • Loading branch information
guerler authored Mar 14, 2017
2 parents 38336e7 + 550bc42 commit 44fd8aa
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions lib/galaxy/web/framework/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,10 @@ def __init__( self ):
self.controllers = dict()
self.api_controllers = dict()
self.mapper = routes.Mapper()
self.clientside_routes = routes.Mapper()
self.clientside_routes = routes.Mapper(controller_scan=None, register=False)
# FIXME: The following two options are deprecated and should be
# removed. Consult the Routes documentation.
self.mapper.minimization = True
# self.mapper.explicit = False
self.transaction_factory = DefaultWebTransaction
# Set if trace logging is enabled
self.trace_logger = None
Expand Down Expand Up @@ -115,6 +114,7 @@ def finalize_config( self ):
"""
# Create/compile the regular expressions for route mapping
self.mapper.create_regs( self.controllers.keys() )
self.clientside_routes.create_regs()

def trace( self, **fields ):
if self.trace_logger:
Expand All @@ -138,7 +138,7 @@ def __call__( self, environ, start_response ):
if self.trace_logger:
self.trace_logger.context_remove( "request_id" )

def _resolve_map_match( self, map_match, path_info, controllers ):
def _resolve_map_match( self, map_match, path_info, controllers, use_default=True):
# Get the controller class
controller_name = map_match.pop( 'controller', None )
controller = controllers.get( controller_name, None )
Expand All @@ -149,7 +149,12 @@ def _resolve_map_match( self, map_match, path_info, controllers ):
# url_for invocations. Specifically, grids.
action = map_match.pop( 'action', 'index' )
method = getattr( controller, action, None )
if method is None and not use_default:
# Skip default, we do this, for example, when we want to fail
# through to another mapper.
raise httpexceptions.HTTPNotFound( "No action for " + path_info )
if method is None:
# no matching method, we try for a default
method = getattr( controller, 'default', None )
if method is None:
raise httpexceptions.HTTPNotFound( "No action for " + path_info )
Expand All @@ -166,7 +171,8 @@ def handle_request( self, environ, start_response, body_renderer=None ):
request_id = environ.get( 'request_id', 'unknown' )
# Map url using routes
path_info = environ.get( 'PATH_INFO', '' )
map_match = self.mapper.match( path_info, environ )
client_match = self.clientside_routes.match( path_info, environ )
map_match = self.mapper.match( path_info, environ ) or client_match
if path_info.startswith('/api'):
environ[ 'is_api_request' ] = True
controllers = self.api_controllers
Expand All @@ -187,12 +193,13 @@ def handle_request( self, environ, start_response, body_renderer=None ):
rc.redirect = trans.response.send_redirect
# Resolve mapping to controller/method
try:
controller_name, controller, action, method = self._resolve_map_match( map_match, path_info, controllers )
# We don't use default methods if there's a clientside match for this route.
use_default = client_match is None
controller_name, controller, action, method = self._resolve_map_match( map_match, path_info, controllers, use_default=use_default)
except httpexceptions.HTTPNotFound:
# Failed, let's check client routes
if not environ[ 'is_api_request' ]:
map_match = self.clientside_routes.match( path_info, environ )
controller_name, controller, action, method = self._resolve_map_match( map_match, path_info, controllers )
controller_name, controller, action, method = self._resolve_map_match( client_match, path_info, controllers )
else:
raise
trans.controller = controller_name
Expand Down

0 comments on commit 44fd8aa

Please sign in to comment.