|
| 1 | +"""Example 006: Embed a clickwrap""" |
| 2 | + |
| 3 | +from os import path |
| 4 | +import json |
| 5 | +import webbrowser |
| 6 | + |
| 7 | +from docusign_click.client.api_exception import ApiException |
| 8 | +from flask import render_template, current_app, Blueprint, session |
| 9 | + |
| 10 | +from ..examples.eg006_embed_clickwrap import Eg006EmbedClickwrapController |
| 11 | +from ..examples.eg002_activate_clickwrap import Eg002ActivateClickwrapController |
| 12 | +from app.docusign import authenticate, get_example_by_number, ensure_manifest |
| 13 | +from app.ds_config import DS_CONFIG |
| 14 | +from app.error_handlers import process_error |
| 15 | + |
| 16 | +example_number = 6 |
| 17 | +eg = f"eg00{example_number}" # Reference (and URL) for this example |
| 18 | +eg006 = Blueprint(eg, __name__) |
| 19 | + |
| 20 | + |
| 21 | +@eg006.route(f"/{eg}", methods=["POST"]) |
| 22 | +@ensure_manifest(manifest_url=DS_CONFIG["click_manifest_url"]) |
| 23 | +@authenticate(eg=eg) |
| 24 | +def embed_clickwrap(): |
| 25 | + """ |
| 26 | + 1. Get required arguments |
| 27 | + 2. Call the worker method |
| 28 | + 3. Render the response |
| 29 | + """ |
| 30 | + example = get_example_by_number(session["manifest"], example_number) |
| 31 | + |
| 32 | + # 1. Get required arguments |
| 33 | + args = Eg006EmbedClickwrapController.get_args() |
| 34 | + |
| 35 | + try: |
| 36 | + # 2. Call the worker method to create a new clickwrap |
| 37 | + results = Eg006EmbedClickwrapController.worker(args) |
| 38 | + current_app.logger.info( |
| 39 | + f"""See the embedded clickwrap in the dialog box.""" |
| 40 | + ) |
| 41 | + except ApiException as err: |
| 42 | + return process_error(err) |
| 43 | + |
| 44 | + # Save for use by other examples which need an clickwrap params. |
| 45 | + session["clickwrap_is_active"] = True |
| 46 | + |
| 47 | + if results.to_dict()["agreement_url"] == None: |
| 48 | + return render_template( |
| 49 | + "error.html", |
| 50 | + error_code="200", |
| 51 | + error_message="The email address was already used to agree to this elastic template. Provide a different email address if you want to view the agreement and agree to it." |
| 52 | + ) |
| 53 | + |
| 54 | + # 3. Render the response |
| 55 | + return render_template( |
| 56 | + "eg006_done.html", |
| 57 | + title=example["ExampleName"], |
| 58 | + message=f"""See the embedded clickwrap in the dialog box.""", |
| 59 | + json=json.dumps(json.dumps(results.to_dict(), default=str)), |
| 60 | + agreementUrl= results.to_dict()["agreement_url"] |
| 61 | + ) |
| 62 | + |
| 63 | + |
| 64 | +@eg006.route(f"/{eg}", methods=["GET"]) |
| 65 | +@ensure_manifest(manifest_url=DS_CONFIG["click_manifest_url"]) |
| 66 | +@authenticate(eg=eg) |
| 67 | +def get_view(): |
| 68 | + """responds with the form for the example""" |
| 69 | + example = get_example_by_number(session["manifest"], example_number) |
| 70 | + |
| 71 | + args = Eg006EmbedClickwrapController.get_args() |
| 72 | + return render_template( |
| 73 | + "eg006_embed_clickwrap.html", |
| 74 | + title=example["ExampleName"], |
| 75 | + example=example, |
| 76 | + clickwraps_data=Eg006EmbedClickwrapController.get_active_clickwraps(args), |
| 77 | + inactive_clickwraps_data=Eg002ActivateClickwrapController.get_inactive_clickwraps(args), |
| 78 | + source_file= "eg006_embed_clickwrap.py", |
| 79 | + source_url=DS_CONFIG["click_github_url"] + "eg006_embed_clickwrap.py", |
| 80 | + ) |
0 commit comments