Skip to content

Commit

Permalink
Merge pull request #213 from GSA/modify-metadata-source-links
Browse files Browse the repository at this point in the history
Modify metadata source links
  • Loading branch information
Jin-Sun-tts authored Nov 6, 2024
2 parents e840772 + 84efd63 commit 56f89f5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
16 changes: 11 additions & 5 deletions ckanext/datagovtheme/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,18 +326,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')
harvest_next = asbool(config.get('ckanext.datagovtheme.harvest_next', 'false'))
if harvest_next:
url = h.url_for(f'/harvest/{harvest_source_id}')
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:
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)
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
4 changes: 1 addition & 3 deletions ckanext/datagovtheme/templates/package/read.html
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ lxml>=2.3
argparse
pyparsing>=2.1.10
requests>=1.1.0
pyproj
pyproj==3.6.1
Shapely==2.0.1
numpy==1.26.4
OWSLib==0.28.1

0 comments on commit 56f89f5

Please sign in to comment.