Skip to content

Commit

Permalink
Upgrade to 2.10
Browse files Browse the repository at this point in the history
  • Loading branch information
tino097 committed Jul 16, 2024
1 parent 2c78ced commit 8d91b06
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
25 changes: 17 additions & 8 deletions ckanext/datesearch/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,33 @@ class DateSearchPlugin(plugins.SingletonPlugin, DefaultTranslation):
plugins.implements(plugins.IConfigurer)
plugins.implements(plugins.IPackageController, inherit=True)

# IConfigurer
def update_config(self, config):
toolkit.add_template_directory(config, 'templates')
toolkit.add_resource('assets', 'datesearch')
toolkit.add_template_directory(config, "templates")
toolkit.add_resource("assets", "datesearch")

# IPackageController
def before_search(self, search_params):
extras = search_params.get('extras')
return self.before_dataset_search(search_params)

def before_dataset_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
start_date = extras.get('ext_startdate')
end_date = extras.get('ext_enddate')
start_date = extras.get("ext_startdate")
end_date = extras.get("ext_enddate")
if not start_date or not end_date:
# The user didn't select a start and end date, so do nothing.
return search_params

# Add a date-range query with the selected start and end dates into the
# Solr facet queries.
fq = search_params['fq']
fq = f'{fq} (begin_collection_date:[* TO {end_date}] -end_collection_date:[* TO *]) OR (-begin_collection_date:[* TO *] end_collection_date:[{start_date} TO *]) OR (begin_collection_date:[* TO {end_date}] end_collection_date:[{start_date} TO *])'
search_params['fq'] = fq
fq = search_params["fq"]
fq = (
f"{fq} ((begin_collection_date:[* TO {end_date}] -end_collection_date:[* TO *]) OR "
f"(-begin_collection_date:[* TO *] AND end_collection_date:[{start_date} TO *]) OR "
f"(begin_collection_date:[* TO {end_date}] AND end_collection_date:[{start_date} TO *]))"
)
search_params["fq"] = fq
return search_params
1 change: 0 additions & 1 deletion ckanext/datesearch/templates/package/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ <h2 class="module-heading">
data-module="daterangepicker-module" />
</div>
</section>
{% snippet "spatial/snippets/spatial_query.html", default_extent="[[47.8390,10.1403],[50.1734,13.2605]]" %}
{{ super() }}
{% endblock %}

0 comments on commit 8d91b06

Please sign in to comment.