From 8e37429aaa5ed214ae9f6fb8d7ace58b68d19060 Mon Sep 17 00:00:00 2001 From: Jesse Vickery Date: Fri, 15 Nov 2024 18:54:53 +0000 Subject: [PATCH 01/11] feat(dev): relationships; - Removed old code. - Reworked other code. --- .../canada/assets/public/canada_public.css | 8 ++ ckanext/canada/schemas/dataset.yaml | 1 + ckanext/canada/schemas/presets.yaml | 28 +++- ckanext/canada/templates/package/read.html | 32 ++--- .../templates/package/resource_read.html | 6 +- .../templates/package/snippets/app_item.html | 7 - .../package/snippets/resource_item.html | 25 ++++ .../snippets/resource_upload_field.html | 50 +++++++ .../templates/package/snippets/resources.html | 131 +++++++++++++----- .../package/snippets/resources_list.html | 9 ++ .../templates/package/snippets/schemaorg.html | 10 +- .../package/snippets/resource_form.html | 61 ++++---- 12 files changed, 260 insertions(+), 108 deletions(-) delete mode 100644 ckanext/canada/templates/package/snippets/app_item.html create mode 100644 ckanext/canada/templates/package/snippets/resource_upload_field.html diff --git a/ckanext/canada/assets/public/canada_public.css b/ckanext/canada/assets/public/canada_public.css index 17a60f9bb..8b1cf29cf 100644 --- a/ckanext/canada/assets/public/canada_public.css +++ b/ckanext/canada/assets/public/canada_public.css @@ -286,6 +286,14 @@ a#edit-comment-body-0-format-help-about, button#edit-submit,button#edit-actions- background-color: #256EB8; } +.res-tag-related-rel{ + background-color: #749a5b; +} + +.res-tag-related-type{ + background-color: #ac468a; +} + .resource-heading { overflow: hidden; text-overflow: ellipsis; diff --git a/ckanext/canada/schemas/dataset.yaml b/ckanext/canada/schemas/dataset.yaml index 1f278bb8a..3f2a69704 100644 --- a/ckanext/canada/schemas/dataset.yaml +++ b/ckanext/canada/schemas/dataset.yaml @@ -482,6 +482,7 @@ resource_fields: - preset: canada_resource_format - preset: canada_resource_language - preset: canada_resource_url +- preset: canada_related_resource_url - preset: canada_resource_data_quality - preset: canada_resource_validation_schema diff --git a/ckanext/canada/schemas/presets.yaml b/ckanext/canada/schemas/presets.yaml index 71d2a069e..817ef51e8 100644 --- a/ckanext/canada/schemas/presets.yaml +++ b/ckanext/canada/schemas/presets.yaml @@ -2702,6 +2702,14 @@ presets: fr: Relation du dossier connexe avec le jeu de données form_panel: related choices: + - label: + en: Defines + fr: Defines FR FR + value: defines + - label: + en: Defined by + fr: Defined by FR FR + value: defined_by - label: en: Continues fr: Se poursuit @@ -2798,6 +2806,10 @@ presets: en: Application fr: Application value: application + - label: + en: Schema + fr: Schema + value: schema - label: en: Other fr: Autre @@ -4065,16 +4077,20 @@ presets: upload_field: upload upload_clear: clear_upload -# XXX This is a copy of the resource URL field to be displayed only in the -# related item panel but is not used directly in any schemas -- preset_name: _canada_related_resource_url +# Field = Related Record URL. +- preset_name: canada_related_resource_url values: - field_name: url + field_name: related_url label: - en: Record URL + en: Related Record URL + fr: Related Record URL help_text: en: The URL for online access to the related record - required: true + fr: The URL for online access to the related record + required: false + form_snippet: null + form_panel: _exclude_from_form + validators: scheming_required unicode_safe remove_whitespace # Field = Data Includes URI. # Default Value = Unchecked. diff --git a/ckanext/canada/templates/package/read.html b/ckanext/canada/templates/package/read.html index 33a04c582..61d444445 100755 --- a/ckanext/canada/templates/package/read.html +++ b/ckanext/canada/templates/package/read.html @@ -179,27 +179,25 @@

{{ _('Made available by the ') + owner_org_title }}

