Skip to content

Commit

Permalink
Refactor failthrough mapping logic
Browse files Browse the repository at this point in the history
  • Loading branch information
dannon committed Mar 14, 2017
1 parent 93c2286 commit 061b7d7
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/galaxy/web/framework/base.py
Expand Up @@ -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, failthrough=None ):
# Get the controller class
controller_name = map_match.pop( 'controller', None )
controller = controllers.get( controller_name, None )
Expand All @@ -149,7 +149,10 @@ 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 failthrough:
return self._resolve_map_match( failthrough, path_info, controllers )
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 +169,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 )
clientmatch = self.clientside_routes.match( path_info, environ )
map_match = self.mapper.match( path_info, environ ) or clientmatch
if path_info.startswith('/api'):
environ[ 'is_api_request' ] = True
controllers = self.api_controllers
Expand All @@ -187,7 +191,7 @@ 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 )
controller_name, controller, action, method = self._resolve_map_match( map_match, path_info, controllers, failthrough=clientmatch)
except httpexceptions.HTTPNotFound:
# Failed, let's check client routes
if not environ[ 'is_api_request' ]:
Expand Down

0 comments on commit 061b7d7

Please sign in to comment.