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

Fixes for Issue #58 #60

Merged
merged 4 commits into from
Sep 26, 2024
Merged
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
12 changes: 12 additions & 0 deletions cernopendata/modules/records/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import json
from re import sub
import six
import itertools

from flask import abort, current_app, jsonify, render_template, request
from invenio_files_rest.views import ObjectResource
from invenio_records.api import Record
Expand Down Expand Up @@ -188,6 +190,16 @@ def record_metadata_view(pid, record, template=None):
collection = ""
if len(record.get("collections", [])) > 0:
collection = record.get("collections", [])[0]

# Fix issue 58 → sort headers beforehand and check all fields
if semantics := record.get("dataset_semantics"):
# dynamically check all fields for used keys
headers = set(itertools.chain(*semantics))
optional = headers.difference(["variable", "type", "description"])

# ensure headers are in the correct order including custom types
record["dataset_semantics_header"] = ["variable", "type"] + sorted(optional) + ["description"]

return render_template(
[
"cernopendata_records_ui/records/record_detail_{}.html".format(collection),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ <h2>Dataset semantics</h2>
<table class="ui table striped">
<thead>
<tr>
{% for col in record.dataset_semantics[0] %}
{% for col in record.dataset_semantics_header %}
<th>{{ col | capitalize }}</th>
{% endfor %}
</tr>
Expand All @@ -256,6 +256,9 @@ <h2>Dataset semantics</h2>
{% if semantic.type %}
<td><em>{{semantic.type}}</em></td>
{% endif %}
{% for other_var in record.dataset_semantics_header[2:-1] %}
<td><span>{{semantic[other_var]}}</span></td>
{% endfor %}
<td><span>{{semantic.description | safe}}</span></td>
</tr>
{% endfor %}
Expand Down
Loading