{{ super() }} {% endif %} {% endblock %} - {% block package_item_apps %} -
- {% set apps = [] %} - {% for resource in pkg.resources %} - {% if resource.format == 'app' %} - {% do apps.append(resource) %} - {% endif %} - {% endfor %} -
- {% if apps|length > 0 %} + {% block related_items %} + {% set related_resources = [] %} + {% for resource in pkg.resources %} + {% if resource.url_type == 'related' %} + {% do related_resources.append(resource) %} + {% endif %} + {% endfor %} + {% if related_resources|length > 0 %}
-

{{ _('Related Items') }}

-
{% endif %} - {% endblock %} - {% block related_items %}{% endblock related_items %} + {% endblock related_items %} {% block contact_information %} {% set info = h.contact_information(pkg.get('contact_information')) %} {% if info %} diff --git a/ckanext/canada/templates/package/resource_read.html b/ckanext/canada/templates/package/resource_read.html index 5bea1a0a8..bbff3cf48 100644 --- a/ckanext/canada/templates/package/resource_read.html +++ b/ckanext/canada/templates/package/resource_read.html @@ -52,7 +52,7 @@ {% endblock %} {% block download_resource_button %} - {%if res.datastore_active %} + {% if res.datastore_active %} +{% endblock %} + +{% block url_type_fields %} + {{ super() }} + +
+ {{ remove_button( + js="$('#field-resource-related').val(''); + let nrmg = document.getElementById('normal-resource-meta-group'); + if( nrmg ){ + nrmg.hidden = false; + nrmg.setAttribute('open', 'open'); + } + let rrmg = document.getElementById('related-resource-meta-group'); + if( rrmg ){ + rrmg.hidden = true; + rrmg.removeAttribute('open'); + }") }} + {{ form.input( + 'related_url', + label=_('Related Record URL'), + id='field-resource-related', + type='url', + placeholder=placeholder, + value=data.get('related_url'), + error=errors.get('related_url'), + is_required=true, + classes=['control-full']) }} +
+{% endblock %} diff --git a/ckanext/canada/templates/package/snippets/resources.html b/ckanext/canada/templates/package/snippets/resources.html index 8a422e050..0e65e7854 100644 --- a/ckanext/canada/templates/package/snippets/resources.html +++ b/ckanext/canada/templates/package/snippets/resources.html @@ -1,6 +1,12 @@ {% ckan_extends %} {% block resources %} + {% set related_resources = [] %} + {% for resource in resources %} + {% if resource.url_type == 'related' %} + {% do related_resources.append(resource) %} + {% endif %} + {% endfor %}
{% block resources_inner %} {% block resources_title %} @@ -11,44 +17,45 @@ {% if g.is_registry %} @@ -59,4 +66,54 @@ {% endblock %}
+ {% if related_resources|length > 0 %} +
+
 {{ _("Related Resources") }}
+
+ +
+
+ {% endif %} {% endblock %} diff --git a/ckanext/canada/templates/package/snippets/resources_list.html b/ckanext/canada/templates/package/snippets/resources_list.html index 19bd96dd2..4cec84e44 100644 --- a/ckanext/canada/templates/package/snippets/resources_list.html +++ b/ckanext/canada/templates/package/snippets/resources_list.html @@ -12,3 +12,12 @@

{{ _('Data and Resources') }} {% endif %}

{% endblock %} + +{% block resource_list_inner %} + {% set can_edit = h.check_access('package_update', {'id':pkg.id }) and not is_activity_archive %} + {% for resource in resources %} + {% if resource.url_type != 'related' %} + {% snippet 'package/snippets/resource_item.html', pkg=pkg, res=resource, can_edit=can_edit, is_activity_archive=is_activity_archive %} + {% endif %} + {% endfor %} +{% endblock %} diff --git a/ckanext/canada/templates/package/snippets/schemaorg.html b/ckanext/canada/templates/package/snippets/schemaorg.html index 3341b3142..981c5cf8c 100644 --- a/ckanext/canada/templates/package/snippets/schemaorg.html +++ b/ckanext/canada/templates/package/snippets/schemaorg.html @@ -58,14 +58,14 @@ {% endif %} {%- if data.resources -%} - {%- set nonapps = [] -%} + {%- set non_related_resource = [] -%} {%- for resource in data.resources -%} - {%- if not resource.related_type -%} - {%- do nonapps.append(resource) -%} + {%- if data.url_type != 'related' -%} + {%- do non_related_resource.append(resource) -%} {%- endif -%} {%- endfor -%} - {%- if nonapps -%} - {% for res in nonapps %} + {%- if non_related_resource -%} + {% for res in non_related_resource %} {{ h.get_translated(res, 'name') }} diff --git a/ckanext/canada/templates/scheming/package/snippets/resource_form.html b/ckanext/canada/templates/scheming/package/snippets/resource_form.html index d78aaa71e..5bcc2ea3f 100644 --- a/ckanext/canada/templates/scheming/package/snippets/resource_form.html +++ b/ckanext/canada/templates/scheming/package/snippets/resource_form.html @@ -11,41 +11,34 @@ {%- snippet 'scheming/snippets/form_field.html', field=field, data=data, errors=errors, entity_type='dataset', object_type=dataset_type -%} {%- endif -%} {%- endfor -%} - {%- if g.action=='new_resource' -%} -

