diff options
author | 2020-08-27 00:59:39 +0200 | |
---|---|---|
committer | 2020-08-27 00:59:39 +0200 | |
commit | 05a0575e28abfebb54a7f3996c182ae6ae091ab6 (patch) | |
tree | 61fa0951297cd0745bda4b95a3c40f04e042f4ad /pydis_site/apps/api/serializers.py | |
parent | OT: Rename variable `ext` to `other_names` (diff) | |
parent | Merge pull request #374 from Numerlor/reminder-direct-retrieve (diff) |
Merge branch 'master' into off-topic-non-random
Diffstat (limited to 'pydis_site/apps/api/serializers.py')
-rw-r--r-- | pydis_site/apps/api/serializers.py | 52 |
1 files changed, 42 insertions, 10 deletions
diff --git a/pydis_site/apps/api/serializers.py b/pydis_site/apps/api/serializers.py index e11c4af2..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.""" @@ -203,7 +235,9 @@ class ReminderSerializer(ModelSerializer): """Metadata defined for the Django REST Framework.""" model = Reminder - fields = ('active', 'author', 'jump_url', 'channel_id', 'content', 'expiration', 'id') + fields = ( + 'active', 'author', 'jump_url', 'channel_id', 'content', 'expiration', 'id', 'mentions' + ) class RoleSerializer(ModelSerializer): @@ -229,13 +263,11 @@ class TagSerializer(ModelSerializer): class UserSerializer(BulkSerializerMixin, ModelSerializer): """A class providing (de-)serialization of `User` instances.""" - roles = PrimaryKeyRelatedField(many=True, queryset=Role.objects.all(), required=False) - class Meta: """Metadata defined for the Django REST Framework.""" model = User - fields = ('id', 'avatar_hash', 'name', 'discriminator', 'roles', 'in_guild') + fields = ('id', 'name', 'discriminator', 'roles', 'in_guild') depth = 1 |