2021-05-31 09:20:38 +00:00
|
|
|
from rest_framework import serializers
|
|
|
|
|
|
|
|
from common.drf.serializers import BulkModelSerializer
|
2021-08-24 06:20:54 +00:00
|
|
|
from notifications.models import SystemMsgSubscription, UserMsgSubscription
|
2021-05-31 09:20:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SystemMsgSubscriptionSerializer(BulkModelSerializer):
|
|
|
|
receive_backends = serializers.ListField(child=serializers.CharField())
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = SystemMsgSubscription
|
|
|
|
fields = (
|
|
|
|
'message_type', 'message_type_label',
|
|
|
|
'users', 'groups', 'receive_backends', 'receivers'
|
|
|
|
)
|
|
|
|
read_only_fields = (
|
|
|
|
'message_type', 'message_type_label', 'receivers'
|
|
|
|
)
|
|
|
|
extra_kwargs = {
|
|
|
|
'users': {'allow_empty': True},
|
|
|
|
'groups': {'allow_empty': True},
|
|
|
|
'receive_backends': {'required': True}
|
|
|
|
}
|
|
|
|
|
2022-11-04 06:22:38 +00:00
|
|
|
def update(self, instance, validated_data):
|
|
|
|
instance.set_message_type_label()
|
|
|
|
return super().update(instance, validated_data)
|
|
|
|
|
2021-05-31 09:20:38 +00:00
|
|
|
|
|
|
|
class SystemMsgSubscriptionByCategorySerializer(serializers.Serializer):
|
|
|
|
category = serializers.CharField()
|
|
|
|
category_label = serializers.CharField()
|
|
|
|
children = SystemMsgSubscriptionSerializer(many=True)
|
2021-08-24 06:20:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
class UserMsgSubscriptionSerializer(BulkModelSerializer):
|
|
|
|
receive_backends = serializers.ListField(child=serializers.CharField(), read_only=False)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = UserMsgSubscription
|
|
|
|
fields = ('user_id', 'receive_backends',)
|