Exemplo n.º 1
0
def embedded_template_requesting(request):
    try:
        hsclient = HSClient(api_key=API_KEY)
    except NoAuthMethod:
        return render(request, 'hellosign/embedded_template_requesting.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 = []
            for key, value in post_dict["ccRole"].iteritems():
                # if value:
                ccs.append({'role_name': key, 'email_address': value})
            custom_fields = []
            for key, value in post_dict["cf"].iteritems():
                if value:
                    custom_fields.append({key: value})
            sr = hsclient.send_signature_request_embedded_with_rf(test_mode = "1",
                client_id = CLIENT_ID, reusable_form_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 = "", signers = signers, ccs = ccs, custom_fields = custom_fields)
            embedded = hsclient.get_embeded_object(sr.signatures[0]["signature_id"])
        # TODO: need some more validations here
        # except KeyError:
        #     return render(request, 'hellosign/embedded_template_requesting.html', {
        #         'error_message': "Please enter both your name and email.",
        #     })
        except NoAuthMethod:
            pass
        else:
            return render(request, 'hellosign/embedded_template_requesting.html', {
                    'client_id': CLIENT_ID,
                    'sign_url': str(embedded.sign_url)
                    })
    else:
        rf_list = hsclient.get_reusable_form_list()
        templates = "[";
        for rf in rf_list:
            # print json.dumps(rf.json_data)
            templates = templates + json.dumps(rf.json_data) + ", "
        templates = templates + "]"
        return render(request, 'hellosign/embedded_template_requesting.html', {
                    'templates': templates
                    })