Skip to content

Commit

Permalink
fix import and add api version to info screen
Browse files Browse the repository at this point in the history
  • Loading branch information
vanatteveldt committed Aug 30, 2023
1 parent 260a422 commit eb5dc87
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 66 deletions.
5 changes: 3 additions & 2 deletions amcat4/api/info.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from fastapi import Request
from fastapi import APIRouter
from fastapi.templating import Jinja2Templates
from importlib.metadata import version

from amcat4 import elastic
from amcat4.api.auth import get_middlecat_config
from amcat4.config import get_settings

templates = Jinja2Templates(directory="templates")

app_info = APIRouter(
tags=["informational"])
app_info = APIRouter(tags=["informational"])


@app_info.get("/")
Expand All @@ -20,6 +20,7 @@ def index(request: Request):
has_admin_email = bool(get_settings().admin_email)
middlecat_url = get_settings().middlecat_url
middlecat_alive = False
api_version = version("amcat4")
if middlecat_url:
try:
get_middlecat_config(middlecat_url)
Expand Down
23 changes: 10 additions & 13 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,18 @@
"pydantic[email]",
"pydantic-settings",
"typing_extensions",
'uvicorn',
'requests'
"uvicorn",
"requests",
"class_doc",
],
extras_require={
'dev': [
'pytest',
'mypy',
'flake8',
'responses',
'pre-commit',
]
},
entry_points={
'console_scripts': [
'amcat4 = amcat4.__main__:main'
"dev": [
"pytest",
"mypy",
"flake8",
"responses",
"pre-commit",
]
},
entry_points={"console_scripts": ["amcat4 = amcat4.__main__:main"]},
)
106 changes: 55 additions & 51 deletions templates/index.html
Original file line number Diff line number Diff line change
@@ -1,98 +1,102 @@
<html>
<link href='https://fonts.googleapis.com/css?family=Poppins' rel='stylesheet'>
<style>
<link href="https://fonts.googleapis.com/css?family=Poppins" rel="stylesheet" />
<style>
body {
text-align: center;
font-family: 'Poppins';
text-align: center;
font-family: "Poppins";
}

.header {
background-color: black
background-color: black;
}

.header h1 {
color: white
color: white;
}

.header h2 {
color: teal
color: teal;
}

.header a {
color: white
color: white;
}

table {
text-align: left;
margin-left: auto;
margin-right: auto;
text-align: left;
margin-left: auto;
margin-right: auto;
}

.good {
color: darkgreen
color: darkgreen;
}

.bad {
color: darkred
color: darkred;
}

a {
color: teal
color: teal;
}

b {
color: teal
color: teal;
}
</style>
<body>
<div class="header">
<h1>AmCAT4 API</h1>
<h2>API Documentation: <a href="redoc">[redoc]</a> | <a href="docs">[docs]</a></h2>
</div>
</style>
<body>
<div class="header">
<h1>AmCAT4 API <small style="color: grey"> {{ api_version }}</small></h1>
<h2>API Documentation: <a href="redoc">[redoc]</a> | <a href="docs">[docs]</a></h2>
</div>

<h1>Settings</h1>
Note: To change settings, add environment variables to the API worker process and/or in a .env file in the working
directory. <br/>
<a href="https://github.com/ccs-amsterdam/amcat4/tree/main/.env.example">Example .env file</a>
<p>
<b>Settings summary:</b>
<table class="center">
<h1>Settings</h1>
Note: To change settings, add environment variables to the API worker process and/or in a .env file in the working
directory. <br />
<a href="https://github.com/ccs-amsterdam/amcat4/tree/main/.env.example">Example .env file</a>
<p>
<b>Settings summary:</b>
</p>

<tr>
<table class="center">
<tr>
<th>Host:</th>
<td>{{ host }}</td>
</tr>
<tr>
</tr>
<tr>
<th>Elasticsearch:</th>
<td>{% if es_alive %}<span class="good">Connected</span>{% else %}<span class="bad">Not Connected</span>{%endif%}
<td>
{% if es_alive %}<span class="good">Connected</span>{% else %}<span class="bad">Not Connected</span>{%endif%}
</td>
</tr>
<tr>
</tr>
<tr>
<th>Authorization mode:</th>
<td>
<span class="{% if auth == 'no_auth'%}bad{%else%}good{%endif%}">
{{auth.name}}: {{ auth.__doc__ }}
</span>
<span class="{% if auth == 'no_auth'%}bad{%else%}good{%endif%}"> {{auth.name}}: {{ auth.__doc__ }} </span>
</td>
</tr>
<tr>
</tr>
<tr>
<th>Middlecat:</th>
<td>{% if middlecat_alive %}<span class="good">Connected</span>{% else %}<span class="bad">Not Connected</span>{%endif%}
<td>
{% if middlecat_alive %}<span class="good">Connected</span>{% else %}<span class="bad">Not Connected</span
>{%endif%}
</td>
</tr>
<tr>
</tr>
<tr>
<th>Middlecat url:</th>
<td>
{% if middlecat_url %}<a href="{{middlecat_url}}">{{middlecat_url}}</a>
{% else %}<span class="bad">Not set up</span>
{% endif %}
{% if middlecat_url %}<a href="{{middlecat_url}}">{{middlecat_url}}</a> {% else %}<span class="bad"
>Not set up</span
>
{% endif %}
</td>
</tr>
<tr>
</tr>
<tr>
<th>Admin email:<span title="Note: Email needs to be authenticated using middlecat">[i]</span></th>
<td>{% if has_admin_email %}<span class="good">Setup</span>{% else %}<span class="bad">Not set up</span>{%endif%}
<td>
{% if has_admin_email %}<span class="good">Setup</span>{% else %}<span class="bad">Not set up</span>{%endif%}
</td>
</tr>
</table>
</body>
</tr>
</table>
</body>
</html>

0 comments on commit eb5dc87

Please sign in to comment.