From: Alex Sadleir Date: Mon, 09 Sep 2013 07:11:20 +0000 Subject: Work on unified metadata output X-Git-Url: https://maxious.lambdacomplex.org/git/?p=ckanext-datagovau.git&a=commitdiff&h=b0ad27eef182ae8a9a1692e8891cfde997b052df --- Work on unified metadata output --- --- /dev/null +++ b/.idea/.name @@ -1,1 +1,1 @@ - +ckanext-datagovau --- /dev/null +++ b/.idea/compiler.xml @@ -1,1 +1,24 @@ + + + + + + --- /dev/null +++ b/.idea/encodings.xml @@ -1,1 +1,6 @@ + + + + + --- /dev/null +++ b/.idea/misc.xml @@ -1,1 +1,23 @@ + + + + + + + + + + + + + + + + + + --- /dev/null +++ b/.idea/modules.xml @@ -1,1 +1,10 @@ + + + + + + + + + --- /dev/null +++ b/.idea/scopes/scope_settings.xml @@ -1,1 +1,5 @@ - + + + + --- /dev/null +++ b/.idea/vcs.xml @@ -1,1 +1,8 @@ + + + + + + + --- /dev/null +++ b/.idea/workspace.xml @@ -1,1 +1,684 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + localhost + 5050 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- a/README.rst +++ b/README.rst @@ -4,9 +4,11 @@ * A CKAN Extension "plugin" at ``ckanext/datagovau/plugin.py`` which, when loaded, overrides various settings in the core ``ini``-file to provide: - * A path to local customisations of the core templates and available licenses database - * A custom Package edit form + * A path to local customisations of the core templates + * A custom Package edit form that defaults to cc-by licence * A custom n3/rdf output format + +* A cut down licenses.json file Installation ============ @@ -17,5 +19,9 @@ Then activate it by setting ``ckan.plugins = datagovau`` in your main ``ini``-file. +To add the cut down licenses.json set ``licenses_group_url = http://%(ckan.site_url)/licenses.json`` +or copy ``ckanext/datagovau/theme/public/licenses.json`` to the same folder as your CKAN config ini file +and set ``licenses_group_url = file://%(here)s/licenses.json`` + --- /dev/null +++ b/ckanext/datagovau/__init__.py --- /dev/null +++ b/ckanext/datagovau/plugin.py @@ -1,1 +1,164 @@ +import logging +import ckan.plugins as plugins +import ckan.plugins.toolkit as tk + + +# get_action will be deprecated soon, this is the replacement +def get_user(user): + user_name = unicode(user) + if user_name: + user_obj = model.User.get(id) + context['user_obj'] = user_obj + if user_obj is None: + raise NotFound + else: + raise NotFound + + return model_dictize.user_dictize(user_obj,context) + + +class ExampleIDatasetFormPlugin(plugins.SingletonPlugin, + tk.DefaultDatasetForm): + '''An example IDatasetForm CKAN plugin. + + Uses a tag vocabulary to add a custom metadata field to datasets. + + ''' + plugins.implements(plugins.IConfigurer, inherit=False) + plugins.implements(plugins.IDatasetForm, inherit=False) + plugins.implements(plugins.ITemplateHelpers, inherit=False) + + # These record how many times methods that this plugin's methods are + # called, for testing purposes. + num_times_new_template_called = 0 + num_times_read_template_called = 0 + num_times_edit_template_called = 0 + num_times_search_template_called = 0 + num_times_history_template_called = 0 + num_times_package_form_called = 0 + num_times_check_data_dict_called = 0 + num_times_setup_template_variables_called = 0 + + + def update_config(self, config): + # Add this plugin's templates dir to CKAN's extra_template_paths, so + # that CKAN will use this plugin's custom templates. + # here = os.path.dirname(__file__) + # rootdir = os.path.dirname(os.path.dirname(here)) + + tk.add_template_directory(config, 'templates') + tk.add_public_directory(config, 'theme/public') + tk.add_resource('theme/public', 'ckanext-datagovau') + # config['licenses_group_url'] = 'http://%(ckan.site_url)/licenses.json' + + def get_helpers(self): + return {'getuser': get_user} + + def is_fallback(self): + # Return True to register this plugin as the default handler for + # package types not handled by any other IDatasetForm plugin. + return True + + def package_types(self): + # This plugin doesn't handle any special package types, it just + # registers itself as the default (above). + return [] + + + def create_package_schema(self): + schema = super(ExampleIDatasetFormPlugin, self).create_package_schema() + schema = self._modify_package_schema(schema) + return schema + + def update_package_schema(self): + schema = super(ExampleIDatasetFormPlugin, self).update_package_schema() + schema = self._modify_package_schema(schema) + return schema + + def show_package_schema(self): + schema = super(ExampleIDatasetFormPlugin, self).show_package_schema() + + # Don't show vocab tags mixed in with normal 'free' tags + # (e.g. on dataset pages, or on the search page) + schema['tags']['__extras'].append(tk.get_converter('free_tags_only')) + + # Add our custom_text field to the dataset schema. + # ignore_missing == optional + # ignore_empty == mandatory but not for viewing + # !!! always convert_from_extras first + schema.update({ + 'agency_program': [tk.get_converter('convert_from_extras'), + tk.get_validator('ignore_missing')], + 'contact_point': [tk.get_converter('convert_from_extras'), + tk.get_validator('ignore_empty')], + 'spatial_coverage': [tk.get_converter('convert_from_extras'), + tk.get_validator('ignore_empty')], + 'granularity': [tk.get_converter('convert_from_extras'), + tk.get_validator('ignore_empty')], + 'jurisdiction': [tk.get_converter('convert_from_extras'), + tk.get_validator('ignore_empty')], + 'temporal_coverage': [tk.get_converter('convert_from_extras'), + tk.get_validator('ignore_empty')], + 'data_state': [tk.get_converter('convert_from_extras'), + tk.get_validator('ignore_empty')], + 'update_freq': [tk.get_converter('convert_from_extras'), + tk.get_validator('ignore_empty')] + }) + return schema + + def _modify_package_schema(self, schema): + # Add our custom_test metadata field to the schema, this one will use + # convert_to_extras instead of convert_to_tags. + # ignore_missing == optional + # not_empty == mandatory, enforced here while modifying + + schema.update({ + 'agency_program': [tk.get_validator('ignore_missing'), + tk.get_converter('convert_to_extras')], + 'contact_point': [tk.get_converter('convert_to_extras'), + tk.get_validator('not_empty')], + 'spatial_coverage': [tk.get_converter('convert_to_extras'), + tk.get_validator('not_empty')], + 'granularity': [tk.get_converter('convert_to_extras'), + tk.get_validator('not_empty')], + 'jurisdiction': [tk.get_converter('convert_to_extras'), + tk.get_validator('not_empty')], + 'temporal_coverage': [tk.get_converter('convert_to_extras'), + tk.get_validator('not_empty')], + 'data_state': [tk.get_converter('convert_to_extras'), + tk.get_validator('not_empty')], + 'update_freq': [tk.get_converter('convert_to_extras'), + tk.get_validator('not_empty')] + }) + return schema + + # These methods just record how many times they're called, for testing + # purposes. + # TODO: It might be better to test that custom templates returned by + # these methods are actually used, not just that the methods get + # called. + + def setup_template_variables(self, context, data_dict): + return super(ExampleIDatasetFormPlugin, self).setup_template_variables( + context, data_dict) + + def new_template(self): + return super(ExampleIDatasetFormPlugin, self).new_template() + + def read_template(self): + return super(ExampleIDatasetFormPlugin, self).read_template() + + def edit_template(self): + return super(ExampleIDatasetFormPlugin, self).edit_template() + + def search_template(self): + return super(ExampleIDatasetFormPlugin, self).search_template() + + def history_template(self): + return super(ExampleIDatasetFormPlugin, self).history_template() + + def package_form(self): + return super(ExampleIDatasetFormPlugin, self).package_form() + + --- /dev/null +++ b/ckanext/datagovau/templates/package/read.html @@ -1,1 +1,44 @@ +{% ckan_extends %} +{% block package_additional_info %} +{{ super() }} + +{# Add our custom field to the dataset read page. #} +{% if pkg.get('agency_program') %} +
+

