diff --git a/ckanext/odsh/i18n/de/LC_MESSAGES/ckanext-odsh.mo b/ckanext/odsh/i18n/de/LC_MESSAGES/ckanext-odsh.mo index 7be3b9dd8e3005b739e5a055e89edb4793ba60ca..952393e23e4bfc2b8588c20b80efe76d2ca4437b 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 8dda226ad3d0a6e2c548bd8182fcc110b9f37c11..072665bdfcd181964eb1fb5507006c1ae65e0c48 100644 --- a/ckanext/odsh/i18n/de/LC_MESSAGES/ckanext-odsh.po +++ b/ckanext/odsh/i18n/de/LC_MESSAGES/ckanext-odsh.po @@ -266,4 +266,10 @@ msgid "borders of map" msgstr "Grenzen der Karte" msgid "Map showing the borders of {map_text}" -msgstr "Karte, die die Grenzen von {map_text} zeigt" \ No newline at end of file +msgstr "Karte, die die Grenzen von {map_text} zeigt" + +msgid "submit date search" +msgstr "Zeitbezug anwenden" + +msgid "daterange" +msgstr "Zeitbezug" \ No newline at end of file diff --git a/ckanext/odsh/plugin.py b/ckanext/odsh/plugin.py index da8a03fb3d2c883565ae78227e7eb1d8c4d324a8..bea06ebf5f8a5c6fcac8bba6a9181ff3cb16105b 100644 --- a/ckanext/odsh/plugin.py +++ b/ckanext/odsh/plugin.py @@ -146,6 +146,7 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm plugins.implements(plugins.IFacets) plugins.implements(plugins.IDatasetForm) plugins.implements(plugins.IValidators) + plugins.implements(plugins.IPackageController, inherit=True) # IConfigurer @@ -301,4 +302,57 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm return { 'odsh_convert_groups_string': odsh_convert_groups_string, 'known_spatial_uri': known_spatial_uri, 'odsh_tag_name_validator': odsh_tag_name_validator} + + + def extend_search_convert_local_to_utc_timestamp(self, str_timestamp): + DATETIME_FORMAT = '%Y-%m-%d' + if not str_timestamp: + return '' + + ##Todo: do we need timezone conversions? + + local_datetime = datetime.datetime.strptime(str_timestamp, DATETIME_FORMAT); + # tz_code = config.get('ckan.timezone', 'Australia/Melbourne') + # local = timezone(tz_code) + # utc_datetime = _make_aware(local_datetime, local) + # local_datetime = utc_datetime.astimezone(pytz.utc) + return local_datetime.strftime(DATETIME_FORMAT)+"T00:00:00Z" + + # Add the custom parameters to Solr's facet queries + def before_search(self, search_params): + + extras = search_params.get('extras') + if not extras: + # There are no extras in the search params, so do nothing. + return search_params + + + print(search_params) + + start_date = self.extend_search_convert_local_to_utc_timestamp(extras.get('ext_startdate')) + end_date = self.extend_search_convert_local_to_utc_timestamp(extras.get('ext_enddate')) + + if not start_date and not end_date: + # The user didn't select any additional params, so do nothing. + return search_params + + if not start_date: + start_date='*' + if not end_date: + end_date='*' + + fq = search_params['fq'] + + if start_date and end_date: + # Add a date-range query with the selected start and end dates into the + # Solr facet queries. + print('change queary') + fq = '{fq} +metadata_modified:[{start_date} TO {end_date}]'.format( + fq=fq, start_date=start_date, end_date=end_date) + print(fq) + + #return modified facet queries + search_params['fq'] = fq + + return search_params diff --git a/ckanext/odsh/templates/package/search.html b/ckanext/odsh/templates/package/search.html index 3e23c668a5ce72bc40d181c052edfc50475948f1..5daf02958e0caa2d64d7848b78d4dfd37044bc2a 100644 --- a/ckanext/odsh/templates/package/search.html +++ b/ckanext/odsh/templates/package/search.html @@ -30,7 +30,19 @@ default_extent="{ \"type\": \"Polygon\", \"coordinates\": [[[7.6574,53.1632],[11 {{ h.snippet('snippets/facet_list.html', title=c.facet_titles[facet], name=facet) }} {% endfor %} </div> - <a class="close no-text hide-filters"><i class="fa fa-times-circle"></i><span class="text">close</span></a> + + {% block datereange_search %} + <form id="date-search-form" method="get" action="{% url_for controller='package', action='search' %}"> + {{ form.input_raw('ext_startdate', id='ext_startdate', value=request.params['ext_startdate'], + classes=['control-full'],type='date',placeholder=_('from')) + }} + {{ form.input_raw('ext_enddate', id='ext_enddate', value=request.params['ext_enddate'], + classes=['control-full'],type='date',placeholder=_('to')) + }} + <a href="javascript:{}" onclick="$('#date-search-form').submit();" class="action">{{_('submit date search') }}</a> + </form> + {% endblock %} + </div> {% endblock %} {% block package_search_results_api %} diff --git a/ckanext/odsh/templates/package/snippets/package_basic_fields.html b/ckanext/odsh/templates/package/snippets/package_basic_fields.html index 276525bfa1e5604b5c79b3e65d0017e1a6ee29d7..e0b8504906b0b40361f9479d0fbe44a527eb3b70 100644 --- a/ckanext/odsh/templates/package/snippets/package_basic_fields.html +++ b/ckanext/odsh/templates/package/snippets/package_basic_fields.html @@ -75,7 +75,7 @@ is_required=true,placeholder=_('Enter title')) }} <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 %} + {% 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')) @@ -84,7 +84,7 @@ is_required=true,placeholder=_('Enter title')) }} <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 %} + {% 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')) }} @@ -200,4 +200,4 @@ is_required=true,placeholder=_('Enter title')) }} </div> </div> </div> - {% endif %} + {% endif %} \ No newline at end of file diff --git a/ckanext/odsh/templates/snippets/search_form.html b/ckanext/odsh/templates/snippets/search_form.html index cd01cdb94cb90e4ba81809ad273a6fbd7278aaa3..c1d4b041c22d64a90cd9fecf628c2d23f760d042 100644 --- a/ckanext/odsh/templates/snippets/search_form.html +++ b/ckanext/odsh/templates/snippets/search_form.html @@ -72,6 +72,27 @@ <p class="filter-list"></p> {% endif %} {% endif %} + <div id="datesearch-filter"> + {%set start_date=request.params.get('ext_startdate')%} + {%set end_date=request.params.get('ext_enddate')%} + {% if start_date or end_date %} + <p class="filter-list"> + {% if start_date %} + <span class="filtered pill"> + {{_('daterange')}}: {{_('from')}} {{ h.odsh_render_datetime(start_date)}} + <a href="{{ h.remove_url_param('ext_startdate') }}" class="remove" title="{{ _('Remove') }}"><i class="fa fa-times"></i></a> + </span> + {% endif %} + + {% if end_date %} + <span class="filtered pill"> + {{_('daterange')}}: {{_('to')}} {{ h.odsh_render_datetime(end_date)}} + <a href="{{ h.remove_url_param('ext_enddate') }}" class="remove" title="{{ _('Remove') }}"><i class="fa fa-times"></i></a> + </span> + {% endif %} + </p> + {% endif %} + </div> {% endblock %} </form>