|
| 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 | + ) |
0 commit comments