-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from salsa-nathan/feature/DDCI-5_temporal_conte…
…nt_ac4 [DDCI-115] - added temporal date fields
- Loading branch information
Showing
5 changed files
with
98 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
ckanext/qdes_schema/templates/scheming/package/snippets/additional_info.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{% extends "package/snippets/additional_info.html" %} | ||
|
||
{%- set exclude_fields = [ | ||
'id', | ||
'title', | ||
'name', | ||
'notes', | ||
'tag_string', | ||
'license_id', | ||
'owner_org', | ||
] -%} | ||
|
||
{%- set temporal_coverage = [ | ||
'temporal_start', | ||
'temporal_end', | ||
] -%} | ||
|
||
{% block package_additional_info %} | ||
{%- for field in schema.dataset_fields -%} | ||
{%- if field.field_name not in exclude_fields | ||
and field.display_snippet is not none -%} | ||
<tr> | ||
<th scope="row" class="dataset-label"> | ||
{% if field.field_name in temporal_coverage %} | ||
{{ "Temporal coverage start" if field.field_name == 'temporal_start' else "Temporal coverage end" }} | ||
{%- else -%} | ||
{{ h.scheming_language_text(field.label) }} | ||
{%- endif -%} | ||
</th> | ||
<td class="dataset-details"{% | ||
if field.display_property %} property="{{ field.display_property | ||
}}"{% endif %}>{%- snippet 'scheming/snippets/display_field.html', | ||
field=field, data=pkg_dict, schema=schema -%}</td> | ||
</tr> | ||
{%- endif -%} | ||
{%- endfor -%} | ||
{% if h.check_access('package_update',{'id':pkg_dict.id}) %} | ||
<tr> | ||
<th scope="row" class="dataset-label">{{ _("State") }}</th> | ||
<td class="dataset-details">{{ _(pkg_dict.state) }}</td> | ||
</tr> | ||
{% endif %} | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import ckan.plugins.toolkit as toolkit | ||
from datetime import datetime as dt | ||
|
||
def qdes_temporal_start_end_date(key, flattened_data, errors, context): | ||
""" | ||
Validate the start and date. | ||
It will raise an error, when: | ||
- If the either start or end date is not empty. | ||
- If the start date < end date | ||
""" | ||
temporal_start_value = flattened_data[('temporal_start',)] | ||
temporal_end_value = flattened_data[('temporal_end',)] | ||
|
||
if ((len(temporal_start_value) > 0) != (len(temporal_end_value) > 0)) and (len(flattened_data.get(key)) == 0): | ||
raise toolkit.Invalid("This field should not be empty") | ||
|
||
if (len(temporal_start_value) > 0) and (len(temporal_end_value) > 0): | ||
if dt.strptime(temporal_start_value, '%Y-%m-%d') > dt.strptime(temporal_end_value, '%Y-%m-%d'): | ||
if key == ('temporal_start',): | ||
raise toolkit.Invalid("Must be earlier than end date.") | ||
elif key == ('temporal_end',): | ||
raise toolkit.Invalid("Must be later than start date.") |