aboutsummaryrefslogtreecommitdiffstats
path: root/pydis_site/apps/api/models
diff options
context:
space:
mode:
authorGravatar Sebastiaan Zeeff <[email protected]>2019-08-22 15:44:06 +0200
committerGravatar Sebastiaan Zeeff <[email protected]>2019-08-23 15:40:52 +0200
commit8da376b0ebff72db9f72b7026b6f2fef4dff4f13 (patch)
treec0ac005706e4976d810ef8dbac8187a43f63bcca /pydis_site/apps/api/models
parentAdding message display to frontend (diff)
Making the deleted-messages-frontend functional with changes, including:
- Adding support for embeds to both the template and the css; - Adding Discord fonts to create a Discord-realistic rendering; - Adding Discord color int to html hex filter for use in templates; - Removing unnecessary int -> hex property from role model (see previous point); - Adding support to compute timestamp from snowflake int in the message model; - Forcing the order of deleted messages list view to snowflake `id` to guarantee chronological order.
Diffstat (limited to 'pydis_site/apps/api/models')
-rw-r--r--pydis_site/apps/api/models/bot/deleted_message.py5
-rw-r--r--pydis_site/apps/api/models/bot/message.py12
2 files changed, 17 insertions, 0 deletions
diff --git a/pydis_site/apps/api/models/bot/deleted_message.py b/pydis_site/apps/api/models/bot/deleted_message.py
index eb7f4c89..1eb4516e 100644
--- a/pydis_site/apps/api/models/bot/deleted_message.py
+++ b/pydis_site/apps/api/models/bot/deleted_message.py
@@ -12,3 +12,8 @@ class DeletedMessage(Message):
help_text="The deletion context this message is part of.",
on_delete=models.CASCADE
)
+
+ class Meta:
+ """Sets the default ordering for list views to oldest first."""
+
+ ordering = ["id"]
diff --git a/pydis_site/apps/api/models/bot/message.py b/pydis_site/apps/api/models/bot/message.py
index 6b566620..0713b9d2 100644
--- a/pydis_site/apps/api/models/bot/message.py
+++ b/pydis_site/apps/api/models/bot/message.py
@@ -1,6 +1,11 @@
+from datetime import datetime
+
+import pytz
from django.contrib.postgres import fields as pgfields
from django.core.validators import MinValueValidator
from django.db import models
+from django.utils import timezone
+
from pydis_site.apps.api.models.bot.tag import validate_tag_embed
from pydis_site.apps.api.models.bot.user import User
@@ -49,6 +54,13 @@ class Message(ModelReprMixin, models.Model):
help_text="Embeds attached to this message."
)
+ @property
+ def timestamp(self) -> datetime:
+ """Attribute that represents the message timestamp as derived from the snowflake id."""
+ tz_naive_datetime = datetime.utcfromtimestamp(((self.id >> 22) + 1420070400000) / 1000)
+ tz_aware_datetime = timezone.make_aware(tz_naive_datetime, timezone=pytz.timezone("UTC"))
+ return tz_aware_datetime
+
class Meta:
"""Metadata provided for Django's ORM."""