From 7ad7263d97c00fe977641efad24b39d44d8d32d0 Mon Sep 17 00:00:00 2001 From: anonymous <anonymous> Date: Wed, 16 Jan 2019 09:53:35 +0100 Subject: [PATCH] first draft with issued --- ckanext/odsh/helpers.py | 19 ++++++++- .../odsh/i18n/de/LC_MESSAGES/ckanext-odsh.mo | Bin 5186 -> 5291 bytes .../odsh/i18n/de/LC_MESSAGES/ckanext-odsh.po | 4 ++ ckanext/odsh/plugin.py | 40 +++++++++++++++--- .../odsh/templates/package/snippets/info.html | 4 +- .../snippets/package_basic_fields.html | 27 +++++++++--- 6 files changed, 80 insertions(+), 14 deletions(-) diff --git a/ckanext/odsh/helpers.py b/ckanext/odsh/helpers.py index 8ca47d1d..e3006a11 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 GIT binary patch delta 1467 zcmX@4v0AhKo)F7a1_lO(Fa`z&83qQ1GfW^J0@tuIFbFX)Fx0X#FmN+4Fic=&U{GaX zV3@-SQGbY)fq|8Qf#E(Y0|Pq)1H)6Oy0@$h4EziX3_n>J7?c?p7&zG&7`PZ17<Abf z7z7y@7%bQr7!(*7>KVM)7#JiO7#Oml60J~$)7c;vE@FdNu#OGlkS%Ns3~USx49D3R z7&sXi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ZgoIG5 zAUN&RGxQ2Vf@(fg;|3_bOAz9aBM^lQmjoe+?uj5IHNSwW`v|3fLupnaNb2Vof|x5W z1aYW=5ZFQnGa-mWJ;3ty3=IB43=A5e{3*o1pv%C(&?y8-EZc=3L3vjQ;`84^khGyE z3<;57VTc8p!jL$v5{5XeR~X{ZX~GN)mJAFGvxFHKoEaDxt_VXySOQeYI3_2j78ffd YZ*FCs%rd!wi*vIR*BXw^YQn9I0OJgSCjbBd diff --git a/ckanext/odsh/i18n/de/LC_MESSAGES/ckanext-odsh.po b/ckanext/odsh/i18n/de/LC_MESSAGES/ckanext-odsh.po index 10c6577f..cdb4740e 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 1751de46..b2b925d0 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 3e67621a..fdd13eb3 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 e0b85049..d4903e9d 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 --> -- GitLab