-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into Health-RI-healthdcat_ap
- Loading branch information
Showing
16 changed files
with
118 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
""" | ||
Helpers used by templates | ||
""" | ||
import simplejson as json | ||
|
||
import ckantoolkit as toolkit | ||
|
||
from ckanext.dcat.processors import RDFSerializer | ||
|
||
config = toolkit.config | ||
|
||
|
||
ENABLE_RDF_ENDPOINTS_CONFIG = "ckanext.dcat.enable_rdf_endpoints" | ||
|
||
|
||
def endpoints_enabled(): | ||
return toolkit.asbool(config.get(ENABLE_RDF_ENDPOINTS_CONFIG, True)) | ||
|
||
|
||
def get_endpoint(_type="dataset"): | ||
return "dcat.read_dataset" if _type == "dataset" else "dcat.read_catalog" | ||
|
||
|
||
def structured_data(dataset_dict, profiles=None, _format="jsonld"): | ||
""" | ||
Returns a string containing the structured data of the given | ||
dataset id and using the given profiles (if no profiles are supplied | ||
the default profiles are used). | ||
This string can be used in the frontend. | ||
""" | ||
|
||
if not profiles: | ||
profiles = ["schemaorg"] | ||
|
||
serializer = RDFSerializer(profiles=profiles) | ||
|
||
output = serializer.serialize_dataset(dataset_dict, _format=_format) | ||
|
||
# parse result again to prevent UnicodeDecodeError and add formatting | ||
try: | ||
json_data = json.loads(output) | ||
return json.dumps( | ||
json_data, | ||
sort_keys=True, | ||
indent=4, | ||
separators=(",", ": "), | ||
cls=json.JSONEncoderForHTML, | ||
) | ||
except ValueError: | ||
# result was not JSON, return anyway | ||
return output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 13 additions & 0 deletions
13
ckanext/dcat/templates/structured_data/package/read_base.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{% ckan_extends %} | ||
|
||
{% block scripts %} | ||
|
||
{{ super() }} | ||
|
||
{% block structured_data %} | ||
<!-- Structured data --> | ||
<script type="application/ld+json"> | ||
{{ h.structured_data(pkg) | safe }} | ||
</script> | ||
{% endblock %} | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
As part of the CKAN ecosystem, ckanext-dcat is entirely open source and welcomes all forms of contributions from the community. | ||
Besides the general guidance provided in the [CKAN documentation](https://docs.ckan.org/en/latest/contributing/index.html) follow these points: | ||
|
||
* Format your code with [Black](https://github.com/psf/black). | ||
* Make sure to include tests for your changes. The extension has an extensive test suite so in most cases you just need to copy some of the existing tests and adapt them. | ||
* It's better to submit a pull request early, even if in draft state, to get feedback and make sure the contribution will be accepted. | ||
|
||
### Including new profiles | ||
|
||
|
||
New [profiles](profiles.md) that are useful to the wider community are welcome, provided that they are sustainable long term. A maintainer unfamiliar with the profile should be able to know what the profile does and be confident that everything works as expected. The way to achieve this is with tests (lots of them!) and documentation. | ||
|
||
More localized profiles are better placed in dedicated extensions. | ||
|
||
A contribution that adds a new profile should include: | ||
|
||
* A new [profile class](https://github.com/ckan/ckanext-dcat/tree/master/ckanext/dcat/profiles) with parse and serialize methods (extending the DCAT v3 one) | ||
* A new dataset [schema](https://github.com/ckan/ckanext-dcat/tree/master/ckanext/dcat/schemas) that contains all new properties supported in the new profile (it can contain just the base DCAT 3 recommended ones) | ||
* [Example](https://github.com/ckan/ckanext-dcat/tree/master/examples) CKAN dataset and DCAT serialization of the new profile | ||
* Tests: | ||
* [SHACL validation](https://github.com/ckan/ckanext-dcat/tree/1e945b6e79f0e0bae1ff76989ef9789abb5e32a8/ckanext/dcat/tests/shacl) if SHACL shapes are provided | ||
* [End to end](https://github.com/ckan/ckanext-dcat/blob/1e945b6e79f0e0bae1ff76989ef9789abb5e32a8/ckanext/dcat/tests/profiles/dcat_ap_3/test_euro_dcatap_3_profile_serialize.py#L44) tests covering parsing and serialization | ||
* Parsing and serialization tests covering [specific functionality](https://github.com/ckan/ckanext-dcat/blob/1e945b6e79f0e0bae1ff76989ef9789abb5e32a8/ckanext/dcat/tests/profiles/dcat_ap_3/test_euro_dcatap_3_profile_serialize.py#L368) for the profile | ||
* [Documentation](https://github.com/ckan/ckanext-dcat/tree/1e945b6e79f0e0bae1ff76989ef9789abb5e32a8/docs) about the new profile (compatibility with DCAT AP versions, other profiles required, config options etc) | ||
|
||
This might seem like a lot of requirements but using the existing linked resources as template should make things much easier. Do not hesitate to ask for help if unsure about one point. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters