from rest_framework import serializers
from apps.api.fields import Base64Field
from apps.filters.models import FilterSet, Rule
from apps.mails.models import Message, MessagePart
[docs]class FilterSetSerializer(serializers.ModelSerializer):
name = serializers.CharField()
created_by = serializers.PrimaryKeyRelatedField(read_only=True)
is_global = serializers.BooleanField()
is_active = serializers.BooleanField()
icon = serializers.CharField(max_length=255)
count = serializers.IntegerField(allow_null=True, default=None)
[docs]class MessagePartSerializer(serializers.ModelSerializer):
[docs]class MessagePartSummarySerializer(serializers.ModelSerializer):
[docs]class MessageSerializer(serializers.ModelSerializer):
recipients_to = serializers.JSONField()
recipients_cc = serializers.JSONField()
recipients_bcc = serializers.JSONField()
headers = serializers.JSONField()
source = Base64Field()
parts = MessagePartSummarySerializer(
many=True,
read_only=True
)
# API V1 Serializers
[docs]class FilterSetAdvancedSerializer(serializers.ModelSerializer):
id = serializers.IntegerField(default=None, allow_null=True)
name = serializers.CharField()
created_by = serializers.PrimaryKeyRelatedField(read_only=True)
is_global = serializers.BooleanField()
is_active = serializers.BooleanField()
icon = serializers.CharField(max_length=255)
rules = serializers.HyperlinkedRelatedField(
read_only=True,
many=True,
view_name='api:rules_single',
lookup_field='pk',
lookup_url_kwarg='identifier'
)
count = serializers.IntegerField(allow_null=True, default=None)
[docs]class RuleAdvancedSerializer(serializers.ModelSerializer):
id = serializers.IntegerField(default=None, allow_null=True)
filter_set = serializers.HyperlinkedRelatedField(
read_only=False,
queryset=FilterSet.objects.all(),
many=False,
view_name='api:filters_single',
lookup_field='pk',
lookup_url_kwarg='identifier'
)