diff options
author | 2020-08-03 10:25:11 +0200 | |
---|---|---|
committer | 2020-08-03 10:25:11 +0200 | |
commit | 685214c5495e0364a57f50c48a8c83d96bd53054 (patch) | |
tree | e0c473c2081a06282b549c2cfb81907e087b9e5d /pydis_site/apps/api/serializers.py | |
parent | Merge pull request #370 from python-discord/role-reminders (diff) | |
parent | Delete FilterList objects for tests. (diff) |
Merge pull request #371 from python-discord/whitelist_system
FilterList model and endpoints
Diffstat (limited to 'pydis_site/apps/api/serializers.py')
-rw-r--r-- | pydis_site/apps/api/serializers.py | 44 |
1 files changed, 38 insertions, 6 deletions
diff --git a/pydis_site/apps/api/serializers.py b/pydis_site/apps/api/serializers.py index 80e552a6..52e0d972 100644 --- a/pydis_site/apps/api/serializers.py +++ b/pydis_site/apps/api/serializers.py @@ -4,13 +4,20 @@ from rest_framework.validators import UniqueTogetherValidator from rest_framework_bulk import BulkSerializerMixin from .models import ( - BotSetting, DeletedMessage, - DocumentationLink, Infraction, - LogEntry, MessageDeletionContext, - Nomination, OffTopicChannelName, + BotSetting, + DeletedMessage, + DocumentationLink, + FilterList, + Infraction, + LogEntry, + MessageDeletionContext, + Nomination, + OffTopicChannelName, OffensiveMessage, - Reminder, Role, - Tag, User + Reminder, + Role, + Tag, + User ) @@ -97,6 +104,31 @@ class DocumentationLinkSerializer(ModelSerializer): fields = ('package', 'base_url', 'inventory_url') +class FilterListSerializer(ModelSerializer): + """A class providing (de-)serialization of `FilterList` instances.""" + + class Meta: + """Metadata defined for the Django REST Framework.""" + + model = FilterList + fields = ('id', 'created_at', 'updated_at', 'type', 'allowed', 'content', 'comment') + + # This validator ensures only one filterlist with the + # same content can exist. This means that we cannot have both an allow + # and a deny for the same item, and we cannot have duplicates of the + # same item. + validators = [ + UniqueTogetherValidator( + queryset=FilterList.objects.all(), + fields=['content', 'type'], + message=( + "A filterlist for this item already exists. " + "Please note that you cannot add the same item to both allow and deny." + ) + ), + ] + + class InfractionSerializer(ModelSerializer): """A class providing (de-)serialization of `Infraction` instances.""" |