Skip to content

Commit 8c02cce

Browse files
Keep Package id / Resource id / Size on the resource page regardless of template precedence
The whitelist that limits the resource "Additional Information" table to Package id, Resource id and Size lived in the theme's copy of scheming/package/resource_read.html. That template only renders when ckanext-iaea outranks ckanext-scheming in ckan.plugins (earlier in the list == higher template precedence). Where it loses, ckanext-scheming's copy renders instead: the same fields come out as collapsible <tr class="toggle-more"> rows, and custom.css was hiding both those rows and the "Show more" button that would expand them, so the three fields disappeared with no way to reach them. Move the whitelist and labels into a format_resource_items helper that overrides the core helper of the same name. All three copies of resource_read.html -- core's, scheming's and ours -- source their rows from that helper, so the filtering holds whichever one renders. Flip the CSS to force .toggle-more rows visible instead of hidden. Nothing worth collapsing survives the helper now, and the toggle control stays hidden. Verified both ways against a local resource page: with the theme template present the output is unchanged, and with it removed (reproducing the losing case) the same four rows render with the correct labels instead of 20 hidden ones. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent c32d550 commit 8c02cce

3 files changed

Lines changed: 59 additions & 18 deletions

File tree

ckanext/iaea/assets/css/custom.css

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -479,14 +479,19 @@ div.dtr-bs-modal .modal-header .modal-title {
479479
padding-right: 36px;
480480
}
481481
/* Resource "Additional Information" table: remove the "Show more" / "Hide"
482-
toggle so it renders as a plain static table and the collapsible rows (the
483-
raw resource-dict fields: Ckan url, Datastore active, Has views, Hash,
484-
Ignore hash, Mimetype, etc.) never become reachable in the UI.
482+
toggle so it renders as a plain static table.
485483
table-toggle-more.js injects a <tr class="toggle-show toggle-show-more">
486484
holding the show-more/show-less links plus a <tr class="toggle-seperator">;
487-
the .toggle-more data rows are hidden by core CSS in the collapsed
488-
(.table-toggle-more) state. We hide the toggle row + separator in BOTH
489-
states and force the collapsible rows to stay hidden even if the state flips.
485+
we hide both in either state so no toggle control is ever shown.
486+
487+
The .toggle-more data rows are then forced VISIBLE, reversing core's
488+
`.js .table-toggle-more .toggle-more { display: none }`. Those rows only
489+
exist when ckanext-scheming's (or core's) resource_read.html renders instead
490+
of ours -- and what lands in them is already restricted to Package id /
491+
Resource id / Size by our format_resource_items helper override, so there is
492+
nothing left worth collapsing. Hiding them instead, as this rule used to,
493+
made those three fields unreachable on any deployment where our template
494+
lost, with no button left to expand them.
490495
Global is safe here: the only other user of .table-toggle-more is the
491496
tabledesigner choice snippet, and the tabledesigner plugin is not enabled. */
492497
.table-toggle-more .toggle-show,
@@ -495,6 +500,7 @@ div.dtr-bs-modal .modal-header .modal-title {
495500
.table-toggle-less .toggle-seperator {
496501
display: none !important;
497502
}
503+
.table-toggle-more .toggle-more,
498504
.table-toggle-less .toggle-more {
499-
display: none !important;
505+
display: table-row !important;
500506
}

ckanext/iaea/helpers.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,46 @@ def get_main_organization():
7676
def is_rtl_language():
7777
return lang() in config.get('ckan.i18n.rtl_languages', 'he ar fa_IR').split()
7878

79+
80+
# Raw resource-dict fields we allow into the resource "Additional Information"
81+
# table, mapped to their display labels. Keys are as returned by CKAN's core
82+
# format_resource_items(), i.e. underscores already replaced with spaces.
83+
RESOURCE_ITEM_LABELS = {
84+
'package id': 'Package id',
85+
'id': 'Resource id',
86+
'resource id': 'Resource id',
87+
'size': 'Size',
88+
}
89+
90+
91+
def format_resource_items(items):
92+
'''Overrides the core helper of the same name to whitelist and relabel the
93+
raw resource fields shown in the resource "Additional Information" table.
94+
95+
This deliberately lives in the plugin rather than in the theme's
96+
scheming/package/resource_read.html, because that template only wins when
97+
ckanext-iaea outranks ckanext-scheming in `ckan.plugins` (earlier in the
98+
list == higher template precedence). When it loses, ckanext-scheming's copy
99+
renders instead and any whitelist kept in our template is bypassed, which
100+
silently drops Package id / Resource id / Size from the page. Every copy of
101+
resource_read.html -- core's, scheming's and ours -- feeds its rows from
102+
this helper, so filtering here holds regardless of which one renders.
103+
104+
Callers other than those three templates: none (checked across ckan and all
105+
bundled extensions).
106+
'''
107+
output = []
108+
for key, value in h.format_resource_items(items):
109+
label = RESOURCE_ITEM_LABELS.get(key)
110+
if label:
111+
# Translate at call time so the active request locale is used.
112+
output.append((tk._(label), value))
113+
return output
114+
115+
79116
def get_helpers():
80117
return {
81118
"iaea_ga_header": googleanalytics_header,
82119
'iaea_get_available_organizations': get_available_organizations,
120+
'format_resource_items': format_resource_items,
83121
}

ckanext/iaea/templates/scheming/package/resource_read.html

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,15 @@
7777
{%- endfor -%}
7878
{%- endblock -%}
7979
{%- block resource_more_items -%}
80-
{#- Whitelist only these raw resource-dict fields, relabel them, and
81-
render as plain rows (no toggle-more) so no "Show more" button appears. -#}
82-
{%- set item_labels = {
83-
'package id': _('Package id'),
84-
'id': _('Resource id'),
85-
'resource id': _('Resource id'),
86-
'size': _('Size'),
87-
} -%}
80+
{#- The whitelist and the labels now live in ckanext.iaea.helpers
81+
.format_resource_items, which overrides the core helper. Keeping
82+
them there rather than here means they still apply when this
83+
template loses to ckanext-scheming's copy of it (which happens
84+
whenever scheming_datasets is listed before iaea in ckan.plugins).
85+
Rows are plain -- no toggle-more class -- so no "Show more"
86+
button appears when our template is the one that renders. -#}
8887
{% for key, value in h.format_resource_items(res.items()) %}
89-
{% if key in item_labels %}
90-
<tr><th scope="row">{{ item_labels[key] }}</th><td>{{ value }}</td></tr>
91-
{% endif %}
88+
<tr><th scope="row">{{ key }}</th><td>{{ value }}</td></tr>
9289
{% endfor %}
9390
{%- endblock -%}
9491
</tbody>

0 commit comments

Comments
 (0)