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", }
class CredentialSearchSerializer(HaystackSerializerMixin, CredentialSerializer): credential_type = CredentialTypeSerializer() names = CredentialNameSerializer(many=True) topic = CredentialTopicSerializer() class Meta(CredentialSerializer.Meta): fields = ( "id", "create_timestamp", "update_timestamp", "credential_type", "effective_date", "names", "revoked", "topic", ) search_fields = ("name", "location", "revoked")
def register_issuer(self, didauth, spec): user = self.update_user(didauth, spec["issuer"]) issuer = self.update_issuer(spec["issuer"]) schemas, credential_types = self.update_schemas_and_ctypes( issuer, spec.get("credential_types", [])) # TODO: use a serializer to return consistent data with REST API? # Do this at the view layer instead of this manager? result = { "issuer": IssuerSerializer(issuer).data, "schemas": [SchemaSerializer(schema).data for schema in schemas], "credential_types": [ CredentialTypeSerializer(credential_type).data for credential_type in credential_types ], } return result
class IssuerViewSet(ReadOnlyModelViewSet): serializer_class = IssuerSerializer queryset = Issuer.objects.all() @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")
def retrieve(self, request, pk=None): queryset = CredentialType.objects.all() item = get_object_or_404(queryset, pk=pk) serializer = CredentialTypeSerializer(item) return Response(serializer.data)
def list(self, request): queryset = CredentialType.objects.all() serializer = CredentialTypeSerializer(queryset, many=True) return Response(serializer.data)
def list_credential_types(self, request, pk=None): queryset = CredentialType.objects.filter(issuer__id=pk) get_object_or_404(queryset, pk=pk) serializer = CredentialTypeSerializer(queryset, many=True) return Response(serializer.data)
def get_credential_type(self, obj): qs = obj.credential_type serializer = CredentialTypeSerializer(instance=qs) return serializer.data
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)