Skip to content

Commit f16bb73

Browse files
Web Forms code example (#143)
* added example * updates for webforms * using correct base path * changing docusign js events * adding web forms SDK --------- Co-authored-by: Paige Rossi <paige.rossi@docusign.com>
1 parent 1ec2c7c commit f16bb73

18 files changed

+423
-3
lines changed

app/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from .monitor import views as monitor_views
1313
from .admin import views as admin_views
1414
from .connect import views as connect_views
15+
from .webforms import views as webforms_views
1516
from .views import core
1617

1718
session_path = "/tmp/python_recipe_sessions"
@@ -113,6 +114,8 @@
113114

114115
app.register_blueprint(connect_views.cneg001)
115116

117+
app.register_blueprint(webforms_views.weg001)
118+
116119
if "DYNO" in os.environ: # On Heroku?
117120
import logging
118121

app/consts.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
# Name of static pdf file
2323
pdf_file = "World_Wide_Corp_lorem.pdf"
2424

25+
web_form_template_file = "World_Wide_Corp_Form.pdf"
26+
27+
web_form_config_file = "web-form-config.json"
28+
2529
# Base uri for callback function
2630
base_uri_suffix = "/restapi"
2731

@@ -109,5 +113,6 @@
109113
"CLICK": "Click",
110114
"ROOMS": "Rooms",
111115
"ADMIN": "Admin",
112-
"CONNECT": "Connect"
116+
"CONNECT": "Connect",
117+
"WEBFORMS": "WebForms"
113118
}

app/docusign/ds_client.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
"asset_group_account_read", "asset_group_account_clone_write", "asset_group_account_clone_read"
3434
]
3535

36+
WEBFORMS_SCOPES = [
37+
"signature", "webforms_read", "webforms_instance_read", "webforms_instance_write"
38+
]
39+
3640

3741
class DSClient:
3842
ds_app = None
@@ -57,6 +61,8 @@ def _auth_code_grant(cls, api):
5761
use_scopes.extend(CLICK_SCOPES)
5862
elif api == "Admin":
5963
use_scopes.extend(ADMIN_SCOPES)
64+
elif api == "WebForms":
65+
use_scopes.extend(WEBFORMS_SCOPES)
6066
else:
6167
use_scopes.extend(SCOPES)
6268
# remove duplicate scopes
@@ -93,6 +99,8 @@ def _jwt_auth(cls, api):
9399
use_scopes.extend(CLICK_SCOPES)
94100
elif api == "Admin":
95101
use_scopes.extend(ADMIN_SCOPES)
102+
elif api == "WebForms":
103+
use_scopes.extend(WEBFORMS_SCOPES)
96104
else:
97105
use_scopes.extend(SCOPES)
98106
# remove duplicate scopes

app/docusign/utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import requests
44
import urllib
55
import json
6+
import re
67

78
from docusign_esign import ApiClient, AccountsApi
89
from flask import session, flash, url_for, redirect, render_template, current_app
@@ -146,3 +147,12 @@ def get_user_info(access_token, base_path, oauth_host_name):
146147
api_client = create_api_client(base_path, access_token)
147148
api_client.set_oauth_host_name(oauth_host_name)
148149
return api_client.get_user_info(access_token)
150+
151+
def replace_template_id(file_path, template_id):
152+
with open(file_path, 'r') as file:
153+
content = file.read()
154+
155+
content = re.sub('template-id', template_id, content)
156+
157+
with open(file_path, 'w') as file:
158+
file.write(content)

app/ds_config_sample.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"rooms_api_client_host": "https://demo.rooms.docusign.com/restapi",
1717
"monitor_api_client_host": "https://lens-d.docusign.net",
1818
"admin_api_client_host": "https://api-d.docusign.net/management",
19+
"webforms_api_client_host": "https://apps-d.docusign.com/api/webforms/v1.1",
1920
"allow_silent_authentication": True, # a user can be silently authenticated if they have an
2021
# active login session on another tab of the same browser
2122
"target_account_id": None, # Set if you want a specific DocuSign AccountId,

app/static/assets/search.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const DS_SEARCH = (function () {
66
ROOMS: "rooms",
77
ADMIN: "admin",
88
CONNECT: "connect",
9+
WEBFORMS: "webforms"
910
}
1011

1112
const processJSONData = function () {
@@ -142,6 +143,8 @@ const DS_SEARCH = (function () {
142143
return "eg";
143144
case API_TYPES.CONNECT:
144145
return "cneg";
146+
case API_TYPES.WEBFORMS:
147+
return "weg";
145148
}
146149
}
147150

44.7 KB
Binary file not shown.

app/static/demo_documents/web-form-config.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

app/templates/cfr_home.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ <h2>{{ group["Name"] }}</h2>
4545
{% for example in group["Examples"] -%}
4646
{% if not example["SkipForLanguages"] or "python" not in example["SkipForLanguages"] %}
4747
{% if example.CFREnabled == "AllAccounts" or example.CFREnabled == "CFROnly" %}
48-
{% set api_prefix = "a" if api["Name"] == "Admin" else "c" if api["Name"] == "Click" else "r" if api["Name"] == "Rooms" else "m" if api["Name"] == "Monitor" else "" %}
48+
{% set api_prefix = "a" if api["Name"] == "Admin" else "c" if api["Name"] == "Click" else "r" if api["Name"] == "Rooms" else "m" if api["Name"] == "Monitor" else "w" if api["Name"] == "WebForms" else "" %}
4949
<h4
5050
id="{{ api_prefix + 'example' + '0' * (3 - example['ExampleNumber'] | string() | length ) + example['ExampleNumber'] | string() }}"
5151
>

app/templates/home.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ <h2>{{ group["Name"] }}</h2>
4545
{% for example in group["Examples"] -%}
4646
{% if not example["SkipForLanguages"] or "python" not in example["SkipForLanguages"] %}
4747
{% if example.CFREnabled != "CFROnly" %}
48-
{% set api_prefix = "a" if api["Name"] == "Admin" else "c" if api["Name"] == "Click" else "r" if api["Name"] == "Rooms" else "m" if api["Name"] == "Monitor" else "cn" if api["Name"] == "Connect" else "" %}
48+
{% set api_prefix = "a" if api["Name"] == "Admin" else "c" if api["Name"] == "Click" else "r" if api["Name"] == "Rooms" else "m" if api["Name"] == "Monitor" else "cn" if api["Name"] == "Connect" else "w" if api["Name"] == "WebForms" else "" %}
4949
<h4
5050
id="{{ api_prefix + 'example' + '0' * (3 - example['ExampleNumber'] | string() | length ) + example['ExampleNumber'] | string() }}"
5151
>

0 commit comments

Comments
 (0)