Skip to content

Commit cf2c8d6

Browse files
authored
Merge pull request #13 from okfn/10-nnew-admin-confg
Add new admin conf
2 parents db3ecc3 + 5b40fd8 commit cf2c8d6

File tree

5 files changed

+42
-6
lines changed

5 files changed

+42
-6
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ See [Troubleshooting procedure](/docs/Troubleshooting.md)
131131

132132
This extension allows customization of the dashboard title displayed on dataset pages.
133133

134-
### `ckanext.bcie.dashboard_title`
134+
### `ckanext.dashboard.title`
135135

136136
- **Type:** `string`
137137
- **Default:** `"Dashboard"`
@@ -143,13 +143,13 @@ This extension allows customization of the dashboard title displayed on dataset
143143
To customize the title:
144144

145145
```ini
146-
ckanext.bcie.dashboard_title = Project Monitoring
146+
ckanext.dashboard.title = Project Monitoring
147147
```
148148

149149
To hide the title completely:
150150

151151
```ini
152-
ckanext.bcie.dashboard_title =
152+
ckanext.dashboard.title =
153153
```
154154

155155
> Note: This setting is read directly from the CKAN configuration file. If you wish to expose it in the sysadmin UI (`/admin/config`), you will need to register a config validator in the plugin.

ckanext/dashboard/helpers.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ def get_dataset_dashboard(package_id):
1515
def get_dashboard_title_from_config():
1616
"""Gets the dashboard title from the .ini configuration"""
1717
# If exists and it's empty, we assume users wants not to display the title
18-
title = t.config.get('ckanext.bcie.dashboard_title', t._('Dashboard'))
18+
title = t.config.get('ckanext.dashboard.title', '')
19+
print(f"Dashboard title from config: {title}") # Debugging output
20+
log.debug(f"Dashboard title from config: {title}")
1921

2022
return title

ckanext/dashboard/plugin.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import logging
2+
13
from ckan import plugins as p
24
from ckan.lib.plugins import DefaultTranslation
35
from ckan.plugins import toolkit
@@ -10,6 +12,9 @@
1012
from ckanext.dashboard import helpers as h
1113

1214

15+
log = logging.getLogger(__name__)
16+
17+
1318
class DashboardPlugin(p.SingletonPlugin, DefaultTranslation):
1419
"""Plugin for managing dashboards in CKAN"""
1520
p.implements(p.IConfigurer)
@@ -26,6 +31,14 @@ def update_config(self, config_):
2631
toolkit.add_public_directory(config_, "public")
2732
toolkit.add_resource("assets", "dashboard")
2833

34+
title_config = config_.get("ckanext.dashboard_title", config_.get("ckanext.dashboard.title", ""))
35+
log.debug(f"Setting default dashboard title: {title_config}")
36+
37+
config_.setdefault(
38+
"ckanext.dashboard.title",
39+
title_config
40+
)
41+
2942
def get_blueprint(self):
3043
return dashboard_bp
3144

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{% ckan_extends %}
2+
{% import 'macros/form.html' as form %}
3+
4+
{% block admin_form %}
5+
{{ super() }}
6+
7+
<h2>{{ _('Dashboard Configuration') }}</h2>
8+
<div class="group-fields">
9+
{{ form.input(
10+
'ckanext.dashboard.title',
11+
label=_('Dashboard Title'),
12+
value=data.get('ckanext.dashboard.title') or h.get_dashboard_title_from_config(),
13+
error=errors['ckanext.dashboard.title']
14+
) }}
15+
</div>
16+
{% endblock %}

ckanext/dashboard/tests/test_title.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,20 @@ def setup_data():
2121
class TestTitle:
2222
""" Test the dashboard title """
2323

24-
@pytest.mark.ckan_config("ckanext.bcie.dashboard_title", "My dash title")
24+
@pytest.mark.ckan_config("ckanext.dashboard.title", "My dash title")
2525
def test_title_exists(self, app, setup_data):
2626
headers = {'Authorization': setup_data.user['token']}
2727
response = app.get(url_for("dataset.read", id=setup_data.dataset["name"]), headers=headers)
2828
assert "dashboard-title-class" in response
2929
assert 'My dash title' in response
30+
html = response.data.decode('utf-8')
31+
assert "dashboard-title-class" in html
32+
assert "My dash title" in html
3033

31-
@pytest.mark.ckan_config("ckanext.bcie.dashboard_title", "")
34+
@pytest.mark.ckan_config("ckanext.dashboard.title", "")
3235
def test_empty_title(self, app, setup_data):
3336
headers = {'Authorization': setup_data.user['token']}
3437
response = app.get(url_for("dataset.read", id=setup_data.dataset["name"]), headers=headers)
3538
assert "dashboard-title-class" not in response
39+
html = response.data.decode('utf-8')
40+
assert "dashboard-title-class" not in html

0 commit comments

Comments
 (0)