class BackpackAssertionSerializerV2(DetailSerializerV2, OriginalJsonSerializerMixin): acceptance = serializers.ChoiceField( choices=BadgeInstance.ACCEPTANCE_CHOICES, default=BadgeInstance.ACCEPTANCE_ACCEPTED) # badgeinstance openBadgeId = serializers.URLField(source='jsonld_id', read_only=True) badgeclass = EntityRelatedFieldV2(source='cached_badgeclass', required=False, queryset=BadgeClass.cached) badgeclassOpenBadgeId = serializers.URLField(source='badgeclass_jsonld_id', read_only=True) issuer = EntityRelatedFieldV2(source='cached_issuer', required=False, queryset=Issuer.cached) issuerOpenBadgeId = serializers.URLField(source='issuer_jsonld_id', read_only=True) image = serializers.FileField(read_only=True) recipient = BadgeRecipientSerializerV2(source='*') issuedOn = serializers.DateTimeField(source='issued_on', read_only=True) narrative = MarkdownCharField(required=False) evidence = EvidenceItemSerializerV2(many=True, required=False) revoked = HumanReadableBooleanField(read_only=True) revocationReason = serializers.CharField(source='revocation_reason', read_only=True) expires = serializers.DateTimeField(source='expires_at', required=False) class Meta(DetailSerializerV2.Meta): model = BadgeInstance
class BackpackAssertionSerializerV2(DetailSerializerV2, OriginalJsonSerializerMixin): acceptance = serializers.ChoiceField(choices=BadgeInstance.ACCEPTANCE_CHOICES, default=BadgeInstance.ACCEPTANCE_ACCEPTED) # badgeinstance openBadgeId = serializers.URLField(source='jsonld_id', read_only=True) badgeclass = EntityRelatedFieldV2(source='cached_badgeclass', required=False, queryset=BadgeClass.cached) badgeclassOpenBadgeId = serializers.URLField(source='badgeclass_jsonld_id', read_only=True) issuer = EntityRelatedFieldV2(source='cached_issuer', required=False, queryset=Issuer.cached) issuerOpenBadgeId = serializers.URLField(source='issuer_jsonld_id', read_only=True) image = serializers.FileField(read_only=True) recipient = BadgeRecipientSerializerV2(source='*') issuedOn = serializers.DateTimeField(source='issued_on', read_only=True) narrative = MarkdownCharField(required=False) evidence = EvidenceItemSerializerV2(many=True, required=False) revoked = HumanReadableBooleanField(read_only=True) revocationReason = serializers.CharField(source='revocation_reason', read_only=True) expires = serializers.DateTimeField(source='expires_at', required=False) class Meta(DetailSerializerV2.Meta): model = BadgeInstance def to_representation(self, instance): representation = super(BackpackAssertionSerializerV2, self).to_representation(instance) request_kwargs = self.context['kwargs'] expands = request_kwargs['expands'] if 'badgeclass' in expands: representation['badgeclass'] = instance.cached_badgeclass.get_json(include_extra=True, use_canonical_id=True) if 'issuer' in expands: representation['badgeclass']['issuer'] = instance.cached_issuer.get_json(include_extra=True, use_canonical_id=True) return representation
class BadgeConnectAssertionSerializer(BadgeConnectBaseEntitySerializer): id = serializers.URLField(source='jsonld_id', read_only=True) badge = serializers.URLField(source='badgeclass_jsonld_id', read_only=True) image = serializers.FileField(read_only=True) recipient = BadgeRecipientSerializerV2(source='*') issuedOn = serializers.DateTimeField(source='issued_on', read_only=True) narrative = MarkdownCharField(required=False) evidence = EvidenceItemSerializerV2(many=True, required=False) revoked = HumanReadableBooleanField(read_only=True) revocationReason = serializers.CharField(source='revocation_reason', read_only=True) expires = serializers.DateTimeField(source='expires_at', required=False) type = serializers.CharField(read_only=True, default='Assertion') class Meta: SCHEMA_TYPE = 'Assertion' model = BadgeInstance apispec_definition = ('BadgeConnectAssertion', { 'properties': OrderedDict([ ('id', { 'type': "string", 'format': "url", 'readOnly': True, 'description': "URL of the BadgeInstance", }), ('badge', { 'type': "string", 'format': "url", 'readOnly': True, 'description': "URL of the BadgeClass", }), ('image', { 'type': "string", 'format': "string", 'readOnly': True, 'description': "Badge Image", }), ('recipient', { 'type': 'object', 'properties': BadgeRecipientSerializerV2.Meta.apispec_definition[1]['properties'], 'readOnly': True, 'description': "Recipient that was issued the Assertion" }), ('issuedOn', { 'type': 'string', 'format': 'ISO8601 timestamp', 'readOnly': True, 'description': "Timestamp when the Assertion was issued", }), ('narrative', { 'type': 'string', 'format': 'markdown', 'description': "Markdown narrative of the achievement", }), ('evidence', { 'type': "string", 'format': "string", 'description': "Unique identifier for this Assertion", }), ('revoked', { 'type': 'boolean', 'readOnly': True, 'description': "True if this Assertion has been revoked", }), ('revocationReason', { 'type': 'string', 'format': "string", 'readOnly': True, 'description': "Short description of why the Assertion was revoked", }), ('expires', { 'type': 'string', 'format': 'ISO8601 timestamp', 'description': "Timestamp when the Assertion expires", }), ('@context', { 'type': 'string', 'format': 'url', 'default': CONTEXT_URI, 'example': CONTEXT_URI, }), ('type', { 'type': 'string', 'default': SCHEMA_TYPE, 'example': SCHEMA_TYPE }) ]) })
class BackpackAssertionSerializerV2(DetailSerializerV2, OriginalJsonSerializerMixin): acceptance = serializers.ChoiceField( choices=BadgeInstance.ACCEPTANCE_CHOICES, default=BadgeInstance.ACCEPTANCE_ACCEPTED) # badgeinstance openBadgeId = serializers.URLField(source='jsonld_id', read_only=True) badgeclass = EntityRelatedFieldV2(source='cached_badgeclass', required=False, queryset=BadgeClass.cached) badgeclassOpenBadgeId = serializers.URLField(source='badgeclass_jsonld_id', read_only=True) issuer = EntityRelatedFieldV2(source='cached_issuer', required=False, queryset=Issuer.cached) issuerOpenBadgeId = serializers.URLField(source='issuer_jsonld_id', read_only=True) image = serializers.FileField(read_only=True) recipient = BadgeRecipientSerializerV2(source='*') issuedOn = DateTimeWithUtcZAtEndField(source='issued_on', read_only=True) narrative = MarkdownCharField(required=False) evidence = EvidenceItemSerializerV2(many=True, required=False) revoked = HumanReadableBooleanField(read_only=True) revocationReason = serializers.CharField(source='revocation_reason', read_only=True) expires = DateTimeWithUtcZAtEndField(source='expires_at', required=False) pending = serializers.ReadOnlyField() class Meta(DetailSerializerV2.Meta): model = BadgeInstance apispec_definition = ('BackpackAssertion', { 'properties': OrderedDict([ ('entityId', { 'type': "string", 'format': "string", 'description': "Unique identifier for this Issuer", 'readOnly': True, }), ('entityType', { 'type': "string", 'format': "string", 'description': "\"Issuer\"", 'readOnly': True, }), ('openBadgeId', { 'type': "string", 'format': "url", 'description': "URL of the OpenBadge compliant json", 'readOnly': True, }), ('badgeclass', { 'type': 'string', 'format': 'entityId', 'description': "BadgeClass that issued this Assertion", 'required': False, }), ('badgeclassOpenBadgeId', { 'type': 'string', 'format': 'url', 'description': "URL of the BadgeClass to award", 'readOnly': True, }), ('image', { 'type': 'string', 'format': 'url', 'description': "URL to the baked assertion image", 'readOnly': True, }), ('recipient', { 'type': 'object', 'properties': OrderedDict([ ('identity', { 'type': 'string', 'format': 'string', 'description': 'Either the hash of the identity or the plaintext value', 'required': True, }), ('type', { 'type': 'string', 'enum': [ c[0] for c in BadgeInstance.RECIPIENT_TYPE_CHOICES ], 'description': "Type of identifier used to identify recipient", 'required': False, }), ('hashed', { 'type': 'boolean', 'description': "Whether or not the identity value is hashed.", 'required': False, }), ('plaintextIdentity', { 'type': 'string', 'description': "The plaintext identity", 'required': False, }), ]), 'description': "Recipient that was issued the Assertion", 'required': True, }), ('issuedOn', { 'type': 'string', 'format': 'ISO8601 timestamp', 'description': "Timestamp when the Assertion was issued", 'required': True, }), ('narrative', { 'type': 'string', 'format': 'markdown', 'description': "Markdown narrative of the achievement", 'required': False, }), ('evidence', { 'type': 'array', 'items': { '$ref': '#/definitions/AssertionEvidence' }, 'description': "List of evidence associated with the achievement", 'required': False, }), ('revoked', { 'type': 'boolean', 'description': "True if this Assertion has been revoked", 'readOnly': True, }), ('revocationReason', { 'type': 'string', 'format': "string", 'description': "Short description of why the Assertion was revoked", 'readOnly': True, }), ('expires', { 'type': 'string', 'format': 'ISO8601 timestamp', 'description': "Timestamp when the Assertion expires", 'required': False, }), ]) }) def to_representation(self, instance): representation = super(BackpackAssertionSerializerV2, self).to_representation(instance) request_kwargs = self.context['kwargs'] expands = request_kwargs.get('expands', []) if self.parent is not None: # we'll have a bare representation instance_data_pointer = representation else: instance_data_pointer = representation['result'][0] if 'badgeclass' in expands: instance_data_pointer[ 'badgeclass'] = instance.cached_badgeclass.get_json( include_extra=True, use_canonical_id=True) if 'issuer' in expands: instance_data_pointer['badgeclass'][ 'issuer'] = instance.cached_issuer.get_json( include_extra=True, use_canonical_id=True) return representation