Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dataset & Resource Relationship Fields #1534

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions changes/1534.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added Dataset & Resource repeating Relationship field groups.
12 changes: 10 additions & 2 deletions ckanext/canada/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
JVickery-TBS marked this conversation as resolved.
Show resolved Hide resolved
data_dict.pop('relationship', None)

return data_dict

# IDataDictionaryForm
Expand Down Expand Up @@ -831,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':
Expand Down
4 changes: 2 additions & 2 deletions ckanext/canada/schemas/dataset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ dataset_fields:
en: FGP viewer is supported
value: fgp_viewer

- preset: canada_dataset_relationship


#
Expand All @@ -462,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:
Expand Down
8 changes: 6 additions & 2 deletions ckanext/canada/schemas/info.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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
Expand All @@ -504,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.
Expand Down
163 changes: 139 additions & 24 deletions ckanext/canada/schemas/presets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -2700,7 +2698,6 @@ 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: Continues
Expand Down Expand Up @@ -2755,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: 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
JVickery-TBS marked this conversation as resolved.
Show resolved Hide resolved
required: true
form_panel: 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:
Expand All @@ -2782,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
Expand All @@ -2802,11 +2835,45 @@ presets:
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: 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
- 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
validators: scheming_required scheming_choices
required: true
form_panel: relationships
JVickery-TBS marked this conversation as resolved.
Show resolved Hide resolved

# Field = Date Published.
# Add a Calendar control to select a Date.
Expand Down Expand Up @@ -2841,7 +2908,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
Expand Down Expand Up @@ -3267,7 +3334,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
Expand Down Expand Up @@ -4065,16 +4132,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.
Expand Down Expand Up @@ -4124,3 +4195,47 @@ presets:
display_snippet: null
validators: ignore
output_validators: canada_output_none


- preset_name: canada_dataset_relationship
values:
field_name: relationship
form_panel: relationships
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


- 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
24 changes: 6 additions & 18 deletions ckanext/canada/templates/package/read.html
Original file line number Diff line number Diff line change
Expand Up @@ -179,27 +179,15 @@ <h4>{{ _('Made available by the ') + owner_org_title }}</h4>
{{ super() }}
{% endif %}
{% endblock %}
{% block package_item_apps %}
<div class="span-6 margin-top-medium clear-both">
{% set apps = [] %}
{% for resource in pkg.resources %}
{% if resource.format == 'app' %}
{% do apps.append(resource) %}
{% endif %}
{% endfor %}
</div>
{% if apps|length > 0 %}
{% block related_items %}
{% if pkg.get('relationship') %}
<div class="span-6 margin-top-medium clear-both">
<h4>{{ _('Related Items') }}</h4>
<ul class="list-unstyled">
{% for resource in apps %}
{% snippet 'package/snippets/app_item.html', pkg=pkg, res=resource, res_num=loop.index, client_lang=client_lang %}
{% endfor %}
</ul>
<h2>{{ _('Dataset Relationships') }}</h2>
{% 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 %}
</div>
{% 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 %}
Expand Down
4 changes: 2 additions & 2 deletions ckanext/canada/templates/package/resource_read.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
{% endblock %}

{% block download_resource_button %}
{%if res.datastore_active %}
{% if res.datastore_active %}
<button class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
{% if not res.url or not h.is_url(res.url) %}
{{ _('Download') }}&nbsp;
Expand All @@ -75,5 +75,5 @@
data-pkg-id="{{ pkg.id }}" data-res-id="{{ res.id }}" data-org-id="{{ pkg.organization.id }}"><span>XML</span></a>
</li>
</ul>
{%endif%}
{% endif %}
{% endblock %}
7 changes: 0 additions & 7 deletions ckanext/canada/templates/package/snippets/app_item.html

This file was deleted.

1 change: 0 additions & 1 deletion ckanext/canada/templates/package/snippets/resources.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
<button class="btn btn-light btn-sm dropdown-toggle" type="button" id="dropdownRes{{ loop.index }}" data-bs-toggle="dropdown" aria-expanded="false" data-toggle="dropdown"><i class="fa fa-wrench"></i></button>
<ul class="dropdown-menu" aria-labelledby="dropdownRes{{ loop.index }}">
<li>{% link_for _('Edit resource'), named_route=pkg.type ~ '_resource.edit', id=pkg.name, resource_id=resource.id, class_='dropdown-item', icon='pencil' %}</li>
{% block resources_list_edit_dropdown_inner scoped %}{% endblock %}
<li>{% link_for _('Views'), named_route=pkg.type ~ '_resource.views', id=pkg.name, resource_id=resource.id, class_='dropdown-item', icon='chart-bar' %}</li>
</ul>
</div>
Expand Down
Loading
Loading