From: CKAN data.gov.au Date: Wed, 11 Sep 2013 07:00:41 +0000 Subject: Load old data from extras key/value store X-Git-Url: https://maxious.lambdacomplex.org/git/?p=ckanext-datagovau.git&a=commitdiff&h=7c7acbf5b45a8c6eb791fd9c6fc6ee57d91fccac --- Load old data from extras key/value store --- --- /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,692 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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,160 @@ +{% ckan_extends %} +{% block package_additional_info %} +
+

{{ _('Additional Info') }}

+ + + + + + + + + + + {# Add our custom field to the dataset read page. #} + {% if pkg.get('metadata_created') %} + + + + + {% endif %} + {% if pkg.get('metadata_updated') %} + + + + + {% endif %} + {% if pkg.get('agency_program') %} + + + + + {% endif %} + {% if pkg.get('Agency Program') %} + + + + + {% endif %} + {% if h.get_pkg_dict_extra(pkg,'DCTERMS.Source.URI') %} + + + + + {% endif %} + + {% if pkg.get('contact_point') %} + + + + + {% endif %} + {% if pkg.get('spatial_coverage') %} + + + + + + {% endif %} + {% if h.get_pkg_dict_extra(pkg,'Geospatial Coverage') %} + + + + + + {% endif %} + {% if pkg.get('granularity') %} + + + + + + {% endif %} + {% if h.get_pkg_dict_extra(pkg,'Granularity') %} + + + + + + {% endif %} + {% if pkg.get('jurisdiction') %} + + + + + + {% endif %} + {% if h.get_pkg_dict_extra(pkg,'AGLSTERMS.Jurisdiction') %} + + + + + + {% endif %} + {% if pkg.get('temporal_coverage') %} + + + + + + {% endif %} + {% if h.get_pkg_dict_extra(pkg,'Temporal Coverage') %} + + + + + + {% endif %} + {% if pkg.get('data_state') %} + + + + + + {% endif %} + {% if pkg.get('update_freq') %} + + + + + + {% endif %} + {% if h.get_pkg_dict_extra(pkg,'Update Frequency') %} + + + + + {% endif %} + + {% if pkg.maintainer_email %} + + + + + {% elif pkg.maintainer %} + + + + + {% endif %} + + +
{{ _('Field') }}{{ _('Value') }}
Date Published{{ pkg.metadata_created.split("T")[0] }}
Date Updated{{ pkg.metadata_updated.split("T")[0] }}
Agency Program {{ pkg.agency_program }}
Agency Program {{ pkg.get('Agency Program') }}
{{ _('Source') }}{{ h.link_to(h.get_pkg_dict_extra(pkg,'DCTERMS.Source.URI'), + h.get_pkg_dict_extra(pkg,'DCTERMS.Source.URI'), rel='dct:source', target='_blank') }} +
Contact Point {{ h.mail_to(email_address=pkg.contact_point, + name=pkg.contact_point) }}
Geospatial Coverage {{ pkg.spatial_coverage }}
Geospatial Coverage {{ h.get_pkg_dict_extra(pkg,'Geospatial Coverage') }}
Data Granularity {{ pkg.granularity }}
Data Granularity {{ h.get_pkg_dict_extra(pkg,'Granularity') }}
Government Jurisdiction {{ pkg.jurisdiction }}
Government Jurisdiction {{ h.get_pkg_dict_extra(pkg,'AGLSTERMS.Jurisdiction') }}
Temporal Coverage {{ pkg.temporal_coverage }}
Temporal Coverage {{ h.get_pkg_dict_extra(pkg,'Temporal Coverage') }}
Data State {{ pkg.data_state }}
Update Frequency {{ pkg.update_freq }}
Update Frequency {{ h.get_pkg_dict_extra(pkg,'Update Frequency') }}
{{ _('Maintainer') }}{{ + h.mail_to(email_address=pkg.maintainer_email, name=pkg.maintainer) }} +
{{ _('Maintainer') }}{{ pkg.maintainer }}
+
+ + +{% 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,149 @@ + + + + ${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"] } + + + ${ group_dict["title"] } + + + ${c.pkg_dict['name']} + + + + + + ${rsc_dict.get('name')} + + ${rsc_dict.get('description')} + + ${rsc_dict.get('created')} + ${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['organization']['title'] } + + + + + ${h.get_action("user_show",{"id":username})["display_name"]} + + + + + + + ${h.get_pkg_dict_extra(c.pkg_dict,'DCTERMS.Source.URI') } + + + ${c.pkg_dict.contact_point } + ${ c.pkg_dict.spatial_coverage } + ${ h.get_pkg_dict_extra(c.pkg_dict,'Geospatial Coverage') } + ${ c.pkg_dict.jurisdiction } + ${ h.get_pkg_dict_extra(c.pkg_dict,'AGLSTERMS.Jurisdiction') } + ${ c.pkg_dict.get('temporal_coverage') } + ${ h.get_pkg_dict_extra(c.pkg_dict,'Temporal Coverage') } + + + Data State + ${ c.pkg_dict.get('data_state') } + + + + + + Update Frequency + ${ c.pkg_dict.get('update_freq') } + + + + + Update Frequency + ${ h.get_pkg_dict_extra(c.pkg_dict,'Update Frequency') } + + + + + + Agency Program + ${ h.get_pkg_dict_extra(c.pkg_dict,'Agency Program') } + + + + + Agency Program + ${ c.pkg_dict.get('agency_program') } + + + + + + Data Granularity + ${ h.get_pkg_dict_extra(c.pkg_dict,'Granularity') } + + + + + Data Granularity + ${ c.pkg_dict.get('granularity') } + + + + + + + ${extra_dict.get('key','')} + ${extra_dict.get('value','')} + + + + + + --- a/ckanext/datagovau/templates/package/read_base.html +++ b/ckanext/datagovau/templates/package/read_base.html @@ -1,15 +1,47 @@ {% ckan_extends %} - -{% block subtitle %}{{ pkg.title or pkg.name }}{% endblock %} {% block links -%} {{ super() }} - + + + {% endblock -%} {% block head_extras -%} {{ super() }} - + + + + + +{% if h.get_pkg_dict_extra(pkg,'DCTERMS.Source.URI') %}{% endif %} + + + + + + + + + + {% endblock -%} +{% block package_info %} +
+
+

{{ pkg.title or pkg.name }}

+
+
+
{{ _('Followers') }}
+
{{ h.SI_number_span(h.get_action('dataset_follower_count', {'id': pkg.id})) }}
+
+
+ +
+
+{% endblock %} + --- /dev/null +++ b/ckanext/datagovau/templates/package/resource_read.html @@ -1,1 +1,36 @@ +{% ckan_extends %} +{% block links -%} +{{ super() }} + + + +{% endblock -%} + +{% block head_extras -%} +{{ super() }} + + + + + +{% if h.get_pkg_dict_extra(pkg,'DCTERMS.Source.URI') %}{% endif %} + + + + + + + + + + + + + + + +{% endblock -%} + + + --- /dev/null +++ b/ckanext/datagovau/templates/package/snippets/package_basic_fields.html @@ -1,1 +1,62 @@ +{% 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.select('data_state', label=_('Data State'), options= [{'value': 'active', 'text': 'Active'}, {'value': 'inactive', 'text': 'Inactive'}], +selected='Active', error=errors.data_state) }} + +{{ 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,42 @@ +{% 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 %} + +{% block package_metadata_author %} +{% endblock %} + +{% block package_metadata_fields_maintainer %} +{% endblock %} + +{% block dataset_fields %} +{% if data.groups %} +
+ +
+ {% for group in data.groups %} + + {% endfor %} +
+
+{% endif %} +{% set group_name = 'groups__%s__id' % data.groups|length %} +{% set group_attrs = {'data-module': 'autocomplete', 'data-module-source': '/api/2/util/group/autocomplete?q=?', 'data-module-key': 'id', 'data-module-label': 'title'} %} +{{ form.input(group_name, label=_('Add Group/Theme'), id="field-group", value=data[group_name], classes=['control-medium'], attrs=group_attrs) }} +{% 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/" + } +]