Skip to content

Commit

Permalink
Merge pull request #4571 from smotornyuk/commonly-use-get-endpoint
Browse files Browse the repository at this point in the history
Replace direct calls to endpoint.split with convenient helper
  • Loading branch information
wardi committed Dec 4, 2018
2 parents 78a4022 + 09f9f7a commit 96444ce
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
6 changes: 3 additions & 3 deletions ckan/lib/helpers.py
Expand Up @@ -731,7 +731,7 @@ def _link_active_pylons(kwargs):


def _link_active_flask(kwargs):
blueprint, endpoint = request.url_rule.endpoint.split('.')
blueprint, endpoint = p.toolkit.get_endpoint()
return(kwargs.get('controller') == blueprint and
kwargs.get('action') == endpoint)

Expand Down Expand Up @@ -785,7 +785,7 @@ def nav_link(text, *args, **kwargs):
def nav_link_flask(text, *args, **kwargs):
if len(args) > 1:
raise Exception('Too many unnamed parameters supplied')
blueprint, endpoint = request.url_rule.endpoint.split('.')
blueprint, endpoint = p.toolkit.get_endpoint()
if args:
kwargs['controller'] = blueprint or None
kwargs['action'] = endpoint or None
Expand Down Expand Up @@ -1805,7 +1805,7 @@ def _create_url_with_params(params=None, controller=None, action=None,
if not controller:
controller = getattr(c, 'controller', False) or request.blueprint
if not action:
action = getattr(c, 'action', False) or request.endpoint.split('.')[1]
action = getattr(c, 'action', False) or p.toolkit.get_endpoint()[1]
if not extras:
extras = {}

Expand Down
9 changes: 1 addition & 8 deletions ckan/views/__init__.py
Expand Up @@ -204,11 +204,4 @@ def _get_user_for_apikey():


def set_controller_and_action():
try:
controller, action = request.endpoint.split(u'.')
except ValueError:
log.debug(
u'Endpoint does not contain dot: {}'.format(request.endpoint)
)
controller = action = request.endpoint
g.controller, g.action = controller, action
g.controller, g.action = p.toolkit.get_endpoint()
2 changes: 1 addition & 1 deletion ckan/views/user.py
Expand Up @@ -78,7 +78,7 @@ def before_request():
context = dict(model=model, user=g.user, auth_user_obj=g.userobj)
logic.check_access(u'site_read', context)
except logic.NotAuthorized:
_, action = request.url_rule.endpoint.split(u'.')
_, action = plugins.toolkit.get_endpoint()
if action not in (
u'login',
u'request_reset',
Expand Down

0 comments on commit 96444ce

Please sign in to comment.