Skip to content
Snippets Groups Projects
Commit 6a016165 authored by chbaeh's avatar chbaeh
Browse files

ODPSH-5: add date range search

parent 06764ded
No related branches found
No related tags found
No related merge requests found
No preview for this file type
......@@ -267,3 +267,9 @@ msgstr "Grenzen der Karte"
msgid "Map showing the borders of {map_text}"
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
......@@ -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
......@@ -302,3 +303,56 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm
'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
......@@ -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 %}
......
......@@ -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>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment