Skip to content

Commit 1864452

Browse files
committed
fix(templates): syntax;
- `helpers` -> `h` - Humanization changes.
1 parent 97bcdc6 commit 1864452

File tree

4 files changed

+16
-17
lines changed

4 files changed

+16
-17
lines changed

ckan/lib/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1091,7 +1091,7 @@ def humanize_entity_type(entity_type: str, object_type: str,
10911091
# (canada fork only): handle all errors in resource actions
10921092
# TODO: upstream contrib??
10931093
'other errors': _('Errors in {object_type}'),
1094-
'other errors package': _('The <a href="{{}}" target="_blank">{object_type}</a> contains errors:'),
1094+
'other errors package': _('The {object_type} contains errors:'),
10951095
'other errors resources': _('The {object_type} contains invalid resources:')
10961096
}
10971097

ckan/templates/macros/form/resource_validation_errors.html

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,40 @@
44
{#
55
Builds a list of errors for the current form.
66

7-
errors - A dict of field/message pairs.
8-
type - The alert-* class that should be applied (default: "error")
9-
classes - A list of classes to apply to the wrapper (default: [])
7+
errors - A dict of object/field/message pairs from the resource_validation_errors method.
8+
'resources' and 'dataset' keys.
9+
type - The alert-* class that should be applied (default: "danger")
10+
classes - A list of classes to apply to the wrapper (default: [])
11+
pkg_name - String; The name or ID of the package.
12+
dataset_type - String; The type of package
13+
h - The template helpers object as Jinja macros are scoped.
1014

1115
Example:
1216

1317
{% import 'macros/form.html' as form %}
14-
{{ form.errors(error_summary, type="warning") }}
18+
{{ form.resource_validation_errors(errors=resource_validation_errors, type="warning", pkg_name=pkg_dict.id, h=h) }}
1519

1620
#}
1721

1822

1923
{# (canada fork only): error -> danger BS version #}
20-
{% macro resource_validation_errors(errors={}, type="danger", classes=[], pkg_name='', dataset_type='dataset', helpers={}) %}
24+
{% macro resource_validation_errors(errors={}, type="danger", classes=[], pkg_name='', dataset_type='dataset', h={}) %}
2125
{% if errors %}
2226
<div class="error-explanation alert alert-{{ type }}{{ " " ~ classes | join(' ') }}">
23-
<h3>{{ helpers.humanize_entity_type('package', dataset_type, 'other errors') or _('Errors in dataset') }}</h3>
27+
<h3>{{ h.humanize_entity_type('package', dataset_type, 'other errors') or _('Errors in dataset') }}</h3>
2428
{% if 'dataset' in errors and errors.dataset %}
25-
{% set dataset_link = helpers.url_for('dataset.read', id=pkg_name) %}
26-
{% set humanized_label = helpers.humanize_entity_type('package', dataset_type, 'other errors package') %}
27-
{% if humanized_label %}
28-
{% set humanized_label = humanized_label.format(dataset_link)|safe %}
29-
{% endif %}
30-
<p>{{ humanized_label or _('The <a href="{}" target="_blank">dataset</a> contains errors:').format(dataset_link) }}</p>
29+
<p>{{ h.humanize_entity_type('package', dataset_type, 'other errors package') or _('The dataset contains errors:') }}</p>
3130
<ul>
3231
{% for field_id, field_errs in errors.dataset.items() %}
3332
<li data-field-label="{{ field_id }}">{% if field_id %}{{ field_id }}{{_(':')}} {% endif %}{{ field_errs|join(', ') }}</li>
3433
{% endfor %}
3534
</ul>
3635
{% endif %}
3736
{% if 'resources' in errors and errors.resources %}
38-
<p>{{ helpers.humanize_entity_type('package', dataset_type, 'other errors resources') or _('The dataset contains invalid resources:') }}</p>
37+
<p>{{ h.humanize_entity_type('package', dataset_type, 'other errors resources') or _('The dataset contains invalid resources:') }}</p>
3938
<ul>
4039
{% for res_id, errs in errors.resources.items() %}
41-
<li><a href="{{ helpers.url_for('resource.read', id=pkg_name, resource_id=res_id) }}" target="_blank">{{ res_id }}</a></li>
40+
<li><a href="{{ h.url_for('resource.read', id=pkg_name, resource_id=res_id) }}" target="_blank">{{ res_id }}</a></li>
4241
<ul>
4342
{% for field_id, field_errs in errs.items() %}
4443
<li data-field-label="{{ field_id }}">{% if field_id %}{{ field_id }}{{_(':')}} {% endif %}{{ field_errs|join(', ') }}</li>

ckan/templates/package/confirm_delete_resource.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
{# TODO: upstream contrib?? #}
1919
{% block errors %}
2020
{% if resource_validation_errors %}
21-
{{ form.resource_validation_errors(errors=resource_validation_errors, pkg_name=pkg_id, dataset_type=dataset_type, helpers=h) }}
21+
{{ form.resource_validation_errors(errors=resource_validation_errors, pkg_name=pkg_id, dataset_type=dataset_type, h=h) }}
2222
{% else %}
2323
{{ form.errors(errors=errors) }}
2424
{% endif %}

ckan/templates/package/snippets/resource_form.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
{# TODO: upstream contrib?? #}
1919
{% block errors %}
2020
{% if resource_validation_errors %}
21-
{{ form.resource_validation_errors(errors=resource_validation_errors, pkg_name=pkg_name, dataset_type=dataset_type, helpers=h) }}
21+
{{ form.resource_validation_errors(errors=resource_validation_errors, pkg_name=pkg_name, dataset_type=dataset_type, h=h) }}
2222
{% else %}
2323
{{ form.errors(errors=errors) }}
2424
{% endif %}

0 commit comments

Comments
 (0)