Skip to content

Commit

Permalink
merge: PR #27 from dev
Browse files Browse the repository at this point in the history
Weekly release 2023-11-27
  • Loading branch information
alycejenni authored Nov 27, 2023
2 parents c270f98 + 45d277a commit 8b47050
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 7 deletions.
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

0 comments on commit 8b47050

Please sign in to comment.