{{ _("You can add either a Resource or a Related Item per session, i.e. not both:") }}

- {% endif %}
- {%- if (not data.related_type) or g.action.endswith('new') -%} -
- - {{ _("Metadata Fields for Resources Only (Not for Related Items)") }} - -
- {%- for field in schema.resource_fields -%} - {%- if field.form_panel == 'resource' -%} - {%- snippet 'scheming/snippets/form_field.html', field=field, data=data, errors=errors, entity_type='dataset', object_type=dataset_type -%} - {%- endif -%} - {%- endfor -%} -
-
- {% endif %} - {%- if data.related_type or g.action.endswith('new') -%} -
- - {{ _("Metadata Fields for Related Items Only") }} - -
- {%- for field in schema.resource_fields -%} - {%- if field.form_panel == 'related' -%} - {%- snippet 'scheming/snippets/form_field.html', field=field, data=data, errors=errors, entity_type='dataset', object_type=dataset_type -%} - {%- endif -%} - {%- endfor -%} -

- {{ _("Use the Download URL field above to link to the related record.") }} -

-
-
- {% endif %} +
+ + {{ _("Metadata Fields for Resources Only (Not for Related Items)") }} + +
+ {%- for field in schema.resource_fields -%} + {%- if field.form_panel == 'resource' -%} + {%- snippet 'scheming/snippets/form_field.html', field=field, data=data, errors=errors, entity_type='dataset', object_type=dataset_type -%} + {%- endif -%} + {%- endfor -%} +
+
+
{% endblock %} @@ -97,11 +77,6 @@ {% endif %} - {% if res.url_type == 'related' and h.is_url(res.related_url) %} -
  • -  {{ _('Go to Related Record') }} -
  • - {% endif %} {% set fgp_url = h.fgp_viewer_url(pkg) %} {% if fgp_url and res.url and h.is_url(res.url) and res.format not in ['PDF','HTML', 'PNG', 'CSV', 'TXT',] %}
  • diff --git a/ckanext/canada/templates/package/snippets/resources.html b/ckanext/canada/templates/package/snippets/resources.html index 0e65e7854..841a33479 100644 --- a/ckanext/canada/templates/package/snippets/resources.html +++ b/ckanext/canada/templates/package/snippets/resources.html @@ -1,12 +1,6 @@ {% ckan_extends %} {% block resources %} - {% set related_resources = [] %} - {% for resource in resources %} - {% if resource.url_type == 'related' %} - {% do related_resources.append(resource) %} - {% endif %} - {% endfor %}
    {% block resources_inner %} {% block resources_title %} @@ -17,45 +11,43 @@ {% if g.is_registry %} @@ -66,54 +58,4 @@ {% endblock %}
    - {% if related_resources|length > 0 %} -
    -
     {{ _("Related Resources") }}
    -
    - -
    -
    - {% endif %} {% endblock %} diff --git a/ckanext/canada/templates/package/snippets/resources_list.html b/ckanext/canada/templates/package/snippets/resources_list.html index 4cec84e44..19bd96dd2 100644 --- a/ckanext/canada/templates/package/snippets/resources_list.html +++ b/ckanext/canada/templates/package/snippets/resources_list.html @@ -12,12 +12,3 @@

    {{ _('Data and Resources') }} {% endif %}

    {% endblock %} - -{% block resource_list_inner %} - {% set can_edit = h.check_access('package_update', {'id':pkg.id }) and not is_activity_archive %} - {% for resource in resources %} - {% if resource.url_type != 'related' %} - {% snippet 'package/snippets/resource_item.html', pkg=pkg, res=resource, can_edit=can_edit, is_activity_archive=is_activity_archive %} - {% endif %} - {% endfor %} -{% endblock %} diff --git a/ckanext/canada/templates/package/snippets/schemaorg.html b/ckanext/canada/templates/package/snippets/schemaorg.html index 981c5cf8c..067cbd95c 100644 --- a/ckanext/canada/templates/package/snippets/schemaorg.html +++ b/ckanext/canada/templates/package/snippets/schemaorg.html @@ -58,24 +58,16 @@ {% endif %} {%- if data.resources -%} - {%- set non_related_resource = [] -%} - {%- for resource in data.resources -%} - {%- if data.url_type != 'related' -%} - {%- do non_related_resource.append(resource) -%} - {%- endif -%} + {% for res in data.resources %} + + + {{ h.get_translated(res, 'name') }} + {%- if res.get('date_published') -%} + + {%- endif -%} + {{ res.format }} + {{ res.url }} + {%- endfor -%} - {%- if non_related_resource -%} - {% for res in non_related_resource %} - - - {{ h.get_translated(res, 'name') }} - {%- if res.get('date_published') -%} - - {%- endif -%} - {{ res.format }} - {{ res.url }} - - {%- endfor -%} - {%- endif -%} {%- endif -%} diff --git a/ckanext/canada/templates/scheming/package/snippets/resource_form.html b/ckanext/canada/templates/scheming/package/snippets/resource_form.html index 5bcc2ea3f..e27e8ad64 100644 --- a/ckanext/canada/templates/scheming/package/snippets/resource_form.html +++ b/ckanext/canada/templates/scheming/package/snippets/resource_form.html @@ -12,9 +12,9 @@ {%- endif -%} {%- endfor -%}
    -
    +
    - {{ _("Metadata Fields for Resources Only (Not for Related Items)") }} + {{ _("Metadata Fields for Resources") }}
    {%- for field in schema.resource_fields -%} @@ -24,19 +24,17 @@ {%- endfor -%}
    -
    From 8df3064c08e71acea349843699b450f1bac2fc9f Mon Sep 17 00:00:00 2001 From: Jesse Vickery Date: Fri, 15 Nov 2024 21:07:17 +0000 Subject: [PATCH 03/11] feat(schema): dataset relationships; - Repeating field groups for dataset relationships. --- ckanext/canada/plugins.py | 10 ++ ckanext/canada/schemas/dataset.yaml | 5 +- ckanext/canada/schemas/info.yaml | 9 +- ckanext/canada/schemas/presets.yaml | 94 +++++++++++++------ ckanext/canada/templates/package/read.html | 8 +- .../dataset_relationship.html | 17 ++++ conf/solr/schema.xml | 4 +- 7 files changed, 113 insertions(+), 34 deletions(-) create mode 100644 ckanext/canada/templates/scheming/display_snippets/dataset_relationship.html diff --git a/ckanext/canada/plugins.py b/ckanext/canada/plugins.py index 741b4b853..fe4e57d7c 100755 --- a/ckanext/canada/plugins.py +++ b/ckanext/canada/plugins.py @@ -407,6 +407,16 @@ def before_index(self, data_dict): for cr in data_dict['credit']: cr.pop('__extras', None) + if data_dict.get('relationship'): + related_relationships = [] + related_types = [] + for rel in data_dict['relationship']: + related_relationships.append(rel.get('related_relationship')) + related_types.append(rel.get('related_type')) + data_dict['related_relationship'] = related_relationships + data_dict['related_type'] = related_types + data_dict.pop('relationship', None) + return data_dict # IDataDictionaryForm diff --git a/ckanext/canada/schemas/dataset.yaml b/ckanext/canada/schemas/dataset.yaml index 3f2a69704..625e071a6 100644 --- a/ckanext/canada/schemas/dataset.yaml +++ b/ckanext/canada/schemas/dataset.yaml @@ -453,6 +453,7 @@ dataset_fields: en: FGP viewer is supported value: fgp_viewer +- preset: canada_dataset_relationship # @@ -462,8 +463,8 @@ resource_fields: - preset: canada_resource_unique_identifier - preset: canada_resource_name -- preset: canada_resource_related_relationship -- preset: canada_resource_related_type +# - preset: canada_resource_related_relationship +# - preset: canada_resource_related_type - preset: canada_resource_date_published - preset: canada_resource_type form_restrict_choices_to: diff --git a/ckanext/canada/schemas/info.yaml b/ckanext/canada/schemas/info.yaml index e5fcce004..33c6b49ba 100644 --- a/ckanext/canada/schemas/info.yaml +++ b/ckanext/canada/schemas/info.yaml @@ -146,6 +146,9 @@ dataset_fields: error_snippet: fluent_text.html validators: fluent_text output_validators: fluent_text_output + form_attrs: + size: 100 + class: form-control # Field = Keywords English. # {Commonly used words or phrases which describe the asset, in English} @@ -488,6 +491,8 @@ dataset_fields: # {The date the asset may be published on the Portal (YYYY-MM-DD)} - preset: canada_portal_release_date +- preset: canada_dataset_relationship + # # RESOURCE FIELDS @@ -504,8 +509,8 @@ resource_fields: # {A French name given to the resource} - preset: canada_resource_name -- preset: canada_resource_related_relationship -- preset: canada_resource_related_type +# - preset: canada_resource_related_relationship +# - preset: canada_resource_related_type # Field = Date Published. # Add a Calendar control to select a Date. diff --git a/ckanext/canada/schemas/presets.yaml b/ckanext/canada/schemas/presets.yaml index 817ef51e8..ee15cccb6 100644 --- a/ckanext/canada/schemas/presets.yaml +++ b/ckanext/canada/schemas/presets.yaml @@ -2689,9 +2689,7 @@ presets: class: form-control # Field = Relationship Type. -# List box Source: Relationship Type code table (refer to Data Migration). -# {The Related Record’s relationship with the dataset} -- preset_name: canada_resource_related_relationship +- preset_name: canada_dataset_related_relationship values: field_name: related_relationship label: @@ -2700,16 +2698,7 @@ presets: help_text: en: The Related Record’s relationship with the dataset fr: Relation du dossier connexe avec le jeu de données - form_panel: related choices: - - label: - en: Defines - fr: Defines FR FR - value: defines - - label: - en: Defined by - fr: Defined by FR FR - value: defined_by - label: en: Continues fr: Se poursuit @@ -2763,25 +2752,64 @@ presets: fr: Séparé de value: separated_from - label: - en: Split into ... - fr: Divisé en … + en: Split into + fr: Divisé en value: split_into - label: - en: Merged with ... + en: Merged with fr: Fusionné avec value: merged_into - label: en: Changed back to fr: Restauré à value: changed_back_to + form_include_blank_choice: true form_snippet: select.html display_snippet: select.html validators: scheming_required scheming_choices + required: true + form_panel: dataset_relationships + +# Field = Related Record URL. +- preset_name: canada_dataset_related_url + values: + field_name: related_url_translated + label: + en: Related Record URL + fr: FR Related Record URL FR + help_text: + en: The URL for online access to the related record + fr: FR The URL for online access to the related record FR + fluent_form_label: + en: + en: "Related Record URL (English)" + fr: "FR Related Record URL (anglais) FR" + fr: + en: "Related Record URL (French)" + fr: "FR Related Record URL (français) FR" + fluent_help_text: + en: + en: The URL for online access to the related record + fr: FR The URL for online access to the related record FR + fr: + en: The URL for online access to the related record + fr: FR The URL for online access to the related record FR + # copied from fluent_text preset + form_snippet: fluent_text.html + display_snippet: fluent_link.html + display_attributes: + style: "word-wrap: break-word" + error_snippet: fluent_text.html + validators: fluent_text + output_validators: fluent_core_translated_output + required: true + form_panel: dataset_relationships + form_attrs: + style: "width: 100%;" + class: form-control # Field = Record Type. -# List box Source: Record Type code table (refer to Data Migration). -# {The portal or page to which the Related Record belongs} -- preset_name: canada_resource_related_type +- preset_name: canada_dataset_related_type values: field_name: related_type label: @@ -2790,9 +2818,6 @@ presets: help_text: en: The portal or page to which the Related Record belongs fr: Portail auquel appartient le dossier connexe - form_panel: related - required: true - form_include_blank_choice: true choices: - label: en: Open Data @@ -2806,19 +2831,16 @@ presets: en: Application fr: Application value: application - - label: - en: Schema - fr: Schema - value: schema - label: en: Other fr: Autre value: other + required: true + form_include_blank_choice: true form_snippet: select.html display_snippet: select.html - # no 'scheming_required' in validators because this field may be omitted - # for non-related-item resources - validators: ignore_missing scheming_choices + validators: scheming_required scheming_choices + form_panel: dataset_relationships # Field = Date Published. # Add a Calendar control to select a Date. @@ -4140,3 +4162,19 @@ presets: display_snippet: null validators: ignore output_validators: canada_output_none + + +- preset_name: canada_dataset_relationship + values: + field_name: relationship + label: + en: Relationship + fr: FR Relationship FR + display_snippet: dataset_relationship.html + form_blanks: 0 + + repeating_subfields: + + - preset: canada_dataset_related_relationship + - preset: canada_dataset_related_type + - preset: canada_dataset_related_url diff --git a/ckanext/canada/templates/package/read.html b/ckanext/canada/templates/package/read.html index 4248a0664..714ab350b 100755 --- a/ckanext/canada/templates/package/read.html +++ b/ckanext/canada/templates/package/read.html @@ -180,7 +180,13 @@

    {{ _('Made available by the ') + owner_org_title }}

    {% endif %} {% endblock %} {% block related_items %} - {# todo, output related items... #} + {% if pkg.get('relationship') %} +
    +

    {{ _('Dataset Relationships') }}

    + {% set relation_field = h.scheming_field_by_name(schema.dataset_fields, 'relationship') %} + {% snippet 'scheming/snippets/display_field.html', field=relation_field, data=pkg, entity_type='dataset', object_type=pkg.type %} +
    + {% endif %} {% endblock related_items %} {% block contact_information %} {% set info = h.contact_information(pkg.get('contact_information')) %} diff --git a/ckanext/canada/templates/scheming/display_snippets/dataset_relationship.html b/ckanext/canada/templates/scheming/display_snippets/dataset_relationship.html new file mode 100644 index 000000000..4e37a63c2 --- /dev/null +++ b/ckanext/canada/templates/scheming/display_snippets/dataset_relationship.html @@ -0,0 +1,17 @@ +{% set fields = data[field.field_name] %} + +{% block subfield_display %} +
    + {%- for field_data in fields -%} +

      + {%- for subfield in field.repeating_subfields -%} + {%- snippet 'scheming/snippets/display_field.html', + field=subfield, + data=field_data, + entity_type=entity_type, + object_type=object_type -%} + {%- endfor -%} +

    + {%- endfor -%} +
    +{% endblock %} diff --git a/conf/solr/schema.xml b/conf/solr/schema.xml index 48ce82d89..5537e88d4 100644 --- a/conf/solr/schema.xml +++ b/conf/solr/schema.xml @@ -146,7 +146,7 @@ - + @@ -155,6 +155,8 @@ + + index_id From d62c460d1497568e7463b8dcd2f2f8f263cb9dce Mon Sep 17 00:00:00 2001 From: Jesse Vickery Date: Fri, 15 Nov 2024 21:24:52 +0000 Subject: [PATCH 04/11] feat(schema): resource relationships; - Started working on resource relationships. --- ckanext/canada/plugins.py | 2 - ckanext/canada/schemas/dataset.yaml | 4 +- ckanext/canada/schemas/info.yaml | 3 +- ckanext/canada/schemas/presets.yaml | 63 +++++++++++++++++-- .../resource_relationship.html | 17 +++++ .../package/snippets/resource_form.html | 2 +- ckanext/canada/validators.py | 8 --- 7 files changed, 78 insertions(+), 21 deletions(-) create mode 100644 ckanext/canada/templates/scheming/display_snippets/resource_relationship.html diff --git a/ckanext/canada/plugins.py b/ckanext/canada/plugins.py index fe4e57d7c..684feb1e8 100755 --- a/ckanext/canada/plugins.py +++ b/ckanext/canada/plugins.py @@ -841,8 +841,6 @@ def get_validators(self): validators.protect_portal_release_date, 'canada_copy_from_org_name': validators.canada_copy_from_org_name, - 'canada_non_related_required': - validators.canada_non_related_required, 'canada_maintainer_email_default': validators.canada_maintainer_email_default, 'user_read_only': diff --git a/ckanext/canada/schemas/dataset.yaml b/ckanext/canada/schemas/dataset.yaml index 625e071a6..a7b337c72 100644 --- a/ckanext/canada/schemas/dataset.yaml +++ b/ckanext/canada/schemas/dataset.yaml @@ -463,8 +463,7 @@ resource_fields: - preset: canada_resource_unique_identifier - preset: canada_resource_name -# - preset: canada_resource_related_relationship -# - preset: canada_resource_related_type +- preset: canada_resource_relationship - preset: canada_resource_date_published - preset: canada_resource_type form_restrict_choices_to: @@ -483,7 +482,6 @@ resource_fields: - preset: canada_resource_format - preset: canada_resource_language - preset: canada_resource_url -- preset: canada_related_resource_url - preset: canada_resource_data_quality - preset: canada_resource_validation_schema diff --git a/ckanext/canada/schemas/info.yaml b/ckanext/canada/schemas/info.yaml index 33c6b49ba..5280771b8 100644 --- a/ckanext/canada/schemas/info.yaml +++ b/ckanext/canada/schemas/info.yaml @@ -509,8 +509,7 @@ resource_fields: # {A French name given to the resource} - preset: canada_resource_name -# - preset: canada_resource_related_relationship -# - preset: canada_resource_related_type +- preset: canada_resource_relationship # Field = Date Published. # Add a Calendar control to select a Date. diff --git a/ckanext/canada/schemas/presets.yaml b/ckanext/canada/schemas/presets.yaml index ee15cccb6..0e028e91f 100644 --- a/ckanext/canada/schemas/presets.yaml +++ b/ckanext/canada/schemas/presets.yaml @@ -2768,7 +2768,7 @@ presets: display_snippet: select.html validators: scheming_required scheming_choices required: true - form_panel: dataset_relationships + form_panel: relationships # Field = Related Record URL. - preset_name: canada_dataset_related_url @@ -2803,7 +2803,7 @@ presets: validators: fluent_text output_validators: fluent_core_translated_output required: true - form_panel: dataset_relationships + form_panel: relationships form_attrs: style: "width: 100%;" class: form-control @@ -2840,7 +2840,32 @@ presets: form_snippet: select.html display_snippet: select.html validators: scheming_required scheming_choices - form_panel: dataset_relationships + form_panel: relationships + +- preset_name: canada_resource_related_relationship + values: + field_name: related_relationship + label: + en: Relationship Type + fr: Type de relation + help_text: + en: The Related Record’s relationship with the resource + fr: Relation du dossier connexe avec le jeu de données + choices: + - label: + en: Defines + fr: FR Defines FR + value: defines + - label: + en: Defined by + fr: FR Defined par FR + value: defined_by + form_include_blank_choice: true + form_snippet: select.html + display_snippet: select.html + validators: scheming_required scheming_choices + required: true + form_panel: relationships # Field = Date Published. # Add a Calendar control to select a Date. @@ -2875,7 +2900,7 @@ presets: field_name: resource_type form_snippet: select.html display_snippet: select.html - validators: canada_non_related_required canada_static_rtype_tabledesigner scheming_choices + validators: scheming_required canada_static_rtype_tabledesigner scheming_choices required: true form_include_blank_choice: true form_panel: resource @@ -3301,7 +3326,7 @@ presets: form_placeholder: en: "eg. CSV, XML or JSON" fr: "par exemple CSV, XML ou JSON" - validators: canada_guess_resource_format scheming_required unicode_safe canada_non_related_required scheming_choices + validators: canada_guess_resource_format scheming_required unicode_safe scheming_required scheming_choices required: false form_include_blank_choice: true form_panel: resource @@ -4167,6 +4192,7 @@ presets: - preset_name: canada_dataset_relationship values: field_name: relationship + form_panel: relationships label: en: Relationship fr: FR Relationship FR @@ -4178,3 +4204,30 @@ presets: - preset: canada_dataset_related_relationship - preset: canada_dataset_related_type - preset: canada_dataset_related_url + + +- preset_name: canada_resource_relationship + values: + field_name: relationship + form_panel: relationships + label: + en: Relationship + fr: FR Relationship FR + display_snippet: resource_relationship.html + form_blanks: 0 + + repeating_subfields: + + - preset: canada_resource_related_relationship + - preset: canada_resource_type + form_restrict_choices_to: + - application + - api + - dataset + - guide + - faq + - specification + - terminology + - tool + - website + - preset: canada_dataset_related_url diff --git a/ckanext/canada/templates/scheming/display_snippets/resource_relationship.html b/ckanext/canada/templates/scheming/display_snippets/resource_relationship.html new file mode 100644 index 000000000..5f5bd4f30 --- /dev/null +++ b/ckanext/canada/templates/scheming/display_snippets/resource_relationship.html @@ -0,0 +1,17 @@ +{% set fields = data[field.field_name] %} + +{% block subfield_display %} +
    + {%- for field_data in fields -%} +

      + {%- for subfield in field.repeating_subfields -%} + {%- snippet 'scheming/snippets/display_field.html', + field=subfield, + data=field_data, + entity_type=entity_type, + object_type=object_type -%} + {%- endfor -%} +

    + {%- endfor -%} +
    +{% endblock %} diff --git a/ckanext/canada/templates/scheming/package/snippets/resource_form.html b/ckanext/canada/templates/scheming/package/snippets/resource_form.html index e27e8ad64..cd433f48c 100644 --- a/ckanext/canada/templates/scheming/package/snippets/resource_form.html +++ b/ckanext/canada/templates/scheming/package/snippets/resource_form.html @@ -31,7 +31,7 @@
    {# TODO: make sure repeater fields work here... #} {%- for field in schema.resource_fields -%} - {%- if field.form_panel == 'resource_relationships' -%} + {%- if field.form_panel == 'relationships' -%} {%- snippet 'scheming/snippets/form_field.html', field=field, data=data, errors=errors, entity_type='dataset', object_type=dataset_type -%} {%- endif -%} {%- endfor -%} diff --git a/ckanext/canada/validators.py b/ckanext/canada/validators.py index b85be9ae0..945189bcd 100644 --- a/ckanext/canada/validators.py +++ b/ckanext/canada/validators.py @@ -204,14 +204,6 @@ def canada_copy_from_org_name(key, data, errors, context): 'fr': org['title'].split(' | ')[-1], }) -def canada_non_related_required(key, data, errors, context): - """ - Required resource field *if* this resource is not a related item - """ - if not data.get(key[:-1] + ('related_type',)): - return not_empty(key, data, errors, context) - return ignore_missing(key, data, errors, context) - def canada_maintainer_email_default(key, data, errors, context): """ From 3c27d5cf4a9dc7f4c461ffa265b4d670cb516749 Mon Sep 17 00:00:00 2001 From: Jesse Vickery Date: Fri, 15 Nov 2024 23:14:49 +0000 Subject: [PATCH 05/11] feat(schema): resource relationships; - Finalized resource relationships. --- ckanext/canada/schemas/presets.yaml | 26 ++++++++++++------- .../package/snippets/resource_form.html | 9 +++---- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/ckanext/canada/schemas/presets.yaml b/ckanext/canada/schemas/presets.yaml index 0e028e91f..f37c22871 100644 --- a/ckanext/canada/schemas/presets.yaml +++ b/ckanext/canada/schemas/presets.yaml @@ -2860,6 +2860,14 @@ presets: en: Defined by fr: FR Defined par FR value: defined_by + - label: + en: References + fr: FR References FR + value: references + - label: + en: Referenced by + fr: FR Referenced par FR + value: referenced_by form_include_blank_choice: true form_snippet: select.html display_snippet: select.html @@ -4221,13 +4229,13 @@ presets: - preset: canada_resource_related_relationship - preset: canada_resource_type form_restrict_choices_to: - - application - - api - - dataset - - guide - - faq - - specification - - terminology - - tool - - website + - application + - api + - dataset + - guide + - faq + - specification + - terminology + - tool + - website - preset: canada_dataset_related_url diff --git a/ckanext/canada/templates/scheming/package/snippets/resource_form.html b/ckanext/canada/templates/scheming/package/snippets/resource_form.html index cd433f48c..8165b138e 100644 --- a/ckanext/canada/templates/scheming/package/snippets/resource_form.html +++ b/ckanext/canada/templates/scheming/package/snippets/resource_form.html @@ -12,8 +12,8 @@ {%- endif -%} {%- endfor -%}
    -
    - +
    + {{ _("Metadata Fields for Resources") }}
    @@ -24,12 +24,11 @@ {%- endfor -%}
    -