From 7e4bf5085d6b2f65a69e77c15b7074c98f4584cd Mon Sep 17 00:00:00 2001 From: anonymous <anonymous> Date: Mon, 21 Jan 2019 16:01:04 +0100 Subject: [PATCH] add remaining fields --- ckanext/odsh/fanstatic/odsh_form.js | 5 +- ckanext/odsh/helpers.py | 2 +- .../odsh/i18n/de/LC_MESSAGES/ckanext-odsh.mo | Bin 5291 -> 5361 bytes .../odsh/i18n/de/LC_MESSAGES/ckanext-odsh.po | 11 ++- ckanext/odsh/plugin.py | 61 ++++++------- ckanext/odsh/templates/macros/form.html | 6 +- .../odsh/templates/package/snippets/info.html | 9 +- .../snippets/package_basic_fields.html | 81 ++++++++++++------ 8 files changed, 103 insertions(+), 72 deletions(-) diff --git a/ckanext/odsh/fanstatic/odsh_form.js b/ckanext/odsh/fanstatic/odsh_form.js index 65db0a26..7a58d4e2 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 af351d91..d09c885f 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..b78ceec4f6a144574ce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ZU%-4 zj0_CBxgk;K!wX3pQM?Qch71f0#k>#)EaipBpXRNH#K}!w2>px~;_}bDkTk)`$G{-Q zz`&r#2N8GWV_;BYU|@*mV_=X6S;z-5Xc1I?10N&`j`2Z4^eP_%g8%~q!(Bc|2)^Tk zM8Q`+hzA+!`5^+r{163lP+FBAk`{EJd?S8H;<V(4Br-pK25`t#@k6rVOn!)iw(&!v z=o&vH5kKOGI2_~(P?`}FfP|!;00V;-0|P_7g#ZJCA_D_MvH&FLTLl;xG#MBe<_kc4 zc2WQmr`H7_2E7(wU@&4}U|<x4SZE>$acGDj#Na4Fh(}VO{A@u;;w%+}gj|&%#3Ks@ z!68)7uuTw>i1rCWg6aZP<3lL@S`gxpuTXW&LXgBKDg;T@l0p!Rm7uf^lr|HB<PHZR zh`9km5QioTLF`Kx0y(svfuRzrph1X%K?9T>g%}ug85kIL2{AC3GcYi`5P~Ec1z|{# zx(P!<AVnCGMy3lxLS~OJ#G*^Wkhpy;3~}H$VTgnO3o|fSg0ig$1A{XI1B0yy1A`_g z`!!DPWL2HaA|lLhrQnvDk&~L2l3Jt?o?0|{6|1*mN~%IiYOz98YGz4MVrgz_F`A;1 z&7W8=F}f8bmSiU8D3lguqRTS`Bg=(kq$(5_q$X#kWu~Smga&ykWELyr<(DXA=jE5@ zZ9c?a!!)^pi*xfst_@6+B?WjUKN41)Y$z-|c|LEzWMKiJ$$N!`H^1i<V47?u?7R6t LzY+6fW|4OQzN5Tp diff --git a/ckanext/odsh/i18n/de/LC_MESSAGES/ckanext-odsh.po b/ckanext/odsh/i18n/de/LC_MESSAGES/ckanext-odsh.po index cdb4740e..fba045b2 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 4ae1d875..53e2a145 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 7e2305ed..f5b95d28 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 fdd13eb3..aa8d02d0 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 36fb61c1..18e2dfee 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"> -- GitLab