Esempio n. 1
0
def init_certificate_template(config):
    template = create_certificate_template(config)
    col = DAO().get_collection("certificate_template")
    if col.find_one():
        _id = col.find_one()["_id"]
        selector = {"_id": _id}
        col.replace_one(selector, template)
    else:
        col.insert_one(template)
    print(template)
Esempio n. 2
0
def get_unsigned_credential(credential, person):
    cert_tools_config = credential.cert_tools_config
    template = Namespace()
    template.issuer_url = cert_tools_config.issuer_url
    template.issuer_email = cert_tools_config.issuer_email
    template.issuer_name = cert_tools_config.issuer_name
    template.issuer_id = cert_tools_config.issuer_id
    template.revocation_list = cert_tools_config.revocation_list
    template.issuer_public_key = cert_tools_config.issuer_public_key
    template.certificate_title = strip_tags(credential.title)
    template.certificate_description = strip_tags(credential.description)
    template.criteria_narrative = strip_tags(credential.narrative)
    template.badge_id = credential.badge_id
    template.issuer_signature_lines = None
    template.hash_emails = False
    template.additional_per_recipient_fields = None
    template.display_html = Template(
        cert_tools_config.display_html_template).safe_substitute(
            name=person.name,
            title=credential.title,
            date_issue=datetime.now().strftime("%B %d, %Y"),
            description=credential.description,
            issuing_department=credential.issuing_department,
            narrative=credential.narrative)
    template.additional_global_fields = [{
        "path": "$.displayHtml",
        "value": template.display_html
    }, {
        "path":
        "$.@context",
        "value": [
            "https://w3id.org/openbadges/v2", "https://w3id.org/blockcerts/v2",
            {
                "displayHtml": {
                    "@id":
                    "https://schemas.learningmachine.com/2017/blockcerts/displayHtml",
                    "@type":
                    "https://schemas.learningmachine.com/2017/types/text/html"
                }
            }
        ]
    }]
    template.issuer_logo_file = 'images/issuer-logo.png'
    template.cert_image_file = 'images/cert-image.png'
    template.abs_data_dir = os.path.abspath(os.path.join(os.getcwd(), 'data'))
    template = create_certificate_template(template)
    usc = create_unsigned_certificates_from_roster(template, [person], False,
                                                   None, False)
    # We only ever ask for one cert here so it's always the first one
    uid = next(iter(usc))
    usc[uid]['id'] = settings.VIEW_URL.format(uid)

    return usc
Esempio n. 3
0
def create_template():
    conf = tpl.get_config(get_tools_conf_dir(TOKEN))
    tpl.create_certificate_template(conf)
Esempio n. 4
0
def create_template():
    conf = tpl.get_config(os.path.abspath('../configuration/cert_tools_conf.ini'))
    tpl.create_certificate_template(conf)