From 49e1d9987e3e83e3521ea3f4d314de016d059b1d Mon Sep 17 00:00:00 2001 From: anonymous <anonymous> Date: Mon, 4 Feb 2019 12:55:26 +0100 Subject: [PATCH] fix erro date handling date range search --- ckanext/odsh/helpers.py | 8 +++++-- .../odsh/i18n/de/LC_MESSAGES/ckanext-odsh.mo | Bin 5504 -> 5512 bytes .../odsh/i18n/de/LC_MESSAGES/ckanext-odsh.po | 4 ++-- ckanext/odsh/public/odsh.css | 7 ++++++ ckanext/odsh/templates/package/search.html | 4 ++-- .../odsh/templates/snippets/search_form.html | 22 ++++++++++++++---- 6 files changed, 34 insertions(+), 11 deletions(-) diff --git a/ckanext/odsh/helpers.py b/ckanext/odsh/helpers.py index 767fcff4..de23276c 100644 --- a/ckanext/odsh/helpers.py +++ b/ckanext/odsh/helpers.py @@ -105,11 +105,15 @@ def odsh_get_spatial_text(pkg_dict): return None -def odsh_render_datetime(datetime_, date_format='{0.day:02d}.{0.month:02d}.{0.year:4d}'): +def odsh_render_datetime(datetime_, fromIso=True): + date_format='{0.day:02d}.{0.month:02d}.{0.year:4d}' if not datetime_: return '' try: - DATETIME_FORMAT = '%Y-%m-%dT%H:%M:%S' + if fromIso: + DATETIME_FORMAT = '%Y-%m-%dT%H:%M:%S' + else: + DATETIME_FORMAT = '%Y-%m-%d' dt = datetime.datetime.strptime( datetime_, DATETIME_FORMAT) return dt.strftime('%d.%m.%Y') diff --git a/ckanext/odsh/i18n/de/LC_MESSAGES/ckanext-odsh.mo b/ckanext/odsh/i18n/de/LC_MESSAGES/ckanext-odsh.mo index fad2be93b305da5ac2ae00cffa567377b95df015..af5ed0c634f28dd2ada0363867e8c0f1f22a8ad6 100644 GIT binary patch delta 70 zcmZqB?$F-Q!m298z`(FVgn>bZfq~($2m^y90|UbY5e5cl1_lNxQ3eK01_p+>%_~`% a`B_}^Qc@<b6%l6(E=epZNtt|9WH$iPHV>!( delta 62 zcmeCsZqVM)!m29Hz`(FVgn<D>9}r<+uw-ChxFN#8;LO0lASBAbpvl0%5Vm<GD>FZ% Q%j69r;*2hn&x-5@0A0}xBLDyZ diff --git a/ckanext/odsh/i18n/de/LC_MESSAGES/ckanext-odsh.po b/ckanext/odsh/i18n/de/LC_MESSAGES/ckanext-odsh.po index 84f15ec8..1fc8c021 100644 --- a/ckanext/odsh/i18n/de/LC_MESSAGES/ckanext-odsh.po +++ b/ckanext/odsh/i18n/de/LC_MESSAGES/ckanext-odsh.po @@ -291,7 +291,7 @@ msgid "map" msgstr "Karte" msgid "wrong_start_date_for_search" -msgstr "Das Datum ist ungültig" +msgstr "Das Startdatum ist ungültig" msgid "wrong_end_date_for_search" -msgstr "Das Datum ist ungültig" +msgstr "Das Enddatum ist ungültig" diff --git a/ckanext/odsh/public/odsh.css b/ckanext/odsh/public/odsh.css index ccaa8fc3..9554c898 100644 --- a/ckanext/odsh/public/odsh.css +++ b/ckanext/odsh/public/odsh.css @@ -367,6 +367,9 @@ label.rangesearch.disabled { top: -8px; right: -8px; } +.pill.error .remove .fa.fa-times{ + background-color: #d4004b; +} .container-fluid.odsh-dataset-item { padding: 20px 0px 20px 0px; @@ -1349,6 +1352,10 @@ display: none; background-color: #003064; color:white; } +.filtered.pill.error{ + background-color: #d4004b; +} + .site-title{ color:black; /* text-align:center; */ diff --git a/ckanext/odsh/templates/package/search.html b/ckanext/odsh/templates/package/search.html index 14ff1f51..58e3082d 100644 --- a/ckanext/odsh/templates/package/search.html +++ b/ckanext/odsh/templates/package/search.html @@ -39,9 +39,9 @@ default_extent="{ \"type\": \"Polygon\", \"coordinates\": [[[7.6574,53.1632],[11 <form id="date-search-form" method="get" action="{% url_for controller='package', action='search' %}"> <div class='controls rangesearch'> {%- set start = request.params['ext_startdate'] -%} - {%- set start_error = h.odsh_render_datetime(start) == '' and start -%} + {%- set start_error = h.odsh_render_datetime(start, False) == '' and start -%} {%- set end = request.params['ext_enddate'] -%} - {%- set end_error = h.odsh_render_datetime(end) == '' and end -%} + {%- set end_error = h.odsh_render_datetime(end, False) == '' and end -%} {%- set typeStart = 'text' if (start_error or not start) else 'date' -%} {%- set typeEnd = 'text' if (end_error or not end) else 'date' -%} {%- set onFocus = 'onfocus=(this.type=\'date\')' -%} diff --git a/ckanext/odsh/templates/snippets/search_form.html b/ckanext/odsh/templates/snippets/search_form.html index 8e3add90..b06a8458 100644 --- a/ckanext/odsh/templates/snippets/search_form.html +++ b/ckanext/odsh/templates/snippets/search_form.html @@ -73,25 +73,37 @@ {% endif %} {% endif %} <div id="datesearch-filter"> - {%set start_date=h.odsh_render_datetime(request.params.get('ext_startdate'))%} - {%set end_date=h.odsh_render_datetime(request.params.get('ext_enddate'))%} + {%set start_date=h.odsh_render_datetime(request.params.get('ext_startdate'), False)%} + {%set end_date=h.odsh_render_datetime(request.params.get('ext_enddate'), False)%} {%- set start_error = start_date == '' and request.params.get('ext_startdate')-%} {%- set end_error = end_date == '' and request.params.get('ext_enddate')-%} - {% if (start_date or end_date) and (not start_error and not end_error)%} + {% if start_date or end_date or start_error or end_error%} <p class="filter-list"> - {% if start_date %} + {% if start_date and not start_error%} <span class="filtered pill"> {{_('daterange')}}: {{_('from')}} {{ start_date}} <a href="{{ h.remove_url_param('ext_startdate') }}" class="remove" title="{{ _('Remove') }}"><i class="fa fa-times"></i></a> </span> {% endif %} + {% if start_error %} + <span class="filtered pill error"> + {{_('daterange')}}: {{_('wrong_start_date_for_search')}} + <a href="{{ h.remove_url_param('ext_startdate') }}" class="remove" title="{{ _('Remove') }}"><i class="fa fa-times"></i></a> + </span> + {% endif %} - {% if end_date %} + {% if end_date and not end_error%} <span class="filtered pill"> {{_('daterange')}}: {{_('to')}} {{ end_date}} <a href="{{ h.remove_url_param('ext_enddate') }}" class="remove" title="{{ _('Remove') }}"><i class="fa fa-times"></i></a> </span> {% endif %} + {% if end_error %} + <span class="filtered pill error"> + {{_('daterange')}}: {{_('wrong_end_date_for_search')}} + <a href="{{ h.remove_url_param('ext_enddate') }}" class="remove" title="{{ _('Remove') }}"><i class="fa fa-times"></i></a> + </span> + {% endif %} </p> {% endif %} </div> -- GitLab