diff options
author | 2023-12-13 09:07:08 +0100 | |
---|---|---|
committer | 2023-12-17 14:34:07 +0100 | |
commit | a908b9aa3a18222f296c0e4bd67d815f48ada5af (patch) | |
tree | f89afe69e35694ca740f5921627ff91a76f272d3 /pydis_site/apps/api/models | |
parent | Merge pull request #1175 from python-discord/dependabot/pip/ruff-0.1.8 (diff) |
Migrate mailing lists to their own API endpoints
Add a new model for the bot to store its mailing list state in, as
opposed to the current JSON blob in the BotSetting table. Migrate the
existing settings from the BotSetting table into the new model.
Diffstat (limited to 'pydis_site/apps/api/models')
-rw-r--r-- | pydis_site/apps/api/models/__init__.py | 2 | ||||
-rw-r--r-- | pydis_site/apps/api/models/bot/__init__.py | 2 | ||||
-rw-r--r-- | pydis_site/apps/api/models/bot/mailing_list.py | 13 | ||||
-rw-r--r-- | pydis_site/apps/api/models/bot/mailing_list_seen_item.py | 29 |
4 files changed, 46 insertions, 0 deletions
diff --git a/pydis_site/apps/api/models/__init__.py b/pydis_site/apps/api/models/__init__.py index fee4c8d5..5901c978 100644 --- a/pydis_site/apps/api/models/__init__.py +++ b/pydis_site/apps/api/models/__init__.py @@ -7,6 +7,8 @@ from .bot import ( DocumentationLink, DeletedMessage, Infraction, + MailingList, + MailingListSeenItem, Message, MessageDeletionContext, Nomination, diff --git a/pydis_site/apps/api/models/bot/__init__.py b/pydis_site/apps/api/models/bot/__init__.py index 6f09473d..c07a3238 100644 --- a/pydis_site/apps/api/models/bot/__init__.py +++ b/pydis_site/apps/api/models/bot/__init__.py @@ -8,6 +8,8 @@ from .infraction import Infraction from .message import Message from .aoc_completionist_block import AocCompletionistBlock from .aoc_link import AocAccountLink +from .mailing_list import MailingList +from .mailing_list_seen_item import MailingListSeenItem from .message_deletion_context import MessageDeletionContext from .nomination import Nomination, NominationEntry from .off_topic_channel_name import OffTopicChannelName diff --git a/pydis_site/apps/api/models/bot/mailing_list.py b/pydis_site/apps/api/models/bot/mailing_list.py new file mode 100644 index 00000000..eaca8fb5 --- /dev/null +++ b/pydis_site/apps/api/models/bot/mailing_list.py @@ -0,0 +1,13 @@ +from django.db import models + +from pydis_site.apps.api.models.mixins import ModelReprMixin + + +class MailingList(ModelReprMixin, models.Model): + """A mailing list that the bot is following.""" + + name = models.CharField( + max_length=50, + help_text="A short identifier for the mailing list.", + unique=True + ) diff --git a/pydis_site/apps/api/models/bot/mailing_list_seen_item.py b/pydis_site/apps/api/models/bot/mailing_list_seen_item.py new file mode 100644 index 00000000..d91cfbe6 --- /dev/null +++ b/pydis_site/apps/api/models/bot/mailing_list_seen_item.py @@ -0,0 +1,29 @@ +from django.db import models + +from pydis_site.apps.api.models.mixins import ModelReprMixin +from .mailing_list import MailingList + + +class MailingListSeenItem(ModelReprMixin, models.Model): + """An item in a mailing list that the bot has consumed and mirrored elsewhere.""" + + list = models.ForeignKey( + MailingList, + on_delete=models.CASCADE, + related_name='seen_items', + help_text="The mailing list from which this seen item originates." + ) + hash = models.CharField( + max_length=100, + help_text="A hash, or similar identifier, of the content that was seen." + ) + + class Meta: + """Prevent adding the same hash to the same list multiple times.""" + + constraints = ( + models.UniqueConstraint( + fields=('list', 'hash'), + name='unique_list_and_hash', + ), + ) |