diff --git a/ckanext/odsh/fanstatic/odsh_form.js b/ckanext/odsh/fanstatic/odsh_form.js index bab54f50a474d7ad27822e3bc43d29694bcfeb3c..c4bbb1641fb8c8006888ef9d564f11cb6d31d3c4 100644 --- a/ckanext/odsh/fanstatic/odsh_form.js +++ b/ckanext/odsh/fanstatic/odsh_form.js @@ -5,12 +5,26 @@ ckan.module('odsh_form', function ($) { // enable multiselect for input if (this.options.multiselect) - $(this.el[0]).multiselect({ - allSelectedText: this.options.allselectedtext, - nonSelectedText: this.options.nonselectedtext, - nSelectedText: this.options.nselectedtext, - numberDisplayed: 1 - }); + { + var multi = $(this.el[0]) + if (multi) + { + multi.multiselect({ + allSelectedText: this.options.allselectedtext, + nonSelectedText: this.options.nonselectedtext, + nSelectedText: this.options.nselectedtext, + numberDisplayed: 1, + onChange: function (option, checked, select) + { + var values = $('#field-groups option:selected') + .map(function (a, item) { return item.value; }).get().join(',') + console.log(values) + $('#field-groups-value').val(values); + } + }); + } + } + if (this.options.licensetoggle) { // toggle input for 'Namensgebung' depending on the selected licence diff --git a/ckanext/odsh/plugin.py b/ckanext/odsh/plugin.py index 9146afeadb6f9a3b05788ac3d73ce8b3fb105724..1de32ff0b0de3578cc8723059b9c81c841a70f84 100644 --- a/ckanext/odsh/plugin.py +++ b/ckanext/odsh/plugin.py @@ -299,7 +299,6 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm plugins.implements(plugins.IDatasetForm) plugins.implements(plugins.IValidators) plugins.implements(plugins.IPackageController, inherit=True) - plugins.implements(IDCATRDFHarvester) # IConfigurer @@ -610,8 +609,8 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm return dict_pkg ## implementation of IDCATRDFHarvester - def before_download(self, url, harvest_job): - return url, [] +class OdshDCATRDFHarvesterPlugin(plugins.SingletonPlugin): + plugins.implements(IDCATRDFHarvester) def update_session(self, session): return session @@ -619,42 +618,28 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm def after_download(self, content, harvest_job): return content, [] - def before_update(self, harvest_object, dataset_dict, temp_dict): - pass - def after_update(self, harvest_object, dataset_dict, temp_dict): return None - def before_create(self, harvest_object, dataset_dict, temp_dict): - pass - def after_create(self, harvest_object, dataset_dict, temp_dict): return None + def before_download(self, url, harvest_job): + return url, [] - def before_update(self, harvest_object, dataset_dict, temp_dict): - if 'license_id' in dataset_dict: - return - + def _updateLicense(self, dataset_dict): register = model.Package.get_license_register() + print(dataset_dict) - for resource in harvest_object.resources: - license = resource.license - if license: - if license in register: - dataset_dict['license_id'] = license - return - - def before_create(self, harvest_object, dataset_dict, temp_dict): + for resource in dataset_dict['resources']: + print(resource) + license = resource['license'] if 'license' in resource else None + if license in register: + dataset_dict['license_id'] = license + return - if 'license_id' in dataset_dict: - return - - register = model.Package.get_license_register() + def before_update(self, harvest_object, dataset_dict, temp_dict): + self._updateLicense(dataset_dict) - for resource in harvest_object.resources: - license = resource.license - if license: - if license in register: - dataset_dict['license_id'] = license - return \ No newline at end of file + def before_create(self, harvest_object, dataset_dict, temp_dict): + self._updateLicense(dataset_dict) diff --git a/ckanext/odsh/profiles.py b/ckanext/odsh/profiles.py new file mode 100644 index 0000000000000000000000000000000000000000..a9285f981dbb312a1feec5d95fb306103f0e7655 --- /dev/null +++ b/ckanext/odsh/profiles.py @@ -0,0 +1,30 @@ +from ckanext.dcatde.profiles import DCATdeProfile +from ckanext.dcat.profiles import EuropeanDCATAPProfile, DCT +from ckan.model.license import LicenseRegister + +class ODSHDCATdeProfile(EuropeanDCATAPProfile): + + def _license(self, dataset_ref): + if self._licenceregister_cache is not None: + license_uri2id, license_title2id = self._licenceregister_cache + else: + license_uri2id = {} + license_title2id = {} + for license_id, license in LicenseRegister().items(): + license_uri2id[license_id] = license_id + license_uri2id[license.url] = license_id + license_title2id[license.title] = license_id + self._licenceregister_cache = license_uri2id, license_title2id + + for distribution in self._distributions(dataset_ref): + # If distribution has a license, attach it to the dataset + license = self._object(distribution, DCT.license) + if license: + # Try to find a matching license comparing URIs, then titles + license_id = license_uri2id.get(license.toPython()) + if not license_id: + license_id = license_title2id.get( + self._object_value(license, DCT.title)) + if license_id: + return license_id + return '' diff --git a/ckanext/odsh/templates/package/snippets/package_basic_fields.html b/ckanext/odsh/templates/package/snippets/package_basic_fields.html index f461de15ed45f2d0740f2e609ef2c0c530684000..683e0f7a6ea3ec7003ce60875b47334fd550a1fe 100644 --- a/ckanext/odsh/templates/package/snippets/package_basic_fields.html +++ b/ckanext/odsh/templates/package/snippets/package_basic_fields.html @@ -1,5 +1,6 @@ {% import 'macros/form.html' as form %} {% resource 'odsh/odsh_form.js' %} +{% resource 'odsh/bootstrap-multiselect.js' %} {% set dataset_is_draft = data.get('state', 'draft').startswith('draft') or data.get('state', 'none') == 'none' %} <!-- field title --> @@ -263,3 +264,41 @@ is_required=true,placeholder=_('Enter title')) }} </div> </div> {% endif %} + + <!-- field groups --> + {# + <div class="control-group"> + {% set groups_label='Kategorien'%} + {% set multiselect_nonSelectedText='keine' %} + {% set multiselect_allSelectedText='alle' %} + {% set multiselect_nSelectedText='gewählt' %} + <!-- {% set error = errors.groups %} --> + <label for="field-groups" class="control-label">{{ groups_label }} + <span title="{{ _("This field is required") }}" class="control-required">*</span> + </label> + <div class="controls"> + {% set existing_groups = data.get('groups') %} + {% if existing_groups %} + {% set existing_groups_string = existing_groups|map(attribute='id')|join(',') %} + {% else %} + {% set existing_groups_string = h.odsh_extract_value_from_extras(data.extras,'groups') %} + {% endif %} + {{existing_groups_string}} + {{existing_groups}} + {% if data.id %} + <input name='groups' value='[{"id":"ener"}]'></input> + {% else %} + <select id='field-groups' multiple="multiple" data-module="odsh_form" data-module-multiselect='true' + data-module-nonSelectedText="{{multiselect_nonSelectedText}}" data-module-allSelectedText="{{multiselect_allSelectedText}}" + data-module-nSelectedText="{{multiselect_nSelectedText}}"> + {% for option in h.groups_available()%} + <option value={{option.id}} {% if existing_groups_string!=None and option['id'] in existing_groups_string %}selected="selected" + {% endif %}> + {{ option['display_name'] }}</option> + {% endfor %} + </select> + {{ form.input_extra('groups', value=existing_groups_string, index=h.odsh_create_checksum('groups'), type='hidden')}} + {% endif %} + </div> + </div> + #} \ No newline at end of file diff --git a/ckanext/odsh/templates/package/snippets/resource_form.html b/ckanext/odsh/templates/package/snippets/resource_form.html index 7652b0b67e4cc9ed4e885e2549f75f63416f075b..91eaae9a5354a38cf88c56962c6dca3a7d756fca 100644 --- a/ckanext/odsh/templates/package/snippets/resource_form.html +++ b/ckanext/odsh/templates/package/snippets/resource_form.html @@ -6,6 +6,8 @@ {% set active = data and data.state=='active' %} {% set action = form_action or h.url_for(controller='package', action='new_resource', id=pkg_name) %} +{{errors}} + <form id="resource-edit" class="dataset-form dataset-resource-form {%if(data)%}resource-edit-form{%endif%}" method="post" action="{{ action }}" data-module="basic-form resource-form" enctype="multipart/form-data" novalidate> {% block stages %} diff --git a/ckanext/odsh/templates/snippets/search_result_text.html b/ckanext/odsh/templates/snippets/search_result_text.html index a764d458e0d529896f88161f3f0f08d5ea8f3ad6..d6160b0b127af11ced59c89e10dd116088eef3d4 100644 --- a/ckanext/odsh/templates/snippets/search_result_text.html +++ b/ckanext/odsh/templates/snippets/search_result_text.html @@ -39,7 +39,7 @@ Example: {{ text_query_none.format(query=query) }} {%- endif -%} {%- else -%} -{%- if count -%} +{%- if count and text_no_query -%} {{ text_no_query.format(number=h.localised_number(count)) }} {%- else -%} {{ text_no_query_none }} diff --git a/setup.py b/setup.py index 22cb91a1d3710cef8488e3945616f7bcbc0d6562..ad83e7b208eb34803ce9b626e428c6a3a8adff39 100755 --- a/setup.py +++ b/setup.py @@ -90,6 +90,9 @@ setup( [babel.extractors] ckan = ckan.lib.extract:extract_ckan + + [ckan.rdf.profiles] + odshdcatap_de=ckanext.odsh.profiles:ODSHDCATdeProfile ''', # If you are changing from the default layout of your extension, you may