Skip to content

Commit

Permalink
[#85] Add support for custom metadata on datasets
Browse files Browse the repository at this point in the history
Allows to provide arbitrary key/value pairs. Support for harvesting them
and displaying them.

Requires ckan/ckan#1894
  • Loading branch information
amercader committed Aug 21, 2014
1 parent 6967a89 commit 591da72
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
13 changes: 13 additions & 0 deletions ckanext/glasgow/logic/schema.py
Expand Up @@ -130,6 +130,12 @@ def convert_ckan_dataset_to_ec_dataset(ckan_dict):
elif ckan_dict.get('tags_string'):
ec_dict['Tags'] = ckan_dict.get('tags_string')

# Arbitrary extras
ec_dict['Metadata'] = {}
for extra in ckan_dict.get('extras', []):
if extra['key'] not in ckan_dict and not extra['key'].startswith('harvest_'):
ec_dict['Metadata'][extra['key']] = extra['value']

return ec_dict


Expand All @@ -149,6 +155,13 @@ def convert_ec_dataset_to_ckan_dataset(ec_dict):
if ckan_dict.get('id'):
ckan_dict['id'] = unicode(ckan_dict['id'])

# Arbitrary stuff stored as extras
ec_keys = [v for k, v in ckan_to_ec_dataset_mapping.iteritems()]
ckan_dict['extras'] = []
for key, value in ec_dict.iteritems():
if key not in ec_keys:
ckan_dict['extras'].append({'key': key, 'value': value})

return ckan_dict


Expand Down
Expand Up @@ -63,4 +63,27 @@ <h3>{{ _('Metadata') }}</h3>
{% endblock %}
</tbody>
</table>

<h3>{{ _('Custom Metadata') }}</h3>
<table class="table table-striped table-bordered table-condensed">
<thead>
<tr>
<th scope="col">{{ _('Field') }}</th>
<th scope="col">{{ _('Value') }}</th>
</tr>
</thead>
<tbody>
{% for extra in pkg_dict.get('extras', []) %}
{% if not extra['key'].startswith('harvest_') %}
<tr>
<th scope="row" class="dataset-label">{{ extra['key'] }}</th>
<td class="dataset-details">{{ extra['value'] }}</td>
</tr>

{% endif %}
{% endfor %}
</tbody>
</table>


</section>
Expand Up @@ -92,6 +92,7 @@
{# Standard Version #}
{{ form.input('standard_version', label=_('Standard Version'), id='field-standard_version', value=data.standard_version, error=errors.standard_version, classes=['control-medium']) }}

{% snippet 'snippets/custom_form_fields.html', extras=data.extras, errors=errors, limit=3 %}
</fieldset>

{% set dataset_is_draft = data.get('state', 'draft').startswith('draft') or data.get('state', 'none') == 'none' %}
Expand Down

0 comments on commit 591da72

Please sign in to comment.