1
0
forked from erp-dev/erp
Files
erpnew/sse/serializers.py

28 lines
782 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from rest_framework import serializers
class PushSSEEventSerializer(serializers.Serializer):
"""
SSE 事件推送序列化器
用于验证推送到 SSE 客户端的事件数据
"""
message = serializers.CharField(
required=True,
help_text="要发送的消息内容",
max_length=10000,
allow_blank=False,
)
type = serializers.CharField(
required=False,
default='message',
help_text="事件类型message, notification, alert 等",
max_length=100,
)
def validate_message(self, value):
"""验证消息内容"""
if not value or not value.strip():
raise serializers.ValidationError("消息内容不能为空")
return value.strip()