Skip to content

Commit d5fcfa6

Browse files
Merge pull request docusign#4 from docusign/October_GA_2.1_Update_MattK
Updating for October GA Release
2 parents 6cb1694 + 1385b6c commit d5fcfa6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2920
-831
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,4 @@ com_crashlytics_export_strings.xml
110110
crashlytics.properties
111111
crashlytics-build.properties
112112
fabric.properties
113+
.vscode/settings.json

app/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
from flask_wtf.csrf import CSRFProtect
55

66

7-
session_path = '/tmp/python_recipe_sessions'
7+
session_path = "/tmp/python_recipe_sessions"
88

99
app = Flask(__name__)
10-
app.config.from_pyfile('config.py')
11-
app.secret_key = ds_config.DS_CONFIG['session_secret']
10+
app.config.from_pyfile("config.py")
11+
app.secret_key = ds_config.DS_CONFIG["session_secret"]
1212
csrf = CSRFProtect(app) # See https://flask-wtf.readthedocs.io/en/stable/csrf.html
1313

14-
if 'DYNO' in os.environ: # On Heroku?
14+
if "DYNO" in os.environ: # On Heroku?
1515
import logging
1616
stream_handler = logging.StreamHandler()
1717
app.logger.addHandler(stream_handler)
1818
app.logger.setLevel(logging.INFO)
19-
app.logger.info('Recipe example startup')
20-
app.config.update(dict(PREFERRED_URL_SCHEME = 'https'))
19+
app.logger.info("Recipe example startup")
20+
app.config.update(dict(PREFERRED_URL_SCHEME = "https"))
2121

2222
from app import views

app/ds_config.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,28 @@
44
import os
55

66
DS_CONFIG = {
7-
'ds_client_id': '{CLIENT_ID}', # The app's DocuSign integration key
8-
'ds_client_secret': '{CLIENT_SECRET}', # The app's DocuSign integration key's secret
9-
'signer_email': '{USER_EMAIL}',
10-
'signer_name': '{USER_FULLNAME}',
11-
'app_url': '{APP_URL}', # The url of the application. Eg http://localhost:5000
7+
"ds_client_id": "{CLIENT_ID}", # The app's DocuSign integration key
8+
"ds_client_secret": "{CLIENT_SECRET}", # The app's DocuSign integration key's secret
9+
"signer_email": "{USER_EMAIL}",
10+
"signer_name": "{USER_FULLNAME}",
11+
"app_url": "{APP_URL}", # The url of the application. Eg http://localhost:5000
1212
# NOTE: You must add a Redirect URI of appUrl/ds/callback to your Integration Key.
1313
# Example: http:#localhost:5000/ds/callback
14-
'authorization_server': 'https://account-d.docusign.com',
15-
'session_secret': '{SESSION_SECRET}', # Secret for encrypting session cookie content
14+
"authorization_server": "https://account-d.docusign.com",
15+
"session_secret": "{SESSION_SECRET}", # Secret for encrypting session cookie content
1616
# Use any random string of characters
17-
'allow_silent_authentication': True, # a user can be silently authenticated if they have an
17+
"allow_silent_authentication": True, # a user can be silently authenticated if they have an
1818
# active login session on another tab of the same browser
19-
'target_account_id': None, # Set if you want a specific DocuSign AccountId,
19+
"target_account_id": None, # Set if you want a specific DocuSign AccountId,
2020
# If None, the user's default account will be used.
21-
'demo_doc_path': 'demo_documents',
22-
'doc_docx': 'World_Wide_Corp_Battle_Plan_Trafalgar.docx',
23-
'doc_pdf': 'World_Wide_Corp_lorem.pdf',
21+
"demo_doc_path": "demo_documents",
22+
"doc_salary_docx": "World_Wide_Corp_salary.docx",
23+
"doc_docx": "World_Wide_Corp_Battle_Plan_Trafalgar.docx",
24+
"doc_pdf": "World_Wide_Corp_lorem.pdf",
2425
# Payment gateway information is optional
25-
'gateway_account_id': '{DS_PAYMENT_GATEWAY_ID}',
26-
'gateway_name': "stripe",
27-
'gateway_display_name': "Stripe",
28-
'github_example_url': 'https://github.com/docusign/eg-03-python-auth-code-grant/tree/master/app/',
29-
'documentation': '' # Use an empty string to indicate no documentation path.
26+
"gateway_account_id": "{DS_PAYMENT_GATEWAY_ID}",
27+
"gateway_name": "stripe",
28+
"gateway_display_name": "Stripe",
29+
"github_example_url": "https://github.com/docusign/eg-03-python-auth-code-grant/tree/master/app/",
30+
"documentation": "" # Use an empty string to indicate no documentation path.
3031
}

app/eg001_embedded_signing.py

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,27 @@
77
import base64
88
import re
99
from docusign_esign import *
10-
from docusign_esign.rest import ApiException
10+
from docusign_esign.client.api_exception import ApiException
1111

