Skip to content

Commit

Permalink
Improve created/modified dates
Browse files Browse the repository at this point in the history
The commit updates the `last_update.html` template in the `schemingdcat` extension to use the `schemingdcat_parse_localised_date` helper function for displaying the date. This ensures that the date is correctly formatted based on the user's locale. The change improves the user experience by providing a more localized and readable date format for the last update information.
  • Loading branch information
mjanez committed May 16, 2024
1 parent 93da11a commit 1ccaa19
Show file tree
Hide file tree
Showing 10 changed files with 489 additions and 92 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.ropeproject
node_modules
bower_components
.vscode

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
32 changes: 31 additions & 1 deletion ckanext/schemingdcat/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from yaml.loader import SafeLoader
from pathlib import Path
from functools import lru_cache
import datetime

from six.moves.urllib.parse import urlencode

Expand Down Expand Up @@ -998,4 +999,33 @@ def schemingdcat_package_count_for_source(source_id):
search_dict = {'fq': fq, 'include_private': True}
context = {'model': model, 'session': model.Session}
result = logic.get_action('package_search')(context, search_dict)
return result.get('count', 0)
return result.get('count', 0)

@helper
def schemingdcat_parse_localised_date(date_=None):
'''Parse a datetime object or timestamp string as a localised date.
If timestamp is badly formatted, then None is returned.
:param date_: the date
:type date_: datetime or date or ISO string format
:rtype: date
'''
if not date_:
return None
if isinstance(date_, str):
try:
date_ = ckan_helpers.date_str_to_datetime(date_)
except (TypeError, ValueError):
return None
# check we are now a datetime or date
if isinstance(date_, datetime.datetime):
date_ = date_.date()
elif not isinstance(date_, datetime.date):
return None

# Format date based on locale
locale = schemingdcat_get_current_lang()
if locale == 'es':
return date_.strftime('%d-%m-%Y')
else:
return date_.strftime('%Y-%m-%d')
67 changes: 43 additions & 24 deletions ckanext/schemingdcat/schemas/dcat/dcat_dataset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ scheming_version: 2
dataset_type: document
about: "Datasets/Distributions: Adaptation for CKAN of the Data Catalog Vocabulary (DCAT) - Version 3 (https://www.w3.org/TR/vocab-dcat-3/)."
about_url: https://github.com/mjanez/ckanext-schemingdcat
schema_version: 1.0
schema_date: 2023-08-24
form_languages: ["en", "es"]
required_language: "en"
schema_version: 2.1
schema_date: 2024-05-01
schema_name: dcat
schema_title: DCAT
schema_description: Data Catalog Vocabulary (DCAT)
Expand All @@ -26,18 +28,19 @@ dataset_fields:
en: Basic metadata identification and reference information.
es: Información básica de identificación y referencia de los metadatos.

# Dataset title (M)
field_name: title
# Dataset title translated (M)
field_name: title_translated
label:
en: Dataset title
es: Título del conjunto de datos
preset: title
validators: not_empty scheming_required
preset: schemingdcat_fluent_title_translated
required: True
display_property: dct:title
form_placeholder:
en: eg. A descriptive title.
es: ej. Un título descriptivo.
form_languages: ["en", "es"]
required_language: "en"

# Dataset locator (O)
## For all resources that is equivalent to this element, such as a URI (of dcat:Dataset)
Expand Down Expand Up @@ -73,18 +76,22 @@ dataset_fields:
en: "Graphic that provides an illustration of the dataset."
es: "Gráfico que ilustra el conjunto de datos."

# Dataset abstract (M)
- field_name: notes
# # Dataset abstract translated (M)
- field_name: notes_translated
label:
en: Abstract
es: Resumen
form_snippet: markdown.html
display_property: dct:description
validators: not_empty scheming_required
preset: schemingdcat_fluent_notes_translated
required: True
display_property: dct:description
form_placeholder:
en: eg. Some useful description about the dataset.
es: ej. Una descripción útil sobre el conjunto de datos.
form_languages: ["en", "es"]
required_language: "en"
default_values:
en: Default abstract of the {dataset}.
es: Resumen por defecto del conjunto de datos {dataset}.

