-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #172 from Materials-Consortia/ml-evs/add_landing_page
Add human-readable landing page at base URLs. New dependency: `Jinja2`.
- Loading branch information
Showing
13 changed files
with
116 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ pymongo==3.10.1 | |
mongomock==3.19.0 | ||
django==2.2.10 | ||
elasticsearch-dsl==6.4.0 | ||
Jinja2==2.11.1 |
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 |
---|---|---|
|
@@ -7,3 +7,4 @@ pymongo | |
mongomock | ||
django | ||
elasticsearch_dsl | ||
Jinja2 |
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
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,40 @@ | ||
""" OPTiMaDe landing page, rendered as a Jinja2 template. """ | ||
|
||
from starlette.routing import Router, Route | ||
from optimade import __api_version__ | ||
from pathlib import Path | ||
from starlette.templating import Jinja2Templates | ||
|
||
from . import ENTRY_COLLECTIONS | ||
from .utils import meta_values | ||
|
||
template_dir = Path(__file__).parent.joinpath("static").resolve() | ||
TEMPLATES = Jinja2Templates(directory=[template_dir]) | ||
|
||
|
||
async def landing(request): | ||
""" Show a human-readable landing page when the base URL is accessed. """ | ||
|
||
meta = meta_values(str(request.url), 1, 1, more_data_available=False) | ||
|
||
major_version = __api_version__.split(".")[0] | ||
versioned_url = ( | ||
f"{request.url}" | ||
if f"v{major_version}" in f"{request.url.path}" | ||
else f"{request.url}v{major_version}/" | ||
) | ||
|
||
context = { | ||
"request": request, | ||
"request_url": request.url, | ||
"api_version": __api_version__, | ||
"implementation": meta.implementation, | ||
"versioned_url": versioned_url, | ||
"provider": meta.provider, | ||
"endpoints": list(ENTRY_COLLECTIONS.keys()) + ["info"], | ||
} | ||
|
||
return TEMPLATES.TemplateResponse("landing_page.html", context) | ||
|
||
|
||
router = Router(routes=[Route("/", endpoint=landing)]) |
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,49 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
{% block head %} | ||
<title>{{ optimade_title }}</title> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<meta name="keywords" content="optimade,materials,crystals,database"> | ||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> | ||
{% endblock %} | ||
|
||
<style> | ||
html { margin: 2em; } | ||
h4, p { margin-left: 2em; } | ||
span.version {background-color: lightgrey; font-weight: bold; font-family: monospace; padding: 0em 0.5em 0em 0.5em; border-radius: 1em;} | ||
</style> | ||
</head> | ||
<body> | ||
<img id="logo" width="100" src="https://avatars0.githubusercontent.com/u/23107754?s=400&u=e1580af496ac195a3ac4c445a66a5699efb0c3d3"></img> | ||
<h3>This is an <a href="https://www.optimade.org">OPTiMaDe</a> base URL which can be queried with an OPTiMaDe client.</h3> | ||
<h3>OPTiMaDe version:</h3> | ||
<h3><span class="version">{{ api_version }}</span></h3> | ||
<h3>Provider:</h3> | ||
<h4>{{ provider.name }}</h4> | ||
<p> Prefix: <span class="version">{{ provider.prefix }}</span></p> | ||
<p> {{ provider.description }} </p> | ||
<p><a href={{provider.homepage}}>{{ provider.homepage }}</a></p> | ||
<h3>Implementation:</h3> | ||
<h4>{{ implementation.name }}</h4> | ||
<p>Version: <span class="version">{{ implementation.version }}</span></p> | ||
<p><a href={{ implementation.source_url }}>{{ implementation.source_url }}</a></p> | ||
<h3>Available endpoints:</h3> | ||
<ul> | ||
{% for endpoint in endpoints %} | ||
{{ '<li><a href="{}{}">{}{}</a></li>'.format(versioned_url, endpoint, versioned_url, endpoint) | safe }} | ||
{% endfor %} | ||
</ul> | ||
<h3>Index base URL:</h3> | ||
<p><a href={{ provider.index_base_url }}>{{ provider.index_base_url }}</a></p> | ||
</body> | ||
<footer> | ||
<div class="footer_text"> | ||
<ul style="list-style-type: none; margin: 0; padding:0; overflow: hidden"> | ||
<li style="padding-top: 5px;">Compliant with the <i class="fa fa-github"></i> <a href="https://github.com/Materials-Consortia/OPTiMaDe">OPTiMaDe specification</a>.</li> | ||
<li style="padding-top: 5px;">Powered by <i class="fa fa-github"></i> <a href="https://www.github.com/Materials-Consortia/optimade-python-tools">Materials-Consortia/optimade-python-tools</a></li> | ||
</ul> | ||
</div> | ||
</footer> | ||
</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
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