You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
from rest_framework import serializers
|
|
|
|
|
|
|
|
from common.drf.serializers import BulkModelSerializer
|
|
|
|
from notifications.models import SystemMsgSubscription, UserMsgSubscription
|
|
|
|
|
|
|
|
|
|
|
|
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}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class SystemMsgSubscriptionByCategorySerializer(serializers.Serializer):
|
|
|
|
category = serializers.CharField()
|
|
|
|
category_label = serializers.CharField()
|
|
|
|
children = SystemMsgSubscriptionSerializer(many=True)
|
|
|
|
|
|
|
|
|
|
|
|
class UserMsgSubscriptionSerializer(BulkModelSerializer):
|
|
|
|
receive_backends = serializers.ListField(child=serializers.CharField(), read_only=False)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = UserMsgSubscription
|
|
|
|
fields = ('user_id', 'receive_backends',)
|