Example #1
0
def retrieve_badge(request, identifier):
    """
    Gets the manifest for a specific badge based on identifier.
    See util.encode_badge() for how identifiers are determined.
    """
    badge = None
    try:
        badge_id, email = decode_badge(str(identifier))
        user = User.objects.get(email=email)
        badge = get_awarded_badges(user)[badge_id]
    except (KeyError, User.DoesNotExist, TypeError):
        pass

    if not badge:
        raise Http404

    response = {
        'spec': '0.1.0',
        'name': badge['name'],
        'evidence': request.build_absolute_uri(badge['evidence']),
        'image': badge['image'],
        'recipient': email,
        'description': badge['description'],
        'template': request.build_absolute_uri(badge['template']),
    }
    return HttpResponse(json.dumps(response),
                        mimetype='application/x-badge-manifest')
Example #2
0
def retrieve_badge(request, identifier):
    """
    Gets the manifest for a specific badge based on identifier.
    See util.encode_badge() for how identifiers are determined.
    """
    badge = None
    try:
        badge_id, email = decode_badge(str(identifier))
        user = User.objects.get(email=email)
        badge = get_awarded_badges(user)[badge_id]
    except (KeyError, User.DoesNotExist, TypeError):
        pass

    if not badge:
        raise Http404

    response = {
        "spec": "0.1.0",
        "name": badge["name"],
        "evidence": request.build_absolute_uri(badge["evidence"]),
        "image": badge["image"],
        "recipient": email,
        "description": badge["description"],
        "template": request.build_absolute_uri(badge["template"]),
    }
    return HttpResponse(json.dumps(response), mimetype="application/x-badge-manifest")
Example #3
0
def retrieve_badge(request, identifier):
    """
    Gets the manifest for a specific badge based on identifier.
    See util.encode_badge() for how identifiers are determined.
    """
    badge = None
    try:
        badge_id, username = decode_badge(str(identifier))
        user = User.objects.get(username=username)
        badge = get_awarded_badges(user)[badge_id]
    except (KeyError, User.DoesNotExist, TypeError):
        pass

    if not badge:
        raise Http404

    recipient, salt = hash_recipient(user.email)
    issuer = Site.objects.get_current()
    origin = "http://%s" % issuer.domain
    # the obi is not appending the origin to the image url.
    image = badge['image']
    if image.startswith('/'):
        image = origin + image

    response = {
        'recipient': recipient,
        'salt': salt,
        'evidence': badge['evidence'],
        'badge': {
            'version': '0.5.0',
            'name': badge['name'][:128],
            'image': image,
            'description': badge['description'][:128],
            'criteria': badge['criteria'],
            'issuer': {
                'origin': origin,
                'name': issuer.name,
             }
        }
    }
    return HttpResponse(json.dumps(response),
        mimetype='application/json')