コード例 #1
0
class CustomTopicRelationshipSerializer(TopicRelationshipSerializer):
    attributes = CredentialAttributeSerializer(source="credential_attributes",
                                               many=True)
    topic = CustomTopicSerializer()
    related_topic = CustomTopicSerializer()
    relation_id = SerializerMethodField()
    topic_id = SerializerMethodField()

    def __init__(self, *args, **kwargs):
        super(CustomTopicRelationshipSerializer, self).__init__(*args)
        self.relationship_type = kwargs.get('relationship_type', 'to')

    class Meta(TopicRelationshipSerializer.Meta):
        depth = 1
        fields = (
            "topic_id",
            "relation_id",
            "credential",
            "topic",
            "related_topic",
            "attributes",
        )

    def get_relation_id(self, obj):
        return obj.id

    def get_topic_id(self, obj):
        if self.relationship_type == 'to':
            return obj.topic.id
        else:
            return obj.related_topic.id
コード例 #2
0
class CredentialSearchSerializer(HaystackSerializerMixin,
                                 CredentialSerializer):
    addresses = CredentialAddressSerializer(many=True)
    attributes = CredentialAttributeSerializer(many=True)
    credential_set = CredentialSetSerializer()
    credential_type = CredentialTypeSerializer()
    names = CredentialNameSerializer(many=True)
    topic = CredentialNamedTopicSerializer()
    related_topics = CredentialNamedTopicSerializer(many=True)

    class Meta(CredentialSerializer.Meta):
        fields = (
            "id",
            "create_timestamp",
            "update_timestamp",
            "effective_date",
            "inactive",
            "latest",
            "revoked",
            "revoked_date",
            "wallet_id",
            "credential_set",
            "credential_type",
            "addresses",
            "attributes",
            "names",
            "topic",
            "related_topics",
        )
        # used by ExactFilter
        exact_fields = (
            "credential_set_id",
            "credential_type_id",
            "issuer_id",
            "schema_name",
            "schema_version",
            "topic_id",
            "topic_type",
            "wallet_id",
        )
        # used by HaystackFilter
        search_fields = (
            "location",
            "effective_date",
            "revoked_date",
            "score",
        )
        # used by StatusFilter
        status_fields = {
            "inactive": "false",
            "latest": "true",
            "revoked": "false",
        }