diff options
author | 2022-01-21 21:55:19 +0000 | |
---|---|---|
committer | 2022-01-21 21:55:19 +0000 | |
commit | 721d313e9170661bd969fe8e737866b2560dae4a (patch) | |
tree | 44aa19b25573ada3bf2ef3cf16c9c279d7b05603 /pydis_site/apps/api/serializers.py | |
parent | Implement voice mute + migration from voice mute -> voice ban (diff) | |
parent | Merge pull request #640 from Krish-bhardwaj/main (diff) |
Merge branch 'main' into voicemute
Diffstat (limited to 'pydis_site/apps/api/serializers.py')
-rw-r--r-- | pydis_site/apps/api/serializers.py | 50 |
1 files changed, 36 insertions, 14 deletions
diff --git a/pydis_site/apps/api/serializers.py b/pydis_site/apps/api/serializers.py index 8484e561..4a702d61 100644 --- a/pydis_site/apps/api/serializers.py +++ b/pydis_site/apps/api/serializers.py @@ -145,7 +145,16 @@ class InfractionSerializer(ModelSerializer): model = Infraction fields = ( - 'id', 'inserted_at', 'expires_at', 'active', 'user', 'actor', 'type', 'reason', 'hidden' + 'id', + 'inserted_at', + 'expires_at', + 'active', + 'user', + 'actor', + 'type', + 'reason', + 'hidden', + 'dm_sent' ) validators = [ UniqueTogetherValidator( @@ -200,25 +209,30 @@ class ExpandedInfractionSerializer(InfractionSerializer): return ret +class OffTopicChannelNameListSerializer(ListSerializer): + """Custom ListSerializer to override to_representation() when list views are triggered.""" + + def to_representation(self, objects: list[OffTopicChannelName]) -> list[str]: + """ + Return a list with all `OffTopicChannelName`s in the database. + + This returns the list of off topic channel names. We want to only return + the name attribute, hence it is unnecessary to create a nested dictionary. + Additionally, this allows off topic channel name routes to simply return an + array of names instead of objects, saving on bandwidth. + """ + return [obj.name for obj in objects] + + class OffTopicChannelNameSerializer(ModelSerializer): """A class providing (de-)serialization of `OffTopicChannelName` instances.""" class Meta: """Metadata defined for the Django REST Framework.""" + list_serializer_class = OffTopicChannelNameListSerializer model = OffTopicChannelName - fields = ('name',) - - def to_representation(self, obj: OffTopicChannelName) -> str: - """ - Return the representation of this `OffTopicChannelName`. - - This only returns the name of the off topic channel name. As the model - only has a single attribute, it is unnecessary to create a nested dictionary. - Additionally, this allows off topic channel name routes to simply return an - array of names instead of objects, saving on bandwidth. - """ - return obj.name + fields = ('name', 'used', 'active') class ReminderSerializer(ModelSerializer): @@ -231,7 +245,15 @@ class ReminderSerializer(ModelSerializer): model = Reminder fields = ( - 'active', 'author', 'jump_url', 'channel_id', 'content', 'expiration', 'id', 'mentions' + 'active', + 'author', + 'jump_url', + 'channel_id', + 'content', + 'expiration', + 'id', + 'mentions', + 'failures' ) |