Skip to content

Commit

Permalink
Merge pull request #22 from adinhodovic/add-wait
Browse files Browse the repository at this point in the history
fix: color for favorite button
  • Loading branch information
adinhodovic committed Feb 28, 2024
2 parents c60c7d1 + 7b025b6 commit bde8d50
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 66 deletions.
14 changes: 6 additions & 8 deletions django_admin_shellx/templates/django_admin_shellx/terminal.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,25 @@
<link rel="stylesheet"
href="{% static 'django_admin_shellx/output/terminal.css' %}" />
{% endblock extrastyle %}

{% block extrahead %}
{{ block.super }}
{{ ws_port|json_script:"ws_port" }}
<script src="https://unpkg.com/htmx.org@1.9.10"></script>
<script src="https://unpkg.com/htmx.org/dist/ext/class-tools.js"></script>
<script type="module"
src="{% static 'django_admin_shellx/output/terminal.js' %}"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha512-DTOQO9RWCH3ppGqcWaEA1BIZOC6xxalwEsw9c2QQeAIftl+Vegovlnee1c9QX4TctnWMn13TZye+giMm8e2LwA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css"
integrity="sha512-DTOQO9RWCH3ppGqcWaEA1BIZOC6xxalwEsw9c2QQeAIftl+Vegovlnee1c9QX4TctnWMn13TZye+giMm8e2LwA=="
crossorigin="anonymous"
referrerpolicy="no-referrer" />
{% endblock extrahead %}

{% block bodyclass %}
{{ block.super }} dashboard
{% endblock bodyclass %}

{% block nav-breadcrumbs %}
{% endblock nav-breadcrumbs %}

{% block nav-sidebar %}
{% endblock nav-sidebar %}

{% block content %}
{{ block.super }}
<div class="flex justify-center">
Expand Down Expand Up @@ -127,7 +125,7 @@
<input name="favorite" type="checkbox" class="toggle toggle-sm" />
</div>
</div>
<input type="text" hidden onkeypress="return event.keyCode!=13"/>
<input type="text" hidden onkeypress="return event.keyCode!=13" />
</form>
<table id="djw_command_history_table" class="table table-sm mt-7">
{% include "django_admin_shellx/terminal_table.html" %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
hx-get="{% url 'admin:django_admin_shellx_terminalcommand_toggle_favorite' pk=command.id %}"
hx-swap="innerHTML">
<div class="tooltip" data-tip="Favorite Command">
<i id="djw_favorite_icon"
class="fa fa-star {% if command.favorite %}text-yellow-400{% endif %}"></i>
<i class="fa fa-star {% if command.favorite %}text-yellow-400{% endif %}"></i>
</div>
</button>
</div>
Expand Down
4 changes: 2 additions & 2 deletions django_admin_shellx/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ def toggle_favorite(request, pk):
instance.favorite = not instance.favorite
instance.save()

color = "text-yellow-500" if instance.favorite else ""
color = "text-yellow-400" if instance.favorite else ""
return HttpResponse(
format_html( # pyright: ignore [reportArgumentType]
"<div class='tooltip' data-tip='Favorite Command'><i id='djw_favorite_icon' class='fa fa-star {}'></i></div>",
"<div class='tooltip' data-tip='Favorite Command'><i class='fa fa-star {}'></i></div>",
mark_safe(color),
)
)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "django-admin-shellx"
version = "0.2.1"
version = "0.2.2"
description = "A Django Admin Shell"
authors = ["Adin Hodovic <hodovicadin@gmail.com>"]
license = "MIT"
Expand Down
41 changes: 0 additions & 41 deletions tests/templates/tests/custom_resume_page.html

This file was deleted.

7 changes: 4 additions & 3 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
from asyncio import sleep
from asyncio.exceptions import CancelledError

import pytest
Expand Down Expand Up @@ -68,8 +69,8 @@ async def test_closes_connection_on_exit(settings, superuser_logged_in):
response = await communicator.receive_from()
assert response == '{"message": "exit"}'

# Wait 5 seconds for the shell to close
await communicator.wait(1)
# Wait for the shell to close
await communicator.wait()

await communicator.send_to(
text_data=json.dumps({"action": "input", "data": {"message": "ls"}})
Expand Down Expand Up @@ -144,7 +145,7 @@ async def test_command_increments_execution_count(settings, superuser_logged_in)
# Test sending text
await communicator.send_to(text_data=json_data)
await communicator.send_to(text_data=json_data)
await communicator.wait(1)
await sleep(1)

log_entry_count, _ = await get_log_entry()
terminal_command_count, terminal_command = await get_terminal_command()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def test_toggle_favorite(admin_client):
)

assert res.status_code == 200
assert "text-yellow-500" in str(res.content)
assert "text-yellow-400" in str(res.content)
tc.refresh_from_db()
assert tc.favorite

Expand Down
12 changes: 4 additions & 8 deletions tests/test_websockets.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
from asyncio import sleep

import pytest

Expand Down Expand Up @@ -72,21 +73,16 @@ async def test_websocket_send_command(settings, superuser_logged_in):
await communicator.send_to(
text_data=json.dumps({"action": "input", "data": {"message": "ls\r"}})
)
await sleep(2)

# Responses can go in multiple messages, so we need to wait for all of them
# Expecting 4 messages from shell
response = await communicator.receive_from()
response += await communicator.receive_from()
# TODO(adinhodovic): This is a hack, we should wait for the response to be complete, which is
# tricky due to terminal output
try:
response += await communicator.receive_from()
except TimeoutError:
pass
try:
response += await communicator.receive_from()
except TimeoutError:
pass
response += await communicator.receive_from()
response += await communicator.receive_from()

assert "LICENSE" in response

Expand Down

0 comments on commit bde8d50

Please sign in to comment.