Agency Program: {{ pkg.agency_program }}

+
+{% endif %} +{% if pkg.get('contact_point') %} +
+

Contact Point: {{ pkg.contact_point }}

+
+{% endif %} +{% if pkg.get('spatial_coverage') %} +
+

Geospatial Coverage: {{ pkg.spatial_coverage }}

+{% endif %} +{% if pkg.get('granularity') %} +
+

Data Granularity: {{ pkg.granularity }}

+{% endif %} +{% if pkg.get('jurisdiction') %} +
+

Government Jurisdiction: {{ pkg.jurisdiction }}

+{% endif %} +{% if pkg.get('temporal_coverage') %} +
+

Temporal Coverage: {{ pkg.temporal_coverage }}

+{% endif %} +{% if pkg.get('data_state') %} +
+

Data State: {{ pkg.data_state }}

+{% endif %} +{% if pkg.get('update_freq') %} +
+

Update Frequency: {{ pkg.update_freq }}

+ +{% endif %} + +{% endblock %} + --- /dev/null +++ b/ckanext/datagovau/templates/package/read.n3 @@ -1,1 +1,45 @@ +@prefix : . +@prefix dcat: . +@prefix dct: . +@prefix foaf: . +@prefix owl: . +@prefix rdf: . +<${ h.url_for(controller='package',action='read',id=c.pkg_dict['name'], qualified=True)}> +a dcat:Dataset; + dct:description "${c.pkg_dict['notes']}"; + dct:identifier "${c.pkg_dict['name']}"; + dct:relation [ + rdf:value ""; + :label "change_note" ], + [ + rdf:value ""; + :label "definition_note" ], + [ + rdf:value ""; + :label "editorial_note" ], + [ + rdf:value ""; + :label "example_note" ], + [ + rdf:value ""; + :label "history_note" ], + [ + rdf:value ""; + :label "scope_note" ], + [ + rdf:value ""; + :label "skos_note" ], + [ + rdf:value ""; + :label "temporal_granularity" ], + [ + rdf:value ""; + :label "type_of_dataset" ], + [ + rdf:value ""; + :label "update_frequency" ]; + dct:title "${c.pkg_dict['title']}"; + :label "${c.pkg_dict['name']}"; + = ; + foaf:homepage . --- /dev/null +++ b/ckanext/datagovau/templates/package/read.rdf @@ -1,1 +1,92 @@ + + + + ${c.pkg_dict['name']} + ${c.pkg_dict['title']} + + + Dataset + ${c.pkg_dict['notes']} + ${c.pkg_dict['metadata_created']} + ${c.pkg_dict['metadata_modified']} + en + ${c.pkg_dict['license_url']} + + ${ tag_dict["name"] } + + + ${ tag_dict["title"] } + + ${h.get_action("user_show",{"id":c.author})["display_name"]} + ${h.get_action("user_show",{"id":c.author})["email"]} + + + ${c.pkg_dict['name']} + + + + + + ${rsc_dict.get('name')} + + ${rsc_dict.get('description')} + + ${rsc_dict.get('revision_timestamp')} + ${rsc_dict.get('revision_timestamp')} + ${rsc_dict.get('size')} + ${rsc_dict.get('mimetype')} + ${rsc_dict.get('size')} bytes + + + ${rsc_dict.get('format')} + ${rsc_dict.get('format')} + + + ${rsc_dict.get('name')} + + + + + + ${ c.pkg_dict['organization']['title'] } + + + + + ${ c.pkg_dict['author'] } + + + + + + ${ c.pkg_dict['maintainer'] } + + + + + + + + + ${extra_dict.get('key','')} + ${extra_dict.get('value','')} + + + + + + --- /dev/null +++ b/ckanext/datagovau/templates/package/snippets/package_basic_fields.html @@ -1,1 +1,63 @@ +{% ckan_extends %} +{% block package_basic_fields_org %} + +{{ super() }} + +{{ form.input('agency_program', label=_('Agency Program'), id='field-agency_program', +placeholder=_('Name of the Agency Program that generated the data if relevant'), +value=data.agency_program, error=errors.agency_program, classes=['control-medium']) }} + +{{ form.input('contact_point', label=_('Contact Point'), id='field-contact_point', +placeholder=_('Email address for questions about content of dataset'), +value=data.contact_point, error=errors.contact_point, classes=['control-medium']) }} + +{{ form.input('spatial_coverage', label=_('Geospatial Coverage'), id='field-spatial_coverage', +placeholder=_('The geographical area covered by the data. Eg: Whole of Australia, New South Wales, Canberra'), +value=data.spatial_coverage, error=errors.spatial_coverage, classes=['control-medium']) }} + +{{ form.input('granularity', label=_('Data Granularity'), id='field-granularity', +placeholder=_('Granularity in time, place etc. Eg: incidents reports on daily basis by location.'), +value=data.granularity, error=errors.granularity, classes=['control-medium']) }} + +{{ form.input('jurisdiction', label=_('Government Jurisdiction'), id='field-jurisdiction', +placeholder=_('New South Wales, Glenorchy City Council, Federal'), +value=data.jurisdiction, error=errors.jurisdiction, classes=['control-medium']) }} + +{{ form.input('temporal_coverage', label=_('Temporal Coverage'), id='field-temporal_coverage', +placeholder=_('The timespan the dataset relates to: Current, 2008, 2008-2012, Jan 2012'), +value=data.temporal_coverage, error=errors.temporal_coverage, classes=['control-medium']) }} + +{{ form.input('data_state', label=_('Data State'), id='field-data_state', +placeholder=_('Active or Inactive'), +value=data.data_state, error=errors.data_state, classes=['control-medium']) }} + +{{ form.input('update_freq', label=_('Update Frequency'), id='field-update_freq', +placeholder=_('How often the dataset is updated. Eg: Daily, Weekly, Never'), +value=data.update_freq, error=errors.update_freq, classes=['control-medium']) }} + +{% endblock %} + + +{% block package_basic_fields_license %} +
+ {% set error = errors.license_id %} + +
+ + {% if error %}{{ error }}{% endif %} + + + {% trans %} + License definitions and additional information can be found + at opendefinition.org + {% endtrans %} + +
+
+{% endblock %} --- /dev/null +++ b/ckanext/datagovau/templates/package/snippets/package_metadata_fields.html @@ -1,1 +1,18 @@ +{% ckan_extends %} +{# Remove 'free extras' from the package form. If you're using +convert_to/from_extras() as we are with our 'custom_text' field below then +you need to remove free extras from the form, or editing your custom field +won't work. #} +{% block custom_fields %} +{% endblock %} + +{# https://github.com/okfn/ckan/blob/master/ckan/templates/macros/form.html documents the macros for fields #} + +{% block package_metadata_fields %} + + +{{ super() }} + +{% endblock %} + --- /dev/null +++ b/ckanext/datagovau/theme/public/licenses.json @@ -1,1 +1,30 @@ +[ + { + "domain_content": true, + "domain_data": false, + "domain_software": false, + "family": "", + "id": "other-open", + "is_generic": true, + "is_okd_compliant": true, + "is_osi_compliant": false, + "maintainer": "", + "status": "active", + "title": "Other (Open)", + "url": "" + }, + { + "domain_content": true, + "domain_data": false, + "domain_software": false, + "family": "", + "id": "cc-by", + "is_okd_compliant": true, + "is_osi_compliant": false, + "maintainer": "", + "status": "active", + "title": "Creative Commons Attribution 3.0 Australia", + "url": "http://creativecommons.org/licenses/by/3.0/au/" + } +]