Beispiel #1
0
class IssuerViewSet(ReadOnlyModelViewSet):
    serializer_class = IssuerSerializer
    queryset = Issuer.objects.all()

    def list(self, request):
        response = super().list(request)
        item_count = self.queryset.count()
        response["item_count"] = item_count
        return response

    @swagger_auto_schema(responses={200: CredentialTypeSerializer(many=True)})
    @action(detail=True, url_path="credentialtype", methods=["get"])
    def list_credential_types(self, request, pk=None):
        item = self.get_object()
        queryset = item.credential_types
        serializer = CredentialTypeSerializer(queryset, many=True)
        return Response(serializer.data)

    @swagger_auto_schema(method="get")
    @action(detail=True, url_path="logo", methods=["get"])
    def fetch_logo(self, request, pk=None):
        issuer = get_object_or_404(self.queryset, pk=pk)
        logo = None
        if issuer.logo_b64:
            logo = base64.b64decode(issuer.logo_b64)
        if not logo:
            raise Http404()
        # FIXME - need to store the logo mime type
        return HttpResponse(logo, content_type="image/jpg")
Beispiel #2
0
class SearchSerializer(HaystackSerializer):
    id = IntegerField(source="object.id")
    source_id = CharField(source="object.source_id")
    type = CharField(source="object.type")
    names = TopicNameSerializer(
        source="object.get_active_names", many=True)
    addresses = TopicAddressSerializer(
        source="object.get_active_addresses", many=True)
    attributes = TopicAttributeSerializer(
        source="object.get_active_attributes", many=True)
    credential_set = CredentialSetSerializer(
        source="object.foundational_credential.credential_set")
    credential_type = CredentialTypeSerializer(
        source="object.foundational_credential.credential_type")
    inactive = BooleanField(
        source="object.foundational_credential.inactive")
    revoked = BooleanField(
        source="object.foundational_credential.revoked")
    effective_date = DateTimeField(
        source="object.foundational_credential.effective_date")
    revoked_date = DateTimeField(
        source="object.foundational_credential.revoked_date")

    class Meta:
        index_classes = [TopicIndex]
        fields = ("id", "source_id", "type", "names", "addresses", "attributes", "credential_set",
                  "credential_type", "inactive", "revoked", "effective_date", "revoked_date")
        # ExactFilter fields
        exact_fields = ("topic_issuer_id", "topic_type_id", "topic_credential_type_id")
        # StatusFilter fields
        status_fields = {"topic_inactive": "false", "topic_revoked": "false"}
        # HaystackFilter fields
        search_fields = ("score")
Beispiel #3
0
 def list_credential_types(self, request, pk=None):
     item = self.get_object()
     queryset = item.credential_types
     serializer = CredentialTypeSerializer(queryset, many=True)
     item_count = len(serializer.data)
     response = Response(serializer.data)
     response["item_count"] = item_count
     return response
Beispiel #4
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",
            "credential_id",
            "credential_set",
            "credential_type",
            "addresses",
            "attributes",
            "names",
            "topic",
            "related_topics",
        )
        # used by ExactFilter
        exact_fields = (
            "credential_set_id",
            "credential_type_id",
            "topic_credential_type_id",
            "issuer_id",
            "schema_name",
            "schema_version",
            "topic_id",
            "topic_type",
            "credential_id",
        )
        # used by HaystackFilter
        search_fields = ("location", "effective_date", "revoked_date", "score")
        # used by StatusFilter
        status_fields = {
            "inactive": "false",
            "latest": "true",
            "revoked": "false"
        }
Beispiel #5
0
 def list_credential_types(self, request, pk=None):
     item = self.get_object()
     queryset = item.credential_types
     serializer = CredentialTypeSerializer(queryset, many=True)
     return Response(serializer.data)