Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change background colour and add markdown support #26

Merged
merged 3 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion ckanext/status/lib/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
# Created by the Natural History Museum in London, UK

from ckan.plugins import toolkit
import markdown


def status_enable_html():
return toolkit.asbool(toolkit.config.get('ckanext.status.enable_html', True))


def status_get_message():
Expand All @@ -15,4 +20,7 @@ def status_get_message():
:rtype: string
"""

return toolkit.config.get('ckanext.status.message', None)
status_message = toolkit.config.get('ckanext.status.message', None)
if status_message and status_enable_html():
status_message = markdown.markdown(status_message)
return status_message
7 changes: 5 additions & 2 deletions ckanext/status/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Created by the Natural History Museum in London, UK

from ckan.plugins import SingletonPlugin, implements, interfaces, toolkit
from ckanext.status.lib.helpers import status_get_message
from ckanext.status.lib.helpers import status_get_message, status_enable_html


class StatusPlugin(SingletonPlugin):
Expand Down Expand Up @@ -33,4 +33,7 @@ def update_config_schema(self, schema):

# ITemplateHelpers
def get_helpers(self):
return {'status_get_message': status_get_message}
return {
'status_get_message': status_get_message,
'status_enable_html': status_enable_html,
}
13 changes: 11 additions & 2 deletions ckanext/status/theme/assets/less/status.less
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
#status-bar {
text-align: center;
background-color: #195d0d;
color: #ffffff;
background-color: var(--ckanext-status-bar-bg, #772e8a);
color: var(--ckanext-status-bar-fg, #ffffff);
margin: 0;
font-size: 1.3em;
padding: 5px 0 10px;

& p {
margin: 0;
}

& a {
color: var(--ckanext-status-bar-fg, #ffffff);
text-decoration: underline;
}
}
8 changes: 7 additions & 1 deletion ckanext/status/theme/templates/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
{% block skip %}
{% if h.status_get_message() %}
{% asset 'ckanext-status/main' %}
<p id="status-bar">{{ h.status_get_message() }}</p>
<div id="status-bar">
{% if h.status_enable_html() %}
{{ h.status_get_message()|safe }}
{% else %}
{{ h.status_get_message() }}
{% endif %}
</div>
{% endif %}
{{ super() }}
{% endblock %}
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ classifiers = [
"Programming Language :: Python :: 3.8"
]
dependencies = [
"ckantools>=0.3.0"
"ckantools>=0.3.0",
"markdown~=3.4"
]

[project.optional-dependencies]
Expand Down
14 changes: 14 additions & 0 deletions tests/test_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,33 @@
import pytest
from ckan.plugins import toolkit
from ckanext.status.lib.helpers import status_get_message
import markdown

TEST_MESSAGE = 'this is a test message'
MARKDOWN_TEST_MESSAGE = '_this_ is a test **message**'
HTML_TEST_MESSAGE = '<p><em>this</em> is a test <strong>message</strong></p>'


@pytest.mark.filterwarnings('ignore::sqlalchemy.exc.SADeprecationWarning')
@pytest.mark.ckan_config('ckan.plugins', 'status')
@pytest.mark.ckan_config('ckanext.status.message', TEST_MESSAGE)
@pytest.mark.ckan_config('ckanext.status.enable_html', False)
@pytest.mark.usefixtures('with_plugins')
def test_helper_gets_message_when_present():
message = status_get_message()
assert message == TEST_MESSAGE


@pytest.mark.filterwarnings('ignore::sqlalchemy.exc.SADeprecationWarning')
@pytest.mark.ckan_config('ckan.plugins', 'status')
@pytest.mark.ckan_config('ckanext.status.message', MARKDOWN_TEST_MESSAGE)
@pytest.mark.ckan_config('ckanext.status.enable_html', True)
@pytest.mark.usefixtures('with_plugins')
def test_helper_parses_markdown_message():
message = status_get_message()
assert message == HTML_TEST_MESSAGE


@pytest.mark.filterwarnings('ignore::sqlalchemy.exc.SADeprecationWarning')
@pytest.mark.ckan_config('ckan.plugins', 'status')
@pytest.mark.usefixtures('with_plugins')
Expand Down