diff --git a/ckanext/odsh/fanstatic/odsh_form.js b/ckanext/odsh/fanstatic/odsh_form.js index 65db0a26a295f238e356e6d5e90296a979bea79e..7a58d4e2a6e193ef4bcecb960b0c512a1ea61749 100644 --- a/ckanext/odsh/fanstatic/odsh_form.js +++ b/ckanext/odsh/fanstatic/odsh_form.js @@ -16,14 +16,15 @@ ckan.module('odsh_form', function ($) // toggle input for 'Namensgebung' depending on the selected licence // TODO: this implementation should be more generic var id = '#field-license'; + var id_name = '#field-licenseAttributionByText-value'; var toggle = function () { if ($(id).val().indexOf('dl-by-de/2.0') !== -1) { - $('#field-licence-name').prop('disabled', false); + $(id_name).prop('disabled', false); } else { - $('#field-licence-name').prop('disabled', true); + $(id_name).prop('disabled', true); } } toggle(id) diff --git a/ckanext/odsh/helpers.py b/ckanext/odsh/helpers.py index af351d915b0dfa6d435fb15d3b5f40bb49559d3f..d09c885f3cda1bc9680bd7a54a45ed5829d6038b 100644 --- a/ckanext/odsh/helpers.py +++ b/ckanext/odsh/helpers.py @@ -128,5 +128,5 @@ def odsh_extract_value_from_extras(extras, key): if not extras: return None for item in extras: - if 'key' in item and item['key'].lower() == key: + if 'key' in item and item['key'].lower() == key.lower(): return item['value'] diff --git a/ckanext/odsh/i18n/de/LC_MESSAGES/ckanext-odsh.mo b/ckanext/odsh/i18n/de/LC_MESSAGES/ckanext-odsh.mo index 91550d475d3d3b14a514f413e8d44e2f15df3c80..b78ceec4f6a144574ce8a604425f7fe531d61b01 100644 Binary files a/ckanext/odsh/i18n/de/LC_MESSAGES/ckanext-odsh.mo and b/ckanext/odsh/i18n/de/LC_MESSAGES/ckanext-odsh.mo differ diff --git a/ckanext/odsh/i18n/de/LC_MESSAGES/ckanext-odsh.po b/ckanext/odsh/i18n/de/LC_MESSAGES/ckanext-odsh.po index cdb4740e8d967875bfd4c91f7d0617ebeb7d05b6..fba045b2488bff750543628d1d90b7eed9034bff 100644 --- a/ckanext/odsh/i18n/de/LC_MESSAGES/ckanext-odsh.po +++ b/ckanext/odsh/i18n/de/LC_MESSAGES/ckanext-odsh.po @@ -165,16 +165,19 @@ msgstr "Dateien" msgid "Spatial uri" msgstr "Raumbezug" -msgid "Spatial uri: The specified URI is not known" +msgid "odsh_spatial_uri_unknown_error_label" msgstr "Der räumliche Bezug is ungültig" -msgid "Spatial uri: Fehlender Wert" +msgid "odsh_spatial_uri_error_label" msgstr "Bitte geben Sie einen räumlichen Bezug an" -msgid "Beginn des Zeitraumes: Fehlender Wert" +msgid "odsh_temporal_start_error_label" msgstr "Bitte wählen Sie einen Beginn des Zeitraumes aus" -msgid "Ende des Zeitraumes: Fehlender Wert" +msgid "odsh_temporal_end_error_label" +msgstr "Bitte wählen Sie ein Ende des Zeitraumes aus" + +msgid "odsh_temporal_error_label" msgstr "Bitte wählen Sie einen Zeitraum aus" msgid "Name: Fehlender Wert" diff --git a/ckanext/odsh/plugin.py b/ckanext/odsh/plugin.py index 4ae1d8759f7eb12d3e1a173de8f9c580d24f60ec..53e2a145d070f9ad21bd3ec15dbcd30f4e2029b2 100644 --- a/ckanext/odsh/plugin.py +++ b/ckanext/odsh/plugin.py @@ -74,7 +74,13 @@ def odsh_group_id_selected(selected, group_id): return False + def known_spatial_uri(key, data, errors, context): + value = _extract_value(key, data, 'spatial_uri') + + if not value: + raise toolkit.Invalid('spatial_uri:odsh_spatial_uri_error_label') + mapping_file = config.get('ckanext.odsh.spatial.mapping') try: mapping_file = urllib2.urlopen(mapping_file) @@ -86,14 +92,14 @@ def known_spatial_uri(key, data, errors, context): spatial = str() cr = csv.reader(mapping_file, delimiter="\t") for row in cr: - if row[0] == data[key]: + if row[0].encode('UTF-8') == value: not_found = False spatial_text = row[1] loaded = json.loads(row[2]) spatial = json.dumps(loaded['geometry']) break if not_found: - raise toolkit.Invalid("The specified URI is not known") + raise toolkit.Invalid('spatial_uri:odsh_spatial_uri_unknown_error_label') # Get the current extras index current_indexes = [k[1] for k in data.keys() @@ -106,7 +112,8 @@ def known_spatial_uri(key, data, errors, context): data[('extras', new_index+1, 'key')] = 'spatial' data[('extras', new_index+1, 'value')] = spatial -def _extract_value(key,data,field): + +def _extract_value(key, data, field): key = None for k in data.keys(): if data[k] == field: @@ -115,20 +122,23 @@ def _extract_value(key,data,field): if key is None: return None - return data[(key[0],key[1],'value')] + return data[(key[0], key[1], 'value')] -def odsh_validate_issued(key, data, errors, context): - value = _extract_value(key,data,'issued') +def odsh_validate_extra_date(key, field, data, errors, context): + value = _extract_value(key, data, field) if not value: - raise toolkit.Invalid('issued:odsh_issued_error_label') - + raise toolkit.Invalid(field+':odsh_'+field+'_error_label') + try: datetime.datetime.strptime(value, '%Y-%m-%d') except ValueError: - raise toolkit.Invalid('issued:odsh_issued_not_date_error_label') + raise toolkit.Invalid(field+':odsh_'+field+'_not_date_error_label') + +def odsh_validate_extra_date_factory(field): + return lambda key, data, errors, context: odsh_validate_extra_date(key, field, data, errors, context) def odsh_tag_name_validator(value, context): @@ -274,24 +284,7 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm def _fields(self): return ['title', 'notes'] - def _extraFields(self): - return ['temporal_start', 'temporal_end', 'spatial_uri', 'licenseAttributionByText'] - def _update_schema(self, schema): - for field in self._extraFields(): - if field == 'licenseAttributionByText': - schema.update({field: [ - toolkit.get_validator('ignore_missing'), - toolkit.get_converter('convert_to_extras')]}) - elif field == 'spatial_uri': - schema.update({field: [ - toolkit.get_converter('not_empty'), - toolkit.get_converter('known_spatial_uri'), - toolkit.get_converter('convert_to_extras')]}) - else: - schema.update({field: [ - toolkit.get_converter('not_empty'), - toolkit.get_converter('convert_to_extras')]}) for field in self._fields(): schema.update({field: [toolkit.get_converter('not_empty')]}) @@ -309,10 +302,14 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm }) schema['extras'].update({ - 'key': [toolkit.get_converter('odsh_validate_issued')] + 'key': [ + toolkit.get_converter('odsh_validate_issued'), + toolkit.get_converter('odsh_validate_temporal_start'), + toolkit.get_converter('odsh_validate_temporal_end'), + toolkit.get_converter('known_spatial_uri'), + ] }) - def create_package_schema(self): schema = super(OdshPlugin, self).create_package_schema() self._update_schema(schema) @@ -325,10 +322,6 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm def show_package_schema(self): schema = super(OdshPlugin, self).show_package_schema() - for field in self._extraFields(): - schema.update({ - field: [toolkit.get_converter('convert_from_extras')] - }) return schema def is_fallback(self): @@ -344,7 +337,9 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm def get_validators(self): return {'odsh_convert_groups_string': odsh_convert_groups_string, 'known_spatial_uri': known_spatial_uri, - 'odsh_validate_issued': odsh_validate_issued, + 'odsh_validate_issued': odsh_validate_extra_date_factory('issued'), + 'odsh_validate_temporal_start': odsh_validate_extra_date_factory('temporal_start'), + 'odsh_validate_temporal_end': odsh_validate_extra_date_factory('temporal_end'), 'odsh_tag_name_validator': odsh_tag_name_validator} def extend_search_convert_local_to_utc_timestamp(self, str_timestamp): diff --git a/ckanext/odsh/templates/macros/form.html b/ckanext/odsh/templates/macros/form.html index 7e2305edf09ed9366641e87343a43bb010df2282..f5b95d288c1e7cf6cd9f23199e33bd5338dde49c 100644 --- a/ckanext/odsh/templates/macros/form.html +++ b/ckanext/odsh/templates/macros/form.html @@ -53,9 +53,11 @@ is_required=false) %} {% endcall %} {% endmacro %} -{% macro input_extra(field, value='', index='') %} +{% macro input_extra(field, value='', index='', placeholder='', type='text', attrs={}) %} +{%- set _type = 'text' if type=='date' and not value else type -%} +{%- set onFocus = 'onfocus=(this.type=\'date\')' if type=='date' and not value else '' -%} <input id="field-{{field}}-key" type="hidden" name="extras__{{index}}__key" value="{{field}}" /> -<input id="field-{{field}}-value" type="text" name="extras__{{index}}__value" value="{{value}}" /> +<input id="field-{{field}}-value" type="{{_type}}" name="extras__{{index}}__value" value="{{value | empty_and_escape }}" placeholder="{{ placeholder }}" {{ onFocus }} {{ attributes(attrs) }}/> {% endmacro %} {# diff --git a/ckanext/odsh/templates/package/snippets/info.html b/ckanext/odsh/templates/package/snippets/info.html index fdd13eb37c5228a807f673aa3238b8769234bdc0..aa8d02d0e4b360fa1415e8975401adfe96a04f8d 100644 --- a/ckanext/odsh/templates/package/snippets/info.html +++ b/ckanext/odsh/templates/package/snippets/info.html @@ -44,7 +44,8 @@ Example: <div class="license-detail info-detail"> <div>{{ _('License') }}:</div> {%set lic=pkg.license_title if pkg.license_title else '-'%} - {%set name=' (' + pkg.licenseAttributionByText +')' if pkg.licenseAttributionByText else ''%} + {%set licenseAttributionByText = h.odsh_extract_value_from_extras(pkg.extras,'licenseAttributionByText') %} + {%set name=' (' + licenseAttributionByText +')' if licenseAttributionByText else ''%} <p>{{ lic }}{{ name }}</p> </div> {% endblock %} @@ -52,8 +53,10 @@ Example: {% block timerange %} <div class="timerange-detail info-detail"> <div>{{ _('timerange') }}:</div> - {%set start=h.odsh_render_datetime(pkg.temporal_start) if pkg.temporal_start else ''%} - {%set end=h.odsh_render_datetime(pkg.temporal_end) if pkg.temporal_end else ''%} + {% set temporal_start = h.odsh_extract_value_from_extras(pkg.extras,'temporal_start') %} + {% set temporal_end = h.odsh_extract_value_from_extras(pkg.extras,'temporal_end') %} + {%set start=h.odsh_render_datetime(temporal_start) if temporal_start else ''%} + {%set end=h.odsh_render_datetime(temporal_end) if temporal_end else ''%} <p>{{ start }} - {{ end }}</p> </div> {% endblock %} diff --git a/ckanext/odsh/templates/package/snippets/package_basic_fields.html b/ckanext/odsh/templates/package/snippets/package_basic_fields.html index 36fb61c1826daed8b2a64a312a2a2c3df1e4701b..18e2dfee69e669945e5c9fa7c620b29a3a01d5b4 100644 --- a/ckanext/odsh/templates/package/snippets/package_basic_fields.html +++ b/ckanext/odsh/templates/package/snippets/package_basic_fields.html @@ -54,10 +54,14 @@ is_required=true,placeholder=_('Enter title')) }} </div> <div class='span3'> <!-- field Namensnennung --> - {{ form.input_raw('licenseAttributionByText', id='field-licence-name', value=data.licenseAttributionByText, - error=errors.licenseAttributionByText, - classes=['control-full'],type='text',is_required=true,attrs={'disabled':true, + {% set field = 'licenseAttributionByText' %} + {% set value = h.odsh_extract_value_from_extras(data.extras,field) %} + <div class="control-group {{ " error" if error }} control-full"> + <div class="controls"> + {{ form.input_extra(field, value=value, index=h.odsh_create_checksum(field), type='text', attrs={'disabled':true, 'data-module':"odsh_form", 'data-module-licensetoggle':'true' }, placeholder=_('enter name')) }} + </div> + </div> </div> <div class="span6 inline-error"> {{error}} @@ -67,47 +71,57 @@ is_required=true,placeholder=_('Enter title')) }} {% endblock %} <!-- timerange --> - {% set error_string = _(_('Temporal end') + ': '+errors.temporal_end[0]) if errors.temporal_end %} + {% set error_start = h.odsh_extract_error('temporal_start', errors) %} + {% set error_end = h.odsh_extract_error('temporal_end', errors) %} + {% set error_string = 'odsh_temporal_error_label' if error_start and error_end else (error_start if error_start else (error_end if error_end))%} <label for="start-end" class="control-label">{{ _('timerange') }}: <span title="{{ _("This field is required") }}" class="control-required">*</span> </label> <div class='row-fluid'> <div id='start-end' class='span3'> <!-- field temporal_start --> - {% set temporal_start_label=_('odsh_temporal_start_label') %} - {% set data_temporal_start = data.temporal_start.split('T')[0] if data.temporal_start else None %} - {{ form.input_raw('temporal_start', id='field-temporal-start', value=data_temporal_start, - error=errors.temporal_start, - classes=['control-full'],type='date',is_required=true,placeholder=_('from')) - }} + {% set field = 'temporal_start' %} + {% set data_temporal_start = h.odsh_extract_value_from_extras(data.extras,field) %} + {% set value = data_temporal_start.split('T')[0] if data_temporal_start else None %} + <div class="control-group {{ " error" if error_start }} control-full"> + <div class="controls"> + {{ form.input_extra(field, value=value, index=h.odsh_create_checksum(field), type='date', placeholder=_('from')) }} + </div> + </div> </div> <div class='span3'> <!-- field temporal_end --> - {% set temporal_end_label='Ende des Zeitraumes' %} - {% set data_temporal_end = data.temporal_end.split('T')[0] if data.temporal_end else None %} - {{ form.input_raw('temporal_end', id='field-temporal-end', value=data_temporal_end, - error=errors.temporal_end, classes=['control-full'],type='date',is_required=true, placeholder=_('to')) - }} - </div> - <div class="span6 inline-error"> - {{error_string}} + {% set field = 'temporal_end' %} + {% set data_temporal_end = h.odsh_extract_value_from_extras(data.extras,field) %} + {% set value = data_temporal_end.split('T')[0] if data_temporal_end else None %} + <div class="control-group {{ " error" if error_end }} control-full"> + <div class="controls"> + {{ form.input_extra(field, value=value, index=h.odsh_create_checksum(field), type='date', placeholder=_('to')) }} + </div> + </div> </div> + {% if error_string %} + <div class="span6 inline-error"> + {{_(error_string)}} + </div> + {% endif %} </div> <!-- field issued --> {% set field = 'issued' %} {% set value = h.odsh_extract_value_from_extras(data.extras,field) %} - <div class="control-group control-full"> + {% set error = h.odsh_extract_error(field, errors) %} + <div class="control-group {{ " error" if error }} control-full"> <label class="control-label" for="field-{{field}}">Veröffentlichungsdatum: <span title="Dieses Feld ist erforderlich" class="control-required">*</span> </label> <div class="controls"> <div class="row-fluid"> <div class="span6"> - {{ form.input_extra(field, value=value if value else h.odsh_now(), index=h.odsh_create_checksum(field)) }} + {{ form.input_extra(field, value=value if value else h.odsh_now(), index=h.odsh_create_checksum(field), type='date') }} </div> <div class="span6 inline-error"> - {% if h.odsh_extract_error(field, errors) %} - {{_(h.odsh_extract_error(field, errors))}} + {% if error %} + {{_(error)}} {% endif %} </div> </div> @@ -168,11 +182,24 @@ is_required=true,placeholder=_('Enter title')) }} {% endblock %} <!-- field spatial_uri --> - {% set error_string = _('Spatial uri' + ': '+errors.spatial_uri[0]) if errors.spatial_uri%} - {{ form.input('spatial_uri', id='field-spatial-uri', label=_('Spatial uri'), - value=data.spatial_uri, - error=error_string, classes=['control-full'],type='text',is_required=true, - placeholder=_('Enter spatial uri')) }} + {% set field = 'spatial_uri' %} + {% set value = h.odsh_extract_value_from_extras(data.extras,field) %} + {% set error = h.odsh_extract_error(field, errors) %} + <div class="control-group {{ " error" if error }} control-full"> + <label class="control-label" for="field-{{field}}">{{_('Spatial uri')}}: <span title="Dieses Feld ist erforderlich" class="control-required">*</span> </label> + <div class="controls"> + <div class="row-fluid"> + <div class="span6"> + {{ form.input_extra(field, value=value, index=h.odsh_create_checksum(field), type='text', placeholder=_('Enter spatial uri')) }} + </div> + <div class="span6 inline-error"> + {% if error %} + {{_(error)}} + {% endif %} + </div> + </div> + </div> + </div> <!-- field private --> <div class="control-group">