1212
eg = "eg001" # reference (and url) for this example
1313
signer_client_id = 1000 # Used to indicate that the signer will use an embedded
1414
# Signing Ceremony. Represents the signer's userId within
1515
# your application.
16-
authentication_method = 'None' # How is this application authenticating
17-
# the signer? See the `authenticationMethod' definition
16+
authentication_method = "None" # How is this application authenticating
17+
# the signer? See the 'authenticationMethod' definition
1818
# https://developers.docusign.com/esign-rest-api/reference/Envelopes/EnvelopeViews/createRecipient
1919

20-
demo_docs_path = path.abspath(path.join(path.dirname(path.realpath(__file__)), 'static/demo_documents'))
20+
demo_docs_path = path.abspath(path.join(path.dirname(path.realpath(__file__)), "static/demo_documents"))
2121

2222

2323
def controller():
2424
"""Controller router using the HTTP method"""
25-
if request.method == 'GET':
25+
if request.method == "GET":
2626
return get_controller()
27-
elif request.method == 'POST':
27+
elif request.method == "POST":
2828
return create_controller()
2929
else:
30-
return render_template('404.html'), 404
30+
return render_template("404.html"), 404
3131

3232

3333
def create_controller():
@@ -41,53 +41,53 @@ def create_controller():
4141
# 2. Call the worker method
4242
# More data validation would be a good idea here
4343
# Strip anything other than characters listed
44-
pattern = re.compile('([^\w \-\@\.\,])+')
45-
signer_email = pattern.sub('', request.form.get('signer_email'))
46-
signer_name = pattern.sub('', request.form.get('signer_name'))
44+
pattern = re.compile("([^\w \-\@\.\,])+")
45+
signer_email = pattern.sub("", request.form.get("signer_email"))
46+
signer_name = pattern.sub("", request.form.get("signer_name"))
4747
envelope_args = {
48-
'signer_email': signer_email,
49-
'signer_name': signer_name,
50-
'signer_client_id': signer_client_id,
51-
'ds_return_url': url_for('ds_return', _external=True),
48+
"signer_email": signer_email,
49+
"signer_name": signer_name,
50+
"signer_client_id": signer_client_id,
51+
"ds_return_url": url_for("ds_return", _external=True),
5252
}
5353
args = {
54-
'account_id': session['ds_account_id'],
55-
'base_path': session['ds_base_path'],
56-
'ds_access_token': session['ds_access_token'],
57-
'envelope_args': envelope_args
54+
"account_id": session["ds_account_id"],
55+
"base_path": session["ds_base_path"],
56+
"ds_access_token": session["ds_access_token"],
57+
"envelope_args": envelope_args
5858
}
5959

