Skip to content

Commit

Permalink
Merge pull request #37 from ImperialCollegeLondon/index-process-data
Browse files Browse the repository at this point in the history
Adding process data to index view
  • Loading branch information
TinyMarsh authored Aug 28, 2024
2 parents 5820da7 + f6defa4 commit 18f7f0b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
22 changes: 22 additions & 0 deletions main/templates/main/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,26 @@

{% block content %}
Welcome to the index page.

<table border="1">
<tr>
<th>uuid</th>
<th>name</th>
<th>user</th>
<th>session</th>
<th>status code</th>
<th>exit code</th>
</tr>
{% for value in values %}
<tr>
<td>{{ value.uuid.uuid }}</td>
<td>{{ value.process_description.metadata.name }}</td>
<td>{{ value.process_description.metadata.user }}</td>
<td>{{ value.process_description.metadata.session }}</td>
<td>{{ value.status_code }}</td>
<td>{{ value.return_code }}</td>
</tr>
{% endfor %}
</table>

{% endblock content %}
18 changes: 17 additions & 1 deletion main/views.py
Original file line number Diff line number Diff line change
@@ -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")
3 changes: 2 additions & 1 deletion tests/test_views.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 18f7f0b

Please sign in to comment.