37
37
Reminder ,
38
38
Role ,
39
39
User ,
40
- UserAltRelationship
40
+ UserAltRelationship ,
41
+ UserModSettings
41
42
)
42
43
43
44
class FrozenFieldsMixin :
@@ -701,11 +702,23 @@ class UserSerializer(ModelSerializer):
701
702
# ID field must be explicitly set as the default id field is read-only.
702
703
id = IntegerField (min_value = 0 )
703
704
705
+ def to_representation (self , instance : User ) -> dict :
706
+ """Serialize the user to a dictionary, serializing the moderator settings."""
707
+ ret = super ().to_representation (instance )
708
+
709
+ if hasattr (instance , 'mod_settings' ) and instance .mod_settings is not None :
710
+ ret ['mod_settings' ] = UserModSettingsSerializer (instance .mod_settings ).data
711
+ else :
712
+ del ret ['mod_settings' ]
713
+
714
+ return ret
715
+
704
716
class Meta :
705
717
"""Metadata defined for the Django REST Framework."""
706
718
707
719
model = User
708
- fields = ('id' , 'name' , 'display_name' , 'discriminator' , 'roles' , 'in_guild' )
720
+ fields = ('id' , 'name' , 'display_name' , 'discriminator' , 'roles' ,
721
+ 'in_guild' , 'mod_settings' )
709
722
depth = 1
710
723
list_serializer_class = UserListSerializer
711
724
@@ -717,6 +730,7 @@ def create(self, validated_data: dict) -> User:
717
730
raise ValidationError ({"id" : ["User with ID already present." ]})
718
731
719
732
733
+ < << << << HEAD
720
734
class UserWithAltsSerializer (FrozenFieldsMixin , UserSerializer ):
721
735
"""A class providing (de-)serialization of `User` instances, expanding their alternate accounts."""
722
736
@@ -736,6 +750,16 @@ def get_alts(self, user: User) -> list[dict]:
736
750
for alt in user .alts .through .objects .filter (source = user )
737
751
]
738
752
753
+ == == == =
754
+ class UserModSettingsSerializer (ModelSerializer ):
755
+ """A class to serialize the moderator settings for a user."""
756
+
757
+ class Meta :
758
+ """Meta settings for the user moderator settings serializer."""
759
+
760
+ model = UserModSettings
761
+ fields = ('pings_disabled_until' , 'pings_schedule_start' , 'pings_schedule_end' )
762
+ > >> >> >> d672a0ab (Add serializer for mod_settings response key on User objects )
739
763
740
764
class NominationEntrySerializer (ModelSerializer ):
741
765
"""A class providing (de-)serialization of `NominationEntry` instances."""
0 commit comments