|
4 | 4 | {# |
5 | 5 | Builds a list of errors for the current form. |
6 | 6 |
|
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. |
10 | 14 |
|
11 | 15 | Example: |
12 | 16 |
|
13 | 17 | {% 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) }} |
15 | 19 |
|
16 | 20 | #} |
17 | 21 |
|
18 | 22 |
|
19 | 23 | {# (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={}) %} |
21 | 25 | {% if errors %} |
22 | 26 | <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> |
24 | 28 | {% 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> |
31 | 30 | <ul> |
32 | 31 | {% for field_id, field_errs in errors.dataset.items() %} |
33 | 32 | <li data-field-label="{{ field_id }}">{% if field_id %}{{ field_id }}{{_(':')}} {% endif %}{{ field_errs|join(', ') }}</li> |
34 | 33 | {% endfor %} |
35 | 34 | </ul> |
36 | 35 | {% endif %} |
37 | 36 | {% 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> |
39 | 38 | <ul> |
40 | 39 | {% 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> |
42 | 41 | <ul> |
43 | 42 | {% for field_id, field_errs in errs.items() %} |
44 | 43 | <li data-field-label="{{ field_id }}">{% if field_id %}{{ field_id }}{{_(':')}} {% endif %}{{ field_errs|join(', ') }}</li> |
|
0 commit comments