Skip to content

Commit

Permalink
Merge branch 'aleeexgreeen-midnight_blue-header'
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed Nov 29, 2024
2 parents a3d58f7 + c51d967 commit 3e10554
Show file tree
Hide file tree
Showing 11 changed files with 1,296 additions and 1,165 deletions.
3 changes: 3 additions & 0 deletions changes/8492.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Adds new logo and updates UI header in `midnight-blue` theme.
Adds macro for creating navigation links.
Adds helpers `endpoint_from_url` and `page_is_active`.
38 changes: 37 additions & 1 deletion ckan/lib/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from markdown import markdown
from bleach import clean as bleach_clean, ALLOWED_TAGS, ALLOWED_ATTRIBUTES
from ckan.common import asbool, config, current_user
from flask import flash, has_request_context
from flask import flash, has_request_context, current_app
from flask import get_flashed_messages as _flask_get_flashed_messages
from flask import redirect as _flask_redirect
from flask import url_for as _flask_default_url_for
Expand Down Expand Up @@ -739,6 +739,42 @@ def get_flashed_messages(**kwargs: Any):
return _flask_get_flashed_messages(**kwargs)


@core_helper
def endpoint_from_url(url: str) -> str:
try:
urls = current_app.url_map.bind("")
match = urls.match(url)
endpoint = match[0]
except RuntimeError:
endpoint = ""
return endpoint


@core_helper
def page_is_active(
menu_item: str, active_blueprints: Optional[list[str]] = None) -> bool:
'''
Returns whether the current link is the active page or not.
`menu_item`
Accepts a route (e.g. 'group.index') or a URL (e.g. '/group')
`active_blueprints`
contains a list of additional blueprints that should be considered
active besides the one in `menu_item`
'''
if menu_item.startswith("/"):
menu_item = endpoint_from_url(menu_item)

blueprint, endpoint = menu_item.split('.')

item = {
'controller': blueprint,
'action': endpoint,
'highlight_controllers': active_blueprints,
}
return _link_active(item)


def _link_active(kwargs: Any) -> bool:
''' creates classes for the link_to calls '''
blueprint, endpoint = p.toolkit.get_endpoint()
Expand Down
Loading

0 comments on commit 3e10554

Please sign in to comment.