aboutsummaryrefslogtreecommitdiffstats
path: root/pydis_site/apps/staff
diff options
context:
space:
mode:
Diffstat (limited to 'pydis_site/apps/staff')
-rw-r--r--pydis_site/apps/staff/README.md19
-rw-r--r--pydis_site/apps/staff/apps.py2
-rw-r--r--pydis_site/apps/staff/templatetags/deletedmessage_filters.py11
-rw-r--r--pydis_site/apps/staff/tests/test_deletedmessage_filters.py2
-rw-r--r--pydis_site/apps/staff/tests/test_logs_view.py12
-rw-r--r--pydis_site/apps/staff/urls.py2
-rw-r--r--pydis_site/apps/staff/views.py (renamed from pydis_site/apps/staff/viewsets/logs.py)0
-rw-r--r--pydis_site/apps/staff/viewsets/__init__.py3
8 files changed, 40 insertions, 11 deletions
diff --git a/pydis_site/apps/staff/README.md b/pydis_site/apps/staff/README.md
new file mode 100644
index 00000000..6707bf26
--- /dev/null
+++ b/pydis_site/apps/staff/README.md
@@ -0,0 +1,19 @@
+# The "staff" app
+
+This Django application hosts any staff-internal tooling, which, at time of
+writing, is only an endpoint to view logs uploaded by the Python bot.
+
+This app mainly interacts with a single model from the `api` app, and has no
+models on its own. The following files and directories are of interest:
+
+- [`templatetags`](./templatetags) contains custom template tags that help with
+ formatting the HTML templates of this app (these can be found in the template
+ root direcetory).
+
+- [`tests`](./tests) contains standard Django unit tests that validate both the
+ template tags and functionality of the log viewer itself.
+
+- [`urls.py`](./urls.py) contains the regular Django URL routing logic.
+
+- [`views.py`](./views.py) contains standard Django views. In our case, the
+ main work happens in the template, so this is relatively straightforward.
diff --git a/pydis_site/apps/staff/apps.py b/pydis_site/apps/staff/apps.py
index 70a15f40..d68a80c3 100644
--- a/pydis_site/apps/staff/apps.py
+++ b/pydis_site/apps/staff/apps.py
@@ -4,4 +4,4 @@ from django.apps import AppConfig
class StaffConfig(AppConfig):
"""Django AppConfig for the staff app."""
- name = 'staff'
+ name = 'pydis_site.apps.staff'
diff --git a/pydis_site/apps/staff/templatetags/deletedmessage_filters.py b/pydis_site/apps/staff/templatetags/deletedmessage_filters.py
index 8e14ced6..c6638a3b 100644
--- a/pydis_site/apps/staff/templatetags/deletedmessage_filters.py
+++ b/pydis_site/apps/staff/templatetags/deletedmessage_filters.py
@@ -6,13 +6,16 @@ register = template.Library()
@register.filter
-def hex_colour(color: int) -> str:
+def hex_colour(colour: str | int) -> str:
"""
- Converts an integer representation of a colour to the RGB hex value.
+ Converts the given representation of a colour to its RGB hex string.
As we are using a Discord dark theme analogue, black colours are returned as white instead.
"""
- colour = f"#{color:0>6X}"
+ if isinstance(colour, str):
+ colour = colour if colour.startswith("#") else f"#{colour}"
+ else:
+ colour = f"#{colour:0>6X}"
return colour if colour != "#000000" else "#FFFFFF"
@@ -24,5 +27,5 @@ def footer_datetime(timestamp: str) -> datetime:
@register.filter
def visible_newlines(text: str) -> str:
- """Takes an embed timestamp and returns a timezone-aware datetime object."""
+ """Visualizes newlines in text by replacing them with a grey-ish `↵`."""
return text.replace("\n", " <span class='has-text-grey'>↵</span><br>")
diff --git a/pydis_site/apps/staff/tests/test_deletedmessage_filters.py b/pydis_site/apps/staff/tests/test_deletedmessage_filters.py
index 31215784..5e49f103 100644
--- a/pydis_site/apps/staff/tests/test_deletedmessage_filters.py
+++ b/pydis_site/apps/staff/tests/test_deletedmessage_filters.py
@@ -3,7 +3,7 @@ import enum
from django.test import TestCase
from django.utils import timezone
-from ..templatetags import deletedmessage_filters
+from pydis_site.apps.staff.templatetags import deletedmessage_filters
class Colour(enum.IntEnum):
diff --git a/pydis_site/apps/staff/tests/test_logs_view.py b/pydis_site/apps/staff/tests/test_logs_view.py
index 45e9ce8f..3e5726cd 100644
--- a/pydis_site/apps/staff/tests/test_logs_view.py
+++ b/pydis_site/apps/staff/tests/test_logs_view.py
@@ -95,12 +95,22 @@ class TestLogsView(TestCase):
"description": "This embed is way too cool to be seen in public channels.",
}
+ cls.embed_three = {
+ "description": "This embed is way too cool to be seen in public channels.",
+ "color": "#e74c3c",
+ }
+
+ cls.embed_four = {
+ "description": "This embed is way too cool to be seen in public channels.",
+ "color": "e74c3c",
+ }
+
cls.deleted_message_two = DeletedMessage.objects.create(
author=cls.author,
id=614444836291870750,
channel_id=1984,
content='Does that mean this thing will halt?',
- embeds=[cls.embed_one, cls.embed_two],
+ embeds=[cls.embed_one, cls.embed_two, cls.embed_three, cls.embed_four],
attachments=['https://http.cat/100', 'https://http.cat/402'],
deletion_context=cls.deletion_context,
)
diff --git a/pydis_site/apps/staff/urls.py b/pydis_site/apps/staff/urls.py
index ca8d1a0f..0565592b 100644
--- a/pydis_site/apps/staff/urls.py
+++ b/pydis_site/apps/staff/urls.py
@@ -1,6 +1,6 @@
from django.urls import path
-from .viewsets import LogView
+from .views import LogView
app_name = 'staff'
urlpatterns = [
diff --git a/pydis_site/apps/staff/viewsets/logs.py b/pydis_site/apps/staff/views.py
index 22dede95..22dede95 100644
--- a/pydis_site/apps/staff/viewsets/logs.py
+++ b/pydis_site/apps/staff/views.py
diff --git a/pydis_site/apps/staff/viewsets/__init__.py b/pydis_site/apps/staff/viewsets/__init__.py
deleted file mode 100644
index 6b10eb83..00000000
--- a/pydis_site/apps/staff/viewsets/__init__.py
+++ /dev/null
@@ -1,3 +0,0 @@
-from .logs import LogView
-
-__all__ = ["LogView"]