Skip to content

Commit ad604e6

Browse files
author
Olena Harkusha
committed
Add unpause a signature workflow example
1 parent 1f66586 commit ad604e6

11 files changed

Lines changed: 161 additions & 13 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ This repo is a Python 3 application that demonstrates:
117117
1. **Pause a signature workflow**
118118
[Source.](./app/eSignature/examples/eg032_pause_signature_workflow/controller.py)
119119
This code example demonstrates how to create an envelope where the workflow is paused before the envelope is sent to a second recipient.
120+
1. **Unpause a signature workflow**
121+
[Source.](./app/eSignature/examples/eg033_unpause_signature_workflow/controller.py)
122+
This code example demonstrates how to resume an envelope workflow that has been paused.
120123

121124

122125
## Rooms API

app/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
app.register_blueprint(examples.eg030)
7474
app.register_blueprint(examples.eg031)
7575
app.register_blueprint(examples.eg032)
76+
app.register_blueprint(examples.eg033)
7677

7778
if "DYNO" in os.environ: # On Heroku?
7879
import logging

app/eSignature/examples/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@
3030
from .eg030_brands_apply_to_template import eg030
3131
from .eg031_bulk_send import eg031
3232
from .eg032_pause_signature_workflow import eg032
33+
from .eg033_unpause_signature_workflow import eg033

app/eSignature/examples/eg032_pause_signature_workflow/controller.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@ def worker(cls, args):
5656
envelope_definition=envelope_definition
5757
)
5858

59-
envelope_id = results.envelope_id
60-
61-
return {"envelope_id": envelope_id}
59+
return {"paused_envelope_id": results.envelope_id}
6260

6361
@classmethod
6462
def make_envelope(cls, args):

app/eSignature/examples/eg032_pause_signature_workflow/views.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,17 @@ def pause_signature_workflow():
3232
except ApiException as err:
3333
return process_error(err)
3434

35-
session["envelope_id"] = results["envelope_id"] # Save for use by other examples which need an envelopeId
35+
session["paused_envelope_id"] = results["paused_envelope_id"] # Save for use by other examples which need an envelopeId
3636

3737
# 2. Render success response with envelopeId
3838
return render_template(
3939
"example_done.html",
4040
title="Envelope sent",
4141
h1="Envelope sent",
42-
message=f"The envelope has been created and sent!<br/>Envelope ID {results['envelope_id']}.<br/>"
43-
f"<p>To resume a workflow after the first resipient signs in the envelope use <a href='eg033'>example33.</a><br/>"
42+
message=f"The envelope has been created and sent!"
43+
f"<br/>Envelope ID {results['paused_envelope_id']}.<br/>"
44+
f"<p>To resume a workflow after the first resipient signs "
45+
f"the envelope use <a href='eg033'>example33.</a><br/>"
4446
)
4547

