Skip to content

Commit

Permalink
add button to open full csw record in FIS-broker
Browse files Browse the repository at this point in the history
  • Loading branch information
knudmoeller committed Feb 12, 2024
1 parent ca76211 commit 12a4f1a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Development

- Add a button to open full CSW record in FIS-Broker.

## [1.4.3](https://github.com/berlinonline/ckanext-fisbroker/releases/tag/1.4.3)

_(2024-02-01)_
Expand Down
29 changes: 28 additions & 1 deletion ckanext/fisbroker/blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import logging
from urllib3.exceptions import ProtocolError

from flask import Blueprint, make_response
from flask import Blueprint, make_response, redirect

# from ckan.common import OrderedDict, _, c, request, response, config
from ckan import model
Expand Down Expand Up @@ -76,6 +76,31 @@ def get_error_dict(error_code):
# environ['pylons.status_code_redirect'] = True
# return base.BaseController.__call__(self, environ, start_response)

def open_csw_record(package_id):
'''Open the full CSW record for `package_id`.'''

package = Package.get(package_id)

if not package:
raise PackageIdDoesNotExistError(package_id)

if not dataset_was_harvested(package):
raise PackageNotHarvestedError(package_id)

harvester = harvester_for_package(package)
harvester_url = harvester.url
harvester_type = harvester.type
if not harvester_type == HARVESTER_ID:
raise PackageNotHarvestedInFisbrokerError(package_id)

fb_guid = fisbroker_guid(package)
if not fb_guid:
raise NoFisbrokerIdError(package_id)

url = f"{harvester_url}/?service=CSW&version=2.0.2&request=GetRecordById&outputschema=http://www.isotc211.org/2005/gmd&elementsetname=full&ID={fb_guid}"

return redirect(url, code=307)

def reimport_through_browser(package_id):
'''Initiate the reimport action through the browser (signified by
the use of a /dataset/{name}/reimport pattern URL).'''
Expand Down Expand Up @@ -299,3 +324,5 @@ def _finish(status_int, response_data=None, direct_call=False):
methods=['GET', 'POST'], view_func=reimport_through_api)
reimportapi.add_url_rule(u'/dataset/<package_id>/reimport',
methods=['GET'], view_func=reimport_through_browser)
reimportapi.add_url_rule(u'/dataset/<package_id>/csw_record',
methods=['GET'], view_func=open_csw_record)
2 changes: 2 additions & 0 deletions ckanext/fisbroker/theme/templates/package/read_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
{% set package_object = h.berlin_package_object(pkg) %}
{% if h.check_access('package_update', {'id':pkg.id }) and h.berlin_is_fisbroker_package(package_object) %}
{% if h.berlin_fisbroker_guid(package_object) %}
<a class="btn btn-default" href="{{ url_for('reimportapi.open_csw_record', package_id=pkg.id) }}" target="_blank"><i
class="fa fa-external-link"></i> Open CSW record</a>
{% link_for _('Reimport'), named_route='reimportapi.reimport_through_browser', package_id=pkg.id, class_='btn btn-default', icon='cloud-download' %}
{% endif %}
{% endif %}
Expand Down

0 comments on commit 12a4f1a

Please sign in to comment.