Skip to content
Snippets Groups Projects
Commit 0b3e91c0 authored by anonymous's avatar anonymous
Browse files

fix harvest bug

parent df8e21cc
No related branches found
No related tags found
No related merge requests found
...@@ -5,12 +5,26 @@ ckan.module('odsh_form', function ($) ...@@ -5,12 +5,26 @@ ckan.module('odsh_form', function ($)
{ {
// enable multiselect for input // enable multiselect for input
if (this.options.multiselect) if (this.options.multiselect)
$(this.el[0]).multiselect({ {
var multi = $(this.el[0])
if (multi)
{
multi.multiselect({
allSelectedText: this.options.allselectedtext, allSelectedText: this.options.allselectedtext,
nonSelectedText: this.options.nonselectedtext, nonSelectedText: this.options.nonselectedtext,
nSelectedText: this.options.nselectedtext, nSelectedText: this.options.nselectedtext,
numberDisplayed: 1 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) if (this.options.licensetoggle)
{ {
// toggle input for 'Namensgebung' depending on the selected licence // toggle input for 'Namensgebung' depending on the selected licence
......
...@@ -299,7 +299,6 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm ...@@ -299,7 +299,6 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm
plugins.implements(plugins.IDatasetForm) plugins.implements(plugins.IDatasetForm)
plugins.implements(plugins.IValidators) plugins.implements(plugins.IValidators)
plugins.implements(plugins.IPackageController, inherit=True) plugins.implements(plugins.IPackageController, inherit=True)
plugins.implements(IDCATRDFHarvester)
# IConfigurer # IConfigurer
...@@ -610,8 +609,8 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm ...@@ -610,8 +609,8 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm
return dict_pkg return dict_pkg
## implementation of IDCATRDFHarvester ## implementation of IDCATRDFHarvester
def before_download(self, url, harvest_job): class OdshDCATRDFHarvesterPlugin(plugins.SingletonPlugin):
return url, [] plugins.implements(IDCATRDFHarvester)
def update_session(self, session): def update_session(self, session):
return session return session
...@@ -619,42 +618,28 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm ...@@ -619,42 +618,28 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm
def after_download(self, content, harvest_job): def after_download(self, content, harvest_job):
return content, [] return content, []
def before_update(self, harvest_object, dataset_dict, temp_dict):
pass
def after_update(self, harvest_object, dataset_dict, temp_dict): def after_update(self, harvest_object, dataset_dict, temp_dict):
return None return None
def before_create(self, harvest_object, dataset_dict, temp_dict):
pass
def after_create(self, harvest_object, dataset_dict, temp_dict): def after_create(self, harvest_object, dataset_dict, temp_dict):
return None return None
def before_download(self, url, harvest_job):
return url, []
def before_update(self, harvest_object, dataset_dict, temp_dict): def _updateLicense(self, dataset_dict):
if 'license_id' in dataset_dict:
return
register = model.Package.get_license_register() register = model.Package.get_license_register()
print(dataset_dict)
for resource in harvest_object.resources: for resource in dataset_dict['resources']:
license = resource.license print(resource)
if license: license = resource['license'] if 'license' in resource else None
if license in register: if license in register:
dataset_dict['license_id'] = license dataset_dict['license_id'] = license
return return
def before_create(self, harvest_object, dataset_dict, temp_dict): def before_update(self, harvest_object, dataset_dict, temp_dict):
self._updateLicense(dataset_dict)
if 'license_id' in dataset_dict:
return
register = model.Package.get_license_register()
for resource in harvest_object.resources: def before_create(self, harvest_object, dataset_dict, temp_dict):
license = resource.license self._updateLicense(dataset_dict)
if license:
if license in register:
dataset_dict['license_id'] = license
return
\ No newline at end of file
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 ''
{% import 'macros/form.html' as form %} {% import 'macros/form.html' as form %}
{% resource 'odsh/odsh_form.js' %} {% 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' %} {% set dataset_is_draft = data.get('state', 'draft').startswith('draft') or data.get('state', 'none') == 'none' %}
<!-- field title --> <!-- field title -->
...@@ -263,3 +264,41 @@ is_required=true,placeholder=_('Enter title')) }} ...@@ -263,3 +264,41 @@ is_required=true,placeholder=_('Enter title')) }}
</div> </div>
</div> </div>
{% endif %} {% 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
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
{% set active = data and data.state=='active' %} {% set active = data and data.state=='active' %}
{% set action = form_action or h.url_for(controller='package', action='new_resource', id=pkg_name) %} {% 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" <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> enctype="multipart/form-data" novalidate>
{% block stages %} {% block stages %}
......
...@@ -39,7 +39,7 @@ Example: ...@@ -39,7 +39,7 @@ Example:
{{ text_query_none.format(query=query) }} {{ text_query_none.format(query=query) }}
{%- endif -%} {%- endif -%}
{%- else -%} {%- else -%}
{%- if count -%} {%- if count and text_no_query -%}
{{ text_no_query.format(number=h.localised_number(count)) }} {{ text_no_query.format(number=h.localised_number(count)) }}
{%- else -%} {%- else -%}
{{ text_no_query_none }} {{ text_no_query_none }}
......
...@@ -90,6 +90,9 @@ setup( ...@@ -90,6 +90,9 @@ setup(
[babel.extractors] [babel.extractors]
ckan = ckan.lib.extract:extract_ckan 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 # If you are changing from the default layout of your extension, you may
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment