diff options
Diffstat (limited to 'pydis_site/apps/staff')
-rw-r--r-- | pydis_site/apps/staff/apps.py | 2 | ||||
-rw-r--r-- | pydis_site/apps/staff/templatetags/__init__.py | 3 | ||||
-rw-r--r-- | pydis_site/apps/staff/templatetags/deletedmessage_filters.py | 17 | ||||
-rw-r--r-- | pydis_site/apps/staff/urls.py | 4 | ||||
-rw-r--r-- | pydis_site/apps/staff/viewsets/__init__.py | 2 | ||||
-rw-r--r-- | pydis_site/apps/staff/viewsets/logs.py | 20 |
6 files changed, 42 insertions, 6 deletions
diff --git a/pydis_site/apps/staff/apps.py b/pydis_site/apps/staff/apps.py index fb8bda03..70a15f40 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'
\ No newline at end of file + name = 'staff' diff --git a/pydis_site/apps/staff/templatetags/__init__.py b/pydis_site/apps/staff/templatetags/__init__.py new file mode 100644 index 00000000..e8b6983a --- /dev/null +++ b/pydis_site/apps/staff/templatetags/__init__.py @@ -0,0 +1,3 @@ +from .deletedmessage_filters import footer_datetime, hex_colour + +__all__ = ["hex_colour", "footer_datetime"] diff --git a/pydis_site/apps/staff/templatetags/deletedmessage_filters.py b/pydis_site/apps/staff/templatetags/deletedmessage_filters.py new file mode 100644 index 00000000..f950870f --- /dev/null +++ b/pydis_site/apps/staff/templatetags/deletedmessage_filters.py @@ -0,0 +1,17 @@ +from datetime import datetime + +from django import template + +register = template.Library() + + +def hex_colour(color: int) -> str: + """Converts an integer representation of a colour to the RGB hex value.""" + return f"#{color:0>6X}" + + +def footer_datetime(timestamp: str) -> datetime: + """Takes an embed timestamp and returns a timezone-aware datetime object.""" + return datetime.fromisoformat(timestamp) diff --git a/pydis_site/apps/staff/urls.py b/pydis_site/apps/staff/urls.py index 95b3caf3..a564d516 100644 --- a/pydis_site/apps/staff/urls.py +++ b/pydis_site/apps/staff/urls.py @@ -1,12 +1,10 @@ from django.conf import settings from django.conf.urls.static import static -from django.contrib import admin -from django.urls import include, path +from django.urls import path from .viewsets import LogView app_name = 'staff' urlpatterns = [ path('bot/logs/<int:pk>/', LogView.as_view(), name="logs"), - path('admin/', admin.site.urls), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/pydis_site/apps/staff/viewsets/__init__.py b/pydis_site/apps/staff/viewsets/__init__.py index ccb57d43..6b10eb83 100644 --- a/pydis_site/apps/staff/viewsets/__init__.py +++ b/pydis_site/apps/staff/viewsets/__init__.py @@ -1,3 +1,3 @@ from .logs import LogView -__all__ = ["LogView"]
\ No newline at end of file +__all__ = ["LogView"] diff --git a/pydis_site/apps/staff/viewsets/logs.py b/pydis_site/apps/staff/viewsets/logs.py index d59847a3..0898d606 100644 --- a/pydis_site/apps/staff/viewsets/logs.py +++ b/pydis_site/apps/staff/viewsets/logs.py @@ -1,3 +1,5 @@ +import logging + from django.core.handlers.wsgi import WSGIRequest from django.http import HttpResponse from django.shortcuts import get_object_or_404, render @@ -5,11 +7,27 @@ from django.views import View from pydis_site.apps.api.models.bot.message_deletion_context import MessageDeletionContext +log = logging.getLogger(__name__) + class LogView(View): + """The default view for the Deleted Messages logs.""" + template_name = "staff/logs.html" def get(self, request: WSGIRequest, pk: int) -> HttpResponse: + """Get method that answers a request with an html response by rendering a template.""" message_context = get_object_or_404(MessageDeletionContext, pk=pk) + + actor = message_context.actor + creation = message_context.creation messages = message_context.deletedmessage_set.all() - return render(request, self.template_name, {"message_context": message_context, "messages": messages}) + + template_fields = { + 'actor': actor, + 'actor_colour': message_context.actor.top_role.colour, + 'creation': creation, + 'messages': messages + } + + return render(request, self.template_name, template_fields) |