Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optional ckanext.datagovtheme.next_harvest for catalog-next #205

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ CKAN version | Compatibility
### Configuration

[Optional]
`ckanext.datagovtheme.js_recent_view = true`
`ckanext.datagovtheme.harvest_next = false`

By default, this setting is `false`. The template relies on `ckanext-harvest` to display Harvest Object and Harvest Source information in the **Metadata Source** block. For catalog-next, datasets are added via API calls, eliminating the need for the `ckanext-harvest` dependency. Set this to `true` for the harvest_next version of the **Metadata Source** block.


[Optional]
`ckanext.datagovtheme.js_recent_view = false`


This defaults to `false`. If displaying the recent view count slows down page loading, the optional parameter can be set to `true` to make the recent view count an AJAX call, improving page loading speed. If the recent view count information (package['tracking_summary']) is already present, the AJAX call is disabled to reduce overhead. Therefore, the built-in recent view count rendering must be disabled for this mechanism to take effect. For catalog.data.gov, it means set setting `ckanext.datagovcatalog.add_packages_tracking_info` to false.
Expand Down
29 changes: 24 additions & 5 deletions ckanext/datagovtheme/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,14 @@ def render_datetime_datagov(date_str):
return value


def get_harvest_object_formats(harvest_object_id):
def get_harvest_object_formats(harvest_object_id, dataset_is_datajson=False):
# simplified return for harvest_next
harvest_next = asbool(config.get('ckanext.datagovtheme.harvest_next', 'false'))
if harvest_next:
return {
'object_format': 'data.json' if dataset_is_datajson else 'ISO-19139'
}

try:
obj = p.toolkit.get_action('harvest_object_show')({}, {'id': harvest_object_id})
except p.toolkit.ObjectNotFound:
Expand Down Expand Up @@ -315,14 +322,24 @@ def format_type(format_name):
}


def get_harvest_source_link(package_dict):
def get_harvest_source_link(package_dict, type='source'):
harvest_source_id = get_pkg_dict_extra(package_dict, 'harvest_source_id', None)
harvest_source_title = get_pkg_dict_extra(package_dict, 'harvest_source_title', None)
harvest_object_id = get_pkg_dict_extra(package_dict, 'harvest_object_id', None)
harvest_admin_url = config.get('ckanext.datagovtheme.harvest_admin_url')

if harvest_source_id and harvest_source_title:
msg = p.toolkit._('Harvested from')
url = h.url_for('harvest_read', id=harvest_source_id)
link = '{msg} <a href="{url}">{title}</a>'.format(url=url, msg=msg, title=harvest_source_title)
harvest_next = asbool(config.get('ckanext.datagovtheme.harvest_next', 'false'))
if type == 'metadata':
url = f"{harvest_admin_url}/harvest_record/{harvest_object_id}/raw"
link = '<a href="{url}">{title}</a>'.format(url=url, title='Download Metadata')
else:
if harvest_next:
url = f"{harvest_admin_url}/harvest_source/{harvest_source_id}"
else:
url = h.url_for('harvest_read', id=harvest_source_id)
link = '{msg} <a href="{url}">{title}</a>'.format(url=url, msg=msg, title=harvest_source_title)
return p.toolkit.literal(link)

return ''
Expand Down Expand Up @@ -679,8 +696,10 @@ def get_pkg_dict_extra(pkg_dict, key, default=None):
if k == key:
return value

harvest_next = asbool(config.get('ckanext.datagovtheme.harvest_next', 'false'))
# Also include harvest information if exists
if key in ['harvest_object_id', 'harvest_source_id', 'harvest_source_title']:
if key in ['harvest_object_id', 'harvest_source_id', 'harvest_source_title'] \
and not harvest_next:

harvest_object = model.Session.query(HarvestObject) \
.filter(HarvestObject.package_id == pkg_dict['id']) \
Expand Down
6 changes: 2 additions & 4 deletions ckanext/datagovtheme/templates/package/read.html
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ <h3>{{ _('Dates') }}</h3>

{% set harvest_object_id = h.get_pkg_dict_extra(pkg, 'harvest_object_id', None) %}
{% if harvest_object_id %}
{% set ho_formats = h.get_harvest_object_formats(harvest_object_id) %}
{% set ho_formats = h.get_harvest_object_formats(harvest_object_id, dataset_is_datajson=dataset_is_datajson) %}
{% if ho_formats.object_format %}
<section id="dataset-metadata-source" class="resources module-content">
<h3>{{ _('Metadata Source') }}</h3>
Expand All @@ -247,9 +247,7 @@ <h3>{{ _('Metadata Source') }}</h3>
{{ ho_formats.object_format }} Metadata
{% endif %}
</strong>
<p class="description">
<a href="/harvest/object/{{ harvest_object_id }}">Download Metadata</a>
</p>
<p class="description">{{ h.get_harvest_source_link(pkg, 'metadata') }}</p>
</li>
{% if ho_formats.original_format %}
<li class="resource-item">
Expand Down
7 changes: 4 additions & 3 deletions ckanext/datagovtheme/templates/package/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</div>

<form id="dataset-search" class="search-form clearfix" method="get" data-module="select-switch">
{% set search_placeholder = 'Search collection...' if request.args.collection_package_id else 'Search datasets...' %}
{% set search_placeholder = 'Search collection...' if request.args.collection_info else 'Search datasets...' %}
<span class="control-group search-giant">
<label for="search-big" class="hide">{{ _('Search datasets') }}</label>
<input id="search-big" type="text" class="search" name="q" value="{{ c.q }}" autocomplete="off" placeholder="{{ search_placeholder }}" onblur="if(value=='') value = 'Search datasets...'" onfocus="if(value=='Search datasets...') value = ''"/>
Expand All @@ -32,7 +32,9 @@
<div class="results">
<div class="filter-list">
{% for field in c.fields_grouped %}
{% if field != 'collection_package_id' %}
{% if field in ['collection_info', 'include_collection'] %}
{% continue %}
{% endif %}
<span class="facet">{{ c.facet_titles.get(field) }}:</span>
{% set search_facets_items = c.search_facets.get(field)['items'] %}
{% for value in c.fields_grouped[field] %}
Expand All @@ -49,7 +51,6 @@
<a href="{{ c.remove_field(field, value) }}" class="remove" title="{{ _('Remove') }}"><i class="fa fa-times"></i></a>
</span>
{% endfor %}
{% endif %}
{% endfor %}
</div>
{% if request.args and c.page.item_count == 0 %}
Expand Down
Loading