4648

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .views import eg033
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from docusign_esign import EnvelopesApi, EnvelopeDefinition
2+
from docusign_esign.models import Workflow
3+
from flask import session
4+
5+
from ....docusign import create_api_client
6+
7+
8+
class Eg033Controller:
9+
@staticmethod
10+
def get_args():
11+
""" Get session arguments """
12+
return {
13+
"account_id": session["ds_account_id"],
14+
"envelope_id": session["paused_envelope_id"],
15+
"base_path": session["ds_base_path"],
16+
"access_token": session["ds_access_token"],
17+
}
18+
19+
@classmethod
20+
def worker(cls, args):
21+
"""
22+
1. Call the envelope update method
23+
"""
24+
25+
# create the envelope definition
26+
env = EnvelopeDefinition(workflow=Workflow(workflow_status="in_progress"))
27+
28+
# Exceptions will be caught by the calling function
29+
api_client = create_api_client(
30+
base_path=args["base_path"], access_token=args["access_token"]
31+
)
32+
33+
# 2. call Envelopes::update API method
34+
# Exceptions will be caught by the calling function
35+
envelopes_api = EnvelopesApi(api_client)
36+
results = envelopes_api.update(
37+
account_id=args["account_id"],
38+
envelope_id=args["envelope_id"],
39+
envelope=env,
40+
resend_envelope=True
41+
)
42+
43+
return {"envelope_id": results.envelope_id}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
""" Example 033: Resuming an envelope workflow that has been paused """
2+
3+
from os import path
4+
5+
from docusign_esign.client.api_exception import ApiException
6+
from flask import render_template, session, Blueprint
7+
8+
from .controller import Eg033Controller
9+
from ....docusign import authenticate
10+
from ....ds_config import DS_CONFIG
11+
from ....error_handlers import process_error
12+
13+
eg = "eg033" # reference (and url) for this example
14+
eg033 = Blueprint("eg033", __name__)
15+
16+
17+
@eg033.route("/eg033", methods=["POST"])
18+
@authenticate(eg=eg)
19+
def unpause_signature_workflow():
20+
"""
21+
1. Get required arguments
22+
2. Call the worker method
23+
3. Render success response with envelopeId
24+
"""
25+
26+
# 1. Get required arguments
27+
args = Eg033Controller.get_args()
28+
try:
29+
# 1. Call the worker method
30+
results = Eg033Controller.worker(args)
31+
except ApiException as err:
32+
return process_error(err)
33+
34+
# Delete "paused_envelope_id" field from session to prevent an error on
35+
# a repeated unpause action for the same envelopeID.
36+
session.pop('paused_envelope_id', None)
37+
38+
# 2. Render success response with envelopeId
39+
return render_template(
40+
"example_done.html",
41+
envelope_ok=True,
42+
title="Envelope unpaused",
43+
h1="Envelope unpaused",
44+
message=f"The envelope workflow has been resumed and the envelope "
45+
f"has been sent to a second recipient!<br/>"
46+
f"Envelope ID {results['envelope_id']}.<br/>"
47+
)
48+
49+
50+
@eg033.route("/eg033", methods=["GET"])
51+
@authenticate(eg=eg)
52+
def get_view():
53+
"""responds with the form for the example"""
54+
55+
return render_template(
56+
"eg033_unpause_signature_workflow.html",
57+
title="Unpausing a signature workflow",
58+
envelope_ok="paused_envelope_id" in session,
59+
source_file=path.basename(path.dirname(__file__)) + "/controller.py",
60+
source_url=DS_CONFIG["github_example_url"] + path.basename(path.dirname(__file__)) + "/controller.py",
61+
documentation=DS_CONFIG["documentation"] + eg,
62+
show_doc=DS_CONFIG["documentation"],
63+
)

app/templates/eg032_pause_signature_workflow.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ <h4>32. Pausing a signature workflow</h4>
1111
{% endif %}
1212

1313
<p>API method used:
14-
<a target='_blank' href="https://developers.docusign.com/esign-rest-api/reference/Envelopes/Envelopes/create">Envelopes::Create</a>.
14+
<a target='_blank' href="https://developers.docusign.com/docs/esign-rest-api/reference/envelopes/envelopes/create/">Envelopes::create</a>.
1515
</p>
1616

1717
<p>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<!-- extend base layout --> {% extends "base.html" %} {% block content %}
2+
3+
<h4>33. Unpausing a signature workflow</h4>
4+
<p>This example demonstrates how to resume an envelope workflow that has been paused.
5+
</p>
6+
7+
{% if show_doc %}
8+
<p><a target='_blank' href='{{ documentation | safe }}'>Documentation</a> about this example.</p>
9+
{% endif %}
10+
11+
<p>API method used:
12+
<a target='_blank' href="https://developers.docusign.com/docs/esign-rest-api/reference/envelopes/envelopes/update/">Envelopes::update</a>.
13+
</p>
14+
15+
<p>
16+
View source file <a target="_blank" href="{{ source_url | safe }}">{{ source_file }}</a> on GitHub.
17+
</p>
18+
19+
{% if envelope_ok %}
20+
<p>The envelope you created via example 32 will be queried.</p>
21+
22+
<form class="eg" action="" method="post" data-busy="form">
23+
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
24+
<button type="submit" class="btn btn-docu">Continue</button>
25+
</form>
26+
27+
{% else %}
28+
<p>Problem: please first create an envelope using <a href="eg032">example 32.</a> <br/>
29+
Thank you.</p>
30+
31+
<form class="eg" action="eg032" method="get">
32+
<button type="submit" class="btn btn-docu">Continue</button>
33+
</form>
34+
{% endif %}
35+
36+
{% endblock %}

0 commit comments

Comments
 (0)