6060
try:
6161
results = worker(args)
6262
except ApiException as err:
63-
error_body_json = err and hasattr(err, 'body') and err.body
63+
error_body_json = err and hasattr(err, "body") and err.body
6464
# we can pull the DocuSign error code and message from the response body
6565
error_body = json.loads(error_body_json)
66-
error_code = error_body and 'errorCode' in error_body and error_body['errorCode']
67-
error_message = error_body and 'message' in error_body and error_body['message']
66+
error_code = error_body and "errorCode" in error_body and error_body["errorCode"]
67+
error_message = error_body and "message" in error_body and error_body["message"]
6868
# In production, may want to provide customized error messages and
6969
# remediation advice to the user.
70-
return render_template('error.html',
70+
return render_template("error.html",
7171
err=err,
7272
error_code=error_code,
7373
error_message=error_message
7474
)
7575
if results:
7676
# Redirect the user to the Signing Ceremony
77-
# Don't use an iFrame!
77+
# Don"t use an iFrame!
7878
# State can be stored/recovered using the framework's session or a
7979
# query parameter on the returnUrl (see the makeRecipientViewRequest method)
8080
return redirect(results["redirect_url"])
8181

8282
else:
83-
flash('Sorry, you need to re-authenticate.')
83+
flash("Sorry, you need to re-authenticate.")
8484
# We could store the parameters of the requested operation
8585
# so it could be restarted automatically.
8686
# But since it should be rare to have a token issue here,
8787
# we'll make the user re-enter the form data after
8888
# authentication.
89-
session['eg'] = url_for(eg)
90-
return redirect(url_for('ds_must_authenticate'))
89+
session["eg"] = url_for(eg)
90+
return redirect(url_for("ds_must_authenticate"))
9191

9292

9393
# ***DS.snippet.0.start
@@ -105,29 +105,29 @@ def worker(args):
105105
# 2. call Envelopes::create API method
106106
# Exceptions will be caught by the calling function
107107
api_client = ApiClient()
108-
api_client.host = args['base_path']
109-
api_client.set_default_header("Authorization", "Bearer " + args['ds_access_token'])
108+
api_client.host = args["base_path"]
109+
api_client.set_default_header("Authorization", "Bearer " + args["ds_access_token"])
110110

111111
envelope_api = EnvelopesApi(api_client)
112-
results = envelope_api.create_envelope(args['account_id'], envelope_definition=envelope_definition)
112+
results = envelope_api.create_envelope(args["account_id"], envelope_definition=envelope_definition)
113113

114114
envelope_id = results.envelope_id
115-
app.logger.info(f'Envelope was created. EnvelopeId {envelope_id}')
115+
app.logger.info(f"Envelope was created. EnvelopeId {envelope_id}")
116116

117117
# 3. Create the Recipient View request object
118118
recipient_view_request = RecipientViewRequest(
119119
authentication_method = authentication_method,
120-
client_user_id = envelope_args['signer_client_id'],
121-
recipient_id = '1',
122-
return_url = envelope_args['ds_return_url'],
123-
user_name = envelope_args['signer_name'], email = envelope_args['signer_email']
120+
client_user_id = envelope_args["signer_client_id"],
121+
recipient_id = "1",
122+
return_url = envelope_args["ds_return_url"],
123+
user_name = envelope_args["signer_name"], email = envelope_args["signer_email"]
124124
)
125125
# 4. Obtain the recipient_view_url for the signing ceremony
126126
# Exceptions will be caught by the calling function
127-
results = envelope_api.create_recipient_view(args['account_id'], envelope_id,
127+
results = envelope_api.create_recipient_view(args["account_id"], envelope_id,
128128
recipient_view_request = recipient_view_request)
129129

130-
return {'envelope_id': envelope_id, 'redirect_url': results.url}
130+
return {"envelope_id": envelope_id, "redirect_url": results.url}
131131

132132

133133
def make_envelope(args):
@@ -142,30 +142,30 @@ def make_envelope(args):
142142
#
143143
# The envelope has one recipient.
144144
# recipient 1 - signer
145-
with open(path.join(demo_docs_path, ds_config.DS_CONFIG['doc_pdf']), "rb") as file:
145+
with open(path.join(demo_docs_path, ds_config.DS_CONFIG["doc_pdf"]), "rb") as file:
146146
content_bytes = file.read()
147-
base64_file_content = base64.b64encode(content_bytes).decode('ascii')
147+
base64_file_content = base64.b64encode(content_bytes).decode("ascii")
148148

149149
# Create the document model
150150
document = Document( # create the DocuSign document object
151151
document_base64 = base64_file_content,
152-
name = 'Example document', # can be different from actual file name
153-
file_extension = 'pdf', # many different document types are accepted
152+
name = "Example document", # can be different from actual file name
153+
file_extension = "pdf", # many different document types are accepted
154154
document_id = 1 # a label used to reference the doc
155155
)
156156

157157
# Create the signer recipient model
158158
signer = Signer( # The signer
159-
email = args['signer_email'], name = args['signer_name'],
159+
email = args["signer_email"], name = args["signer_name"],
160160
recipient_id = "1", routing_order = "1",
161161
# Setting the client_user_id marks the signer as embedded
162-
client_user_id = args['signer_client_id']
162+
client_user_id = args["signer_client_id"]
163163
)
164164

165165
# Create a sign_here tab (field on the document)
166166
sign_here = SignHere( # DocuSign SignHere field/tab
167-
anchor_string = '/sn1/', anchor_units = 'pixels',
168-
anchor_y_offset = '10', anchor_x_offset = '20'
167+
anchor_string = "/sn1/", anchor_units = "pixels",
168+
anchor_y_offset = "10", anchor_x_offset = "20"
169169
)
170170

171171
# Add the tabs model (including the sign_here tab) to the signer
@@ -192,14 +192,14 @@ def get_controller():
192192
return render_template("eg001_embedded_signing.html",
193193
title="Embedded Signing Ceremony",
194194
source_file=path.basename(__file__),
195-
source_url=ds_config.DS_CONFIG['github_example_url'] + path.basename(__file__),
196-
documentation=ds_config.DS_CONFIG['documentation'] + eg,
197-
show_doc=ds_config.DS_CONFIG['documentation'],
198-
signer_name=ds_config.DS_CONFIG['signer_name'],
199-
signer_email=ds_config.DS_CONFIG['signer_email']
195+
source_url=ds_config.DS_CONFIG["github_example_url"] + path.basename(__file__),
196+
documentation=ds_config.DS_CONFIG["documentation"] + eg,
197+
show_doc=ds_config.DS_CONFIG["documentation"],
198+
signer_name=ds_config.DS_CONFIG["signer_name"],
199+
signer_email=ds_config.DS_CONFIG["signer_email"]
200200
)
201201
else:
202202
# Save the current operation so it will be resumed after authentication
203-
session['eg'] = url_for(eg)
204-
return redirect(url_for('ds_must_authenticate'))
203+
session["eg"] = url_for(eg)
204+
return redirect(url_for("ds_must_authenticate"))
205205

0 commit comments

Comments
 (0)