diff --git a/main/templates/main/index.html b/main/templates/main/index.html index 1d813967..abf2a515 100644 --- a/main/templates/main/index.html +++ b/main/templates/main/index.html @@ -4,4 +4,26 @@ {% block content %} Welcome to the index page. + + + + + + + + + + + {% for value in values %} + + + + + + + + + {% endfor %} +
uuidnameusersessionstatus codeexit code
{{ value.uuid.uuid }}{{ value.process_description.metadata.name }}{{ value.process_description.metadata.user }}{{ value.process_description.metadata.session }}{{ value.status_code }}{{ value.return_code }}
+ {% endblock content %} diff --git a/main/views.py b/main/views.py index b9156198..f922d8e0 100644 --- a/main/views.py +++ b/main/views.py @@ -1,9 +1,25 @@ """Views for the main app.""" +import asyncio + from django.http import HttpRequest, HttpResponse from django.shortcuts import render +from drunc.process_manager.process_manager_driver import ProcessManagerDriver +from drunc.utils.shell_utils import create_dummy_token_from_uname +from druncschema.process_manager_pb2 import ProcessInstanceList, ProcessQuery + + +async def get_session_info() -> ProcessInstanceList: + """Get info about all sessions from process manager.""" + token = create_dummy_token_from_uname() + pmd = ProcessManagerDriver("drunc:10054", token=token, aio_channel=True) + query = ProcessQuery(names=[".*"]) + return await pmd.ps(query) def index(request: HttpRequest) -> HttpResponse: """View that renders the index/home page.""" - return render(request=request, template_name="main/index.html") + val = asyncio.run(get_session_info()) + context = {"values": val.data.values} + + return render(request=request, context=context, template_name="main/index.html") diff --git a/tests/test_views.py b/tests/test_views.py index da30fdc1..d35094c3 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -1,8 +1,9 @@ from pytest_django.asserts import assertTemplateUsed -def test_index(client, admin_client): +def test_index(client, admin_client, mocker): """Test the index view.""" + mocker.patch("main.views.get_session_info") with assertTemplateUsed(template_name="main/index.html"): response = client.get("/") assert response.status_code == 200