diff --git a/ckanext/odsh/helpers.py b/ckanext/odsh/helpers.py index 8ca47d1db0fd4a8d7dd00975a003c47a3fa23539..e3006a11acd1e64caf99bf2a9abe65a7b25cc31a 100644 --- a/ckanext/odsh/helpers.py +++ b/ckanext/odsh/helpers.py @@ -107,4 +107,21 @@ def odsh_upload_known_formats(): return value def odsh_encodeurl(url): - return urllib.quote(url, safe='') \ No newline at end of file + return urllib.quote(url, safe='') + +def odsh_extract_error(key, errors): + if not errors or not ('extras' in errors): + return None + ext = errors['extras'] + for item in ext: + if 'key' in item: + for error in item['key']: + if error.startswith(key): + return error.replace(key+':','') + +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: + return item['value'] \ No newline at end of file diff --git a/ckanext/odsh/i18n/de/LC_MESSAGES/ckanext-odsh.mo b/ckanext/odsh/i18n/de/LC_MESSAGES/ckanext-odsh.mo index c95ab37b7b246ec07bc35948f19a82d5b63f66ac..91550d475d3d3b14a514f413e8d44e2f15df3c80 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 10c6577fa1cf294bea25256b7b4903c44173ea5f..cdb4740e8d967875bfd4c91f7d0617ebeb7d05b6 100644 --- a/ckanext/odsh/i18n/de/LC_MESSAGES/ckanext-odsh.po +++ b/ckanext/odsh/i18n/de/LC_MESSAGES/ckanext-odsh.po @@ -198,6 +198,10 @@ msgstr "Bitte geben Sie einen Titel ein" msgid "odsh_issued_error_label" msgstr "Bitte wählen Sie ein Veröffentlichungsdatum" + +msgid "odsh_issued_not_date_error_label" +msgstr "Bitte wählen Sie ein korrektes Veröffentlichungsdatum" + msgid "Tag string: Fehlender Wert" msgstr "Bitte wählen Sie geeignete Schlagwörter" diff --git a/ckanext/odsh/plugin.py b/ckanext/odsh/plugin.py index 1751de4650caec9a81fec4a780b42bed63993703..b2b925d0b4a392fc5c425d2f3d74f7f40ba1664a 100644 --- a/ckanext/odsh/plugin.py +++ b/ckanext/odsh/plugin.py @@ -87,8 +87,6 @@ def known_spatial_uri(key, data, errors, context): spatial = str() cr = csv.reader(mapping_file, delimiter="\t") for row in cr: - print(data[key]) - print(row[0]) if row[0] == data[key]: not_found = False spatial_text = row[1] @@ -109,6 +107,30 @@ 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): + key = None + for k in data.keys(): + if data[k] == field: + key = k + break + if key is None: + return None + + return data[(key[0],key[1],'value')] + + +def odsh_validate_issued(key, data, errors, context): + value = _extract_value(key,data,'issued') + + if not value: + raise toolkit.Invalid('issued:odsh_issued_error_label') + + try: + datetime.datetime.strptime(value, '%Y-%m-%d') + except ValueError: + raise toolkit.Invalid('issued:odsh_issued_not_date_error_label') + + def odsh_tag_name_validator(value, context): tagname_match = re.compile('[\w \-.\:\(\)]*$', re.UNICODE) @@ -180,7 +202,9 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm 'odsh_get_spatial_text': odsh_helpers.odsh_get_spatial_text, 'odsh_render_datetime': odsh_helpers.odsh_render_datetime, 'odsh_upload_known_formats': odsh_helpers.odsh_upload_known_formats, - 'odsh_encodeurl': odsh_helpers.odsh_encodeurl + 'odsh_encodeurl': odsh_helpers.odsh_encodeurl, + 'odsh_extract_error': odsh_helpers.odsh_extract_error, + 'odsh_extract_value_from_extras': odsh_helpers.odsh_extract_value_from_extras } def before_map(self, map): @@ -251,7 +275,7 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm return ['title', 'notes'] def _extraFields(self): - return ['issued', 'temporal_start', 'temporal_end', 'spatial_uri', 'licenseAttributionByText'] + return ['temporal_start', 'temporal_end', 'spatial_uri', 'licenseAttributionByText'] def _update_schema(self, schema): for field in self._extraFields(): @@ -284,6 +308,11 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm 'format': [toolkit.get_converter('not_empty')] }) + schema['extras'].update({ + 'key': [toolkit.get_converter('odsh_validate_issued')] + }) + + def create_package_schema(self): schema = super(OdshPlugin, self).create_package_schema() self._update_schema(schema) @@ -315,6 +344,7 @@ 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_tag_name_validator': odsh_tag_name_validator} def extend_search_convert_local_to_utc_timestamp(self, str_timestamp): @@ -378,8 +408,6 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm fq = '{fq} ({start_query} OR {end_query} {enclosing_query})'.format( fq=fq, start_query=start_query, end_query=end_query, enclosing_query=enclosing_query) - print(fq) - # return modified facet queries search_params['fq'] = fq diff --git a/ckanext/odsh/templates/package/snippets/info.html b/ckanext/odsh/templates/package/snippets/info.html index 3e67621aaec07cfc1ae6a534a4c5cf9515bd9dc0..fdd13eb37c5228a807f673aa3238b8769234bdc0 100644 --- a/ckanext/odsh/templates/package/snippets/info.html +++ b/ckanext/odsh/templates/package/snippets/info.html @@ -60,8 +60,8 @@ Example: {% block last_change %} <div class="last-change-detail info-detail"> - {%set issued=h.odsh_render_datetime(pkg.issued) if pkg.issued else - h.odsh_render_datetime(pkg.metadata_created)%} + {% set value = h.odsh_extract_value_from_extras(pkg.extras,'issued')%} + {% set issued = h.odsh_render_datetime(value) if value else h.odsh_render_datetime(pkg.metadata_created)%} <div>{{ _('issued') }}:</div> {{issued}} </div> diff --git a/ckanext/odsh/templates/package/snippets/package_basic_fields.html b/ckanext/odsh/templates/package/snippets/package_basic_fields.html index e0b8504906b0b40361f9479d0fbe44a527eb3b70..d4903e9d1cded62f4513e53f0e8d78c018b3e0ea 100644 --- a/ckanext/odsh/templates/package/snippets/package_basic_fields.html +++ b/ckanext/odsh/templates/package/snippets/package_basic_fields.html @@ -95,11 +95,28 @@ is_required=true,placeholder=_('Enter title')) }} </div> <!-- field issued --> - {% set issued_value=data.issued if data.issued else h.odsh_now() %} - {% set error_string = _('odsh_issued_error_label') if errors.issued %} - {% set issued_label='Veröffentlichungsdatum'%} - {{ form.input('issued', id='field-issued', label=issued_label, value=issued_value, - error=error_string, classes=['control-full'], type='date', is_required=true) }} + + {% set field='issued' %} + {% set value = h.odsh_extract_value_from_extras(data.extras,field)%} + {% set value_extras = value if value else h.odsh_now() %} + {% set index = 4 %} + + <div class="control-group 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"> + <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_extras}}" /> + </div> + <div class="span6 inline-error"> + {% if h.odsh_extract_error(field, errors) %} + {{_(h.odsh_extract_error(field, errors))}} + {% endif %} + </div> + </div> + </div> + </div> <!-- field tags -->