Commit 8c1d5291 authored by Merret Buurman's avatar Merret Buurman
Browse files

Added landing page for dataset (first version).

parent 63720ca1
......@@ -156,7 +156,7 @@ def _extract_info_on_one_aggregation_record(handle):
### Parsing dataset handle records
###
def get_drs_from_record(json_record):
def get_drs_name_from_record(json_record):
return get_value_from_record(json_record, 'DRS_ID')
def get_version_number_from_record(json_record):
......@@ -165,6 +165,64 @@ def get_version_number_from_record(json_record):
def get_replaced_by_from_record(json_record):
return get_value_from_record(json_record, 'REPLACED_BY')
def get_hosts_original_from_record(json_record):
field_string = get_value_from_record(json_record, 'HOSTING_NODE')
parsed = _extract_url_info_from_field(field_string, 'host')
return parsed
def get_hosts_replicas_from_record(json_record):
field_string = get_value_from_record(json_record, 'REPLICA_NODE')
parsed = _extract_url_info_from_field(field_string, 'host')
return parsed
def get_list_of_parts_handles_from_record(json_record):
field_string = _get_parts_field_from_record(json_record)
return field_string.split(';')
def get_list_of_parts_records_from_record(list_of_parts_handles):
list_to_be_returned = []
any_replaced = False
for handle in list_of_parts_handles:
info, replaced = _extract_info_on_one_part_record(handle)
list_to_be_returned.append(info)
if replaced:
any_replaced = True
return list_to_be_returned, any_replaced
def _extract_info_on_one_part_record(handle):
# Retrieve handle:
json_record = retrieval.get_handle_record_json(handle)
# Get info:
aggregation_level = get_aggregation_level(json_record)
title = get_title_from_record(json_record)
vers_num = get_version_number_from_record(json_record)
newer_version = get_replaced_by_from_record(json_record)
replaced = False
if newer_version is not None and not newer_version == handle:
replaced = True
# Assemble info:
info_to_return = dict(
handle = handle,
level = aggregation_level,
title = title,
replaced = replaced
)
if vers_num is not None:
info_to_return['version'] = version
return info_to_return, replaced
def _get_parts_field_from_record(json_record):
field_string = get_value_from_record(json_record, 'HAS_PARTS')
if field_string is None:
field_string = get_value_from_record(json_record, 'CHILDREN') # TODO Remove once migration is done!
return field_string
###
### Utils
###
......
from django.template import loader
import xml.etree.ElementTree as ET
import landingpage.handle.cmip6parser as parser
#
# API of this module:
#
def get_context(json_record):
return _get_context(json_record)
def get_template():
return _get_template()
def _get_template():
return loader.get_template('landingpage/cmip6_dataset.html')
#
# Logic of this module:
#
def _get_context(json_record):
context = {}
context['content'] = json_record
context['handle'] = json_record['handle']
context['values'] = parser.get_all_entries_as_dict(json_record)
# drs
val = parser.get_drs_name_from_record(json_record)
if val is not None:
context['drs'] = val
# version number
val = parser.get_version_number_from_record(json_record)
if val is not None:
context['version'] = val
# newer version
val = parser.get_replaced_by_from_record(json_record)
if val is not None:
context['newerversion'] = val
# hosts original
val = parser.get_hosts_original_from_record(json_record)
if val is not None:
context['hosts_original'] = val
# hosts replicas
val = parser.get_hosts_replicas_from_record(json_record)
if val is not None:
context['hosts_replicas'] = val
# Subparts (formerly known as children)
val1 = parser.get_list_of_parts_handles_from_record(json_record)
if val1 is not None:
context['list_of_parts_handles'] = val1
val2,val3 = parser.get_list_of_parts_records_from_record(val1)
if val2 is not None:
context['list_of_parts_records'] = val2
context['any_part_replaced'] = val3
return context
......@@ -2,7 +2,7 @@ from django.template import loader
import requests
import json
import xml.etree.ElementTree as ET
import filelevel
import filelevel, datasetlevel
from landingpage.handle import retrieval, cmip6parser
......@@ -17,7 +17,7 @@ def _get_template_for_aggregation_level(json_record):
if cmip6parser.is_file(json_record):
return filelevel.get_template()
elif cmip6parser.is_dataset(json_record):
return loader.get_template('landingpage/cmip6_dataset.html') # TODO
return datasetlevel.get_template()
else:
return loader.get_template('landingpage/cmip6_fallback.html') # TODO
......@@ -26,7 +26,7 @@ def _get_context_for_aggregation_level(json_record):
if cmip6parser.is_file(json_record):
return filelevel.get_context(json_record)
elif cmip6parser.is_dataset(json_record):
return _get_handle_info_for_dataset(json_record) # TODO
return datasetlevel.get_context(json_record)
else:
return _get_dict_generic(json_record) # TODO
......
{% extends "landingpage/cmip6_headerfooter.html" %}
{% block content %}
<!--
The context object needs the following objects:
Simple values:
* drs
* handle [*]
* version
* newerversion
* any_part_replaced
Complex objects:
* hosts_original: List of dicts. Every dict needs:
* host [*]
* hosts_replicas: List of dicts. Every dict needs:
* host [*]
* list_of_parts_handles: List of strings (handles).
These handles can be retrieved from the dataset handle record, but it is very little information.
The user needs to click on them to know what they are, if they are up-to-date, etc.
Alternative: list_of_parts_records
* list_of_parts_records: List of dicts.
This contains more info, which is extracted from the records of the aggregation handles, so more
calls to retrieve handle records are needed. Maybe one day this could be done on user's request only.
Every dict needs:
* level (e.g. "file") [*]
* handle [*]
* version
* title [*] (can be drs-name, can be file name... depends on the level)
* replaced (True or False) [*]
[*] I do not check the existence of these, so if they don't exist, the page may break.
-->
<div class="section">
{% if drs %}
<h1><em>{{drs}}</em> (dataset)</h1>
{% else %}
<h1>Dataset <em>(DRS name unknown)</em></h1>
{% endif %}
</div>
<div class="section">
<h2>General information</h2>
<table>
{% if drs %}
<tr>
<td id="leftcol">DRS name</td>
<td>{{drs}}</td>
</tr>
{% endif %}
<tr>
<td id="leftcol">Persistent identifier</td>
<td><a href="http://hdl.handle.net/{{handle}}">hdl:{{handle}}</a></td>
</tr>
{% if version %}
<tr>
<td id="leftcol">Version number</td>
<td>{{version}}</td>
</tr>
{% endif %}
{% if newerversion %}
<tr>
<td id="leftcol">Newer version</td>
<td><a href="http://hdl.handle.net/{{handle}}">hdl:{{newerversion}}</a></td>
</tr>
{% endif %}
</table>
</div>
<div class="section">
<h2>Dataset host(s)</h2>
{% if hosts_original or hosts_replica %}
<table>
{% if hosts_original %}
{% for entry in hosts_original %}
<tr>
<td id="leftcol">Hosted by <a href="{{entry.host}}">{{entry.host}}</a></td>
<td></td>
</tr>
{% endfor %}
{% endif %}
{% if hosts_replica %}
{% for entry in hosts_replica %}
<tr>
<td id="leftcol">Mirrored at <a href="{{entry.host}}">{{entry.host}}</a></td>
<td></td>
</tr>
{% endfor %}
{% endif %}
</table>
{% endif %}
</div>
<div class="section">
<h2>Parts</em></h2>
{% if list_of_parts_records %}
<table>
{% for item in list_of_parts_records %}
<tr>
<td id="leftcol">{{item.level}}</td>
<td>
{{ item.title }}
{% if item.version %}
(version {{ item.version }})
{% endif %}
<br/><a href="http://hdl.handle.net/{{ item.handle }}/">hdl:{{ item.handle }}</a>
{% if item.replaced %}
<br/><span class="attention">Attention, this {{item.level}} was replaced by a newer version!*</span>
{% endif %}
</td>
</tr>
{% endfor %}
</table>
{% else %}{% if list_of_parts_handles %}
<table>
{% for handle in list_of_parts_handles %}
<tr><td><a href="http://hdl.handle.net/{{ handle }}/">{{ handle }}</a></td></tr>
{% endfor %}
</table>
{% else %}
<p>No information on parts of this dataset.</p>
{% endif %}{% endif %}
</div>
{% endblock %}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment