Ejemplo n.º 1
0
def index():
	client = HSClient(api_key=HS_APP_KEY)
	embedded_sign = client.send_signature_request_embedded_with_template(
		test_mode=True,
		client_id=HS_CLIENT_ID,
		template_id=TEMPLATE_ID,
		subject='<subject>',
		message='<message>',
		signers=[{ 
			'role_name': '<role>', 
			'email_address': '<email>', 
			'name': '<name>' 
			}])
	embed_id = client.get_embedded_object(embedded_sign.signatures[0].signature_id)
	sign_url = str(embed_id.sign_url)
	return render_template('index.html', client_id=HS_CLIENT_ID, sign_url=sign_url)
Ejemplo n.º 2
0
def embedded_signing_with_template(request):
    try:
        hsclient = HSClient(api_key=API_KEY)
    except NoAuthMethod:
        return render(
            request, 'hellosign/embedded_signing_with_template.html', {
                'error_message':
                "Please update your settings to include a value for API_KEY."
            })
    if request.method == 'POST':
        try:
            signers = []
            post_dict = parser.parse(request.POST.urlencode())
            template_id = post_dict["template"]
            for (key, value) in post_dict["signerRole"].iteritems():
                if value:
                    value['role_name'] = key
                    signers.append(value)

            ccs = []
            if 'ccRole' in post_dict and len(post_dict['ccRole']) > 0:
                for (key, value) in post_dict["ccRole"].iteritems():
                    # if value:
                    ccs.append({'role_name': key, 'email_address': value})

            custom_fields = []
            if 'cf' in post_dict and len(post_dict['cf']) > 0:
                for (key, value) in post_dict["cf"].iteritems():
                    if value:
                        custom_fields.append({key: value})

            sr = hsclient.send_signature_request_embedded_with_template(
                test_mode=True,
                client_id=CLIENT_ID,
                template_id=template_id,
                title="NDA with Acme Co.",
                subject="The NDA we talked about",
                message=
                "Please sign this NDA and then we can discuss more. Let me know if you have any questions.",
                signing_redirect_url=None,
                signers=signers,
                ccs=ccs,
                custom_fields=custom_fields)
            embedded = hsclient.get_embedded_object(
                sr.signatures[0].signature_id)

        # TODO: need some more validations here
        # except KeyError:
        #     return render(request, 'hellosign/embedded_signing_with_template.html', {
        #         'error_message': "Please enter both your name and email.",
        #     })
        except NoAuthMethod:
            pass
        else:
            return render(request,
                          'hellosign/embedded_signing_with_template.html', {
                              'client_id': CLIENT_ID,
                              'sign_url': str(embedded.sign_url)
                          })
    else:
        template_list = hsclient.get_template_list()
        templates = []
        for template in template_list:
            template_data = dict(template.json_data)
            del template_data['accounts']
            templates.append(template_data)
        templates = json.dumps(templates)
        return render(request, 'hellosign/embedded_signing_with_template.html',
                      {'templates': templates})