# Dataset type (M)
- field_name: dcat_type
Expand Down Expand Up @@ -374,23 +381,18 @@ dataset_fields:
label:
en: Date of creation
es: Fecha de creación
validators: not_empty scheming_required
display_property: dct:created
required: True
preset: date
preset: date_created

# Date of last revision (O)
- field_name: modified
label:
en: Date of last revision
es: Fecha de última modificación
validators: not_empty scheming_required
display_snippet: schemingdcat/display_snippets/last_update.html
display_property: dct:modified
required: True
preset: date
preset: date_modified

##TODO:##
# Keyword value (M)
- field_name: tag_string
label:
Expand All @@ -403,6 +405,21 @@ dataset_fields:
en: A keyword or tag describing the resource.'
es: 'Palabra clave o etiqueta que describe el recurso.'

# Keyword URI (M)
## TODO: Improve form_snippet to generate tag_uri auto from tag_string
## TODO: Add as scheming_datastore_choices (helpers.py/#102) http://github.com/ckan/ckanext-scheming/issues/270
## Only for ckanext-dcat profiles.py
- field_name: tag_uri
label:
en: Keyword URIs
es: URI de palabras clave
preset: multiple_text
display_snippet: schemingdcat/display_snippets/list_keywords.html
form_placeholder: 'http://inspire.ec.europa.eu/metadata-codelist/IACSData/gsaa'
help_text:
en: 'eg.: Metadata code list register (INSPIRE): http://inspire.ec.europa.eu/metadata-codelist'
es: 'ej: Registro de listas controladas de metadatos (INSPIRE): http://inspire.ec.europa.eu/metadata-codelist'

# TODO: Probably better include contact_role and contact_organization (boolean) to distinguish between vcard:Individual and vcard:Organizationto use in ckanext-dcat/profiles.py
# Metadata point of contact URI (M)
- field_name: contact_uri
Expand Down Expand Up @@ -673,11 +690,12 @@ dataset_fields:
label:
en: Provenance statement
es: Declaración de procedencia
form_snippet: markdown.html
preset: schemingdcat_fluent_markdown
display_property: dct:provenance
form_placeholder:
en: Means the history of a data set, and the life cycle from collection and acquisition through compilation and derivation to its current form, in accordance with EN ISO-19101.
es: Historia de un conjunto de datos y su ciclo de vida desde su recogida y adquisición hasta su compilación y derivación hasta su forma actual, con arreglo a la norma EN ISO-19101.
form_languages: ["en", "es"]

# Conformity (M)
- field_name: conforms_to
Expand Down Expand Up @@ -1182,11 +1200,12 @@ dataset_fields:
help_text:
en: A description of the differences between this version and a previous version of the Dataset.
es: Una descripción de las diferencias entre esta versión y una versión anterior del Dataset.
preset: schemingdcat_fluent_markdown
display_property: adms:versionNotes
form_snippet: markdown.html
form_placeholder:
en: eg. Some useful version notes about the dataset.
es: ej. Una descripción útil sobre las diferencias de esta versión del conjunto de datos.
form_languages: ["en", "es"]

# Dataset validity (O)
- field_name: valid
Expand All @@ -1208,7 +1227,7 @@ resource_fields:
display_property: dcat:accessURL
display_snippet: schemingdcat/display_snippets/link.html

# Resource title (M)
#FIX: Resource title (M) -- name_translated field dont work
- field_name: name
label:
en: Distribution title
Expand All @@ -1218,7 +1237,7 @@ resource_fields:
es: ej. Web Map Service
display_property: dct:title

# Resource abstract (M)
#FIX: Resource abstract (M) -- description_translated field dont work
- field_name: description
label:
en: Distribution abstract
Expand All @@ -1235,15 +1254,15 @@ resource_fields:
en: Date of creation
es: Fecha de creación
display_property: dct:created
preset: date
preset: date_created

# Date of last revision (M)
- field_name: modified
label:
en: Date of last revision
es: Fecha de última modificación
display_property: dct:modified
preset: date
preset: date_modified

# Resource status (O)
- field_name: availability
Expand Down
Loading

0 comments on commit 1ccaa19

Please sign in to comment.