def create(image_src_dir, badge_dst_dir, kind, username, email):
    """Create JSON and PNG for a new badge."""

    # Paths
    image_src_path, image_dst_path, json_dst_path = \
        make_paths(image_src_dir, badge_dst_dir, kind, username)

    # When is the badge being created?
    when = datetime.date.today().isoformat()

    # Hide the email address
    hashedemail = hash_email_address(email, badge.SALT)

    # Consistent slug combining kind and username.
    slug = "{0}/{1}".format(kind, username)

    # Cache a few values.
    name = kind
    description = badge.BADGE_DESCRIPTIONS[kind][1]
    criteria = "/badges/index.html#{0}.html".format(kind)
    assertion_url = "/badges/{0}.json".format(slug)
    image_url = "/badges/{0}.png".format(slug)

    new_badge = {
        "uid": hashedemail,
        "issuedOn": when,
        "image": badge.set_image_url(name),
        "recipient": {
            "identity": hashedemail,
            "type": "email",
            "hashed": True,
            "salt": badge.SALT
        },
        "badge": badge.set_badge_url(name),
        "verify": {
            "type": "hosted",
            "url": badge.set_verify_url(name, username)
        }
    }

    # Create and save the JSON assertion.
    with open(json_dst_path, "w") as writer:
        json.dump(new_badge, writer, indent=True, sort_keys=True)

    badgebakery.bake_badge("img/badges/{0}.png".format(kind),
                           "{0}.png".format(username), slug)
Beispiel #2
0
def create(image_src_dir, badge_dst_dir, kind, username, email):
    """Create JSON and PNG for a new badge."""

    # Paths
    image_src_path, image_dst_path, json_dst_path = \
        make_paths(image_src_dir, badge_dst_dir, kind, username)

    # When is the badge being created?
    when = datetime.date.today().isoformat()

    # Hide the email address
    hashedemail = hash_email_address(email, badge.SALT)

    # Consistent slug combining kind and username.
    slug = "{0}/{1}".format(kind, username)

    # Cache a few values.
    name = kind
    description = badge.BADGE_DESCRIPTIONS[kind][1]
    criteria = "/badges/index.html#{0}.html".format(kind)
    assertion_url = "/badges/{0}.json".format(slug)
    image_url = "/badges/{0}.png".format(slug)

    new_badge = {
        "uid":hashedemail,
        "issuedOn":when,
        "image":badge.set_image_url(name),
        "recipient":{
            "identity":hashedemail,
            "type":"email",
            "hashed":True,
            "salt":badge.SALT},
        "badge":badge.set_badge_url(name),
        "verify":{
            "type":"hosted",
            "url":badge.set_verify_url(name, username)}}

    # Create and save the JSON assertion.
    with open(json_dst_path, "w") as writer:
        json.dump(new_badge, writer, indent=True, sort_keys=True)

    badgebakery.bake_badge("img/badges/{0}.png".format(kind),
            "{0}.png".format(username),
            slug)
def update_badge_assertion(old_badge, badge_filename):
    """Create a BadgeAssertion based on the old badge structure.

    For more information about BadgeAssertion:
    https://github.com/mozilla/openbadges-specification/blob/master/Assertion/latest.md#structures.
    """
    new_badge = {
        "uid": old_badge["recipient"],
        "recipient": {
            "identity": old_badge["recipient"],
            "type": "email",
            "hashed": True
        },
        "badge": badge.set_badge_url(old_badge["badge"]["name"].lower()),
        "verify": {
            "type": "hosted",
            "url": "{0}/{1}".format(badge.URL, badge_filename)
        }
    }

    if "salt" in old_badge:
        new_badge["recipient"]["salt"] = old_badge["salt"]
    if "issued_on" in old_badge:
        new_badge["issuedOn"] = old_badge["issued_on"]

    if "badge" in old_badge and "image" in old_badge["badge"]:
        # Check for relative path
        if old_badge["badge"]["image"][0] == "/":
            new_badge["image"] = "{0}{1}".format(badge.URL,
                                                 old_badge["badge"]["image"])
        else:
            new_badge["image"] = old_badge["badge"]["image"]
    else:
        new_badge["image"] = set_image_url(old_badge["badge"]["name"])

    if "evidence" in old_badge:
        new_badge["evidence"] = old_badge["evidence"]

    if "expires" in old_badge:
        new_badge["expires"] = old_badge["expires"]

    return new_badge
Beispiel #4
0
def update_badge_assertion(old_badge, badge_filename):
    """Create a BadgeAssertion based on the old badge structure.

    For more information about BadgeAssertion:
    https://github.com/mozilla/openbadges-specification/blob/master/Assertion/latest.md#structures.
    """
    new_badge = {
        "uid":old_badge["recipient"],
        "recipient":{
            "identity":old_badge["recipient"],
            "type":"email",
            "hashed":True},
        "badge":badge.set_badge_url(old_badge["badge"]["name"].lower()),
        "verify":{
            "type":"hosted",
            "url":"{0}/{1}".format(badge.URL, badge_filename)}}

    if "salt" in old_badge:
        new_badge["recipient"]["salt"] = old_badge["salt"]
    if "issued_on" in old_badge:
        new_badge["issuedOn"] = old_badge["issued_on"]

    if "badge" in old_badge and "image" in old_badge["badge"]:
        # Check for relative path
        if old_badge["badge"]["image"][0] == "/":
            new_badge["image"] = "{0}{1}".format(
                    badge.URL, old_badge["badge"]["image"])
        else:
            new_badge["image"] = old_badge["badge"]["image"]
    else:
        new_badge["image"] = set_image_url(old_badge["badge"]["name"])

    if "evidence" in old_badge:
        new_badge["evidence"] = old_badge["evidence"]

    if "expires" in old_badge:
        new_badge["expires"] = old_badge["expires"]

    return new_badge