Skip to content

Commit

Permalink
optional ckanext.datagovtheme.harvest_next for catalog-next
Browse files Browse the repository at this point in the history
  • Loading branch information
FuhuXia committed Jul 8, 2024
1 parent 42dce54 commit e840772
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
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
19 changes: 16 additions & 3 deletions ckanext/datagovtheme/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,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 @@ -325,7 +332,11 @@ def get_harvest_source_link(package_dict):

if harvest_source_id and harvest_source_title:
msg = p.toolkit._('Harvested from')
url = h.url_for('harvest_read', id=harvest_source_id)
harvest_next = asbool(config.get('ckanext.datagovtheme.harvest_next', 'false'))
if harvest_next:
url = h.url_for(f'/harvest/{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)

Expand Down Expand Up @@ -683,8 +694,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
2 changes: 1 addition & 1 deletion 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 Down

0 comments on commit e840772

Please sign in to comment.