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..6cb05577e992d402f1ba627d382cf8add6cac944 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,32 @@ 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, harvest_object, dataset_dict): + if 'license_id' in dataset_dict and dataset_dict['license_id']: + return register = model.Package.get_license_register() - 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']: + license = resource['license'] + print(license) + if license and license in register: + print("LICENSRE") + print(license) + 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(json.loads(harvest_object.content), 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(json.loads(harvest_object.content), dataset_dict) 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..0eb7cc0ad6352ae7a577f1d98ce85f999a3b4f6f 100755 --- a/setup.py +++ b/setup.py @@ -82,6 +82,7 @@ setup( [ckan.plugins] odsh=ckanext.odsh.plugin:OdshPlugin odsh_icap=ckanext.odsh.plugin:OdshIcapPlugin + odsh_dcatdeharvester=ckanext.odsh.plugin:OdshDCATRDFHarvesterPlugin statistikamtnord_harvester=ckanext.odsh.harvesters:StatistikamtNordHarvester kiel_harvester=ckanext.odsh.harvesters:KielHarvester