Skip to content

Commit 7fc86c8

Browse files
update example (#58)
1 parent e8c5cae commit 7fc86c8

3 files changed

Lines changed: 101 additions & 100 deletions

File tree

app/eSignature/examples/eg030_brands_apply_to_template.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def get_args():
1818
cc_email = request.form.get("cc_email")
1919
cc_name = request.form.get("cc_name")
2020
brand_id = request.form.get("brand")
21-
template_id = request.form.get("envelope_template")
21+
template_id = session["template_id"]
2222

2323
if cc_email and cc_name:
2424
cc_email = pattern.sub("", cc_email)
@@ -95,19 +95,15 @@ def make_envelope(cls, args):
9595

9696
@staticmethod
9797
def get_data(args):
98-
"""Retrieve brands and envelope templates"""
98+
"""Retrieve brands"""
9999
api_client = create_api_client(base_path=args["base_path"], access_token=args["access_token"])
100100

101101
try:
102102
"""Retrieve all brands using the AccountBrands::List"""
103103
account_api = AccountsApi(api_client)
104104
brands = account_api.list_brands(account_id=args["account_id"]).brands
105105

106-
"""Retrieve all templates using the Templates::List"""
107-
template_api = TemplatesApi(api_client)
108-
envelope_templates = template_api.list_templates(account_id=args["account_id"]).envelope_templates
109-
110-
return brands, envelope_templates
106+
return brands
111107

112108
except ApiException as err:
113109
return process_error(err)

app/eSignature/views/eg030_brands_apply_to_template.py

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,44 @@
1717
@authenticate(eg=eg)
1818
def brands_apply_to_template():
1919
"""
20-
1. Get required arguments
21-
2. Call the worker method
22-
3. Render a response
20+
1. Check the presence of a saved template_id
21+
2. Get required arguments
22+
3. Call the worker method
23+
4. Render a response
2324
"""
2425

25-
# 1. Get required arguments
26-
args = Eg030BrandsApplyToTemplateController.get_args()
27-
try:
28-
# 2: Call the worker method to apply the brand to the template
29-
response = Eg030BrandsApplyToTemplateController.worker(args)
30-
envelope_id = response.envelope_id
31-
app.logger.info(f"The brand and template have been applied to the envelope. Envelope ID: {envelope_id}")
26+
# 1. Check the presence of a saved template_id
27+
if "template_id" in session:
28+
# 2. Get required arguments
29+
args = Eg030BrandsApplyToTemplateController.get_args()
30+
try:
31+
# 3: Call the worker method to apply the brand to the template
32+
response = Eg030BrandsApplyToTemplateController.worker(args)
33+
envelope_id = response.envelope_id
34+
app.logger.info(f"The brand and template have been applied to the envelope. Envelope ID: {envelope_id}")
3235

33-
# 3: Render the response
36+
# 4: Render the response
37+
return render_template(
38+
"example_done.html",
39+
title="Applying a brand and template to an envelope",
40+
h1="Applying a brand and template to an envelope",
41+
message=f"The brand and template have been applied to the envelope!<br/> Envelope ID: {envelope_id}."
42+
)
43+
44+
except ApiException as err:
45+
return process_error(err)
46+
47+
else:
3448
return render_template(
35-
"example_done.html",
49+
"eg030_brands_apply_to_template.html",
3650
title="Applying a brand and template to an envelope",
37-
h1="Applying a brand and template to an envelope",
38-
message=f"The brand and template have been applied to the envelope!<br/> Envelope ID: {envelope_id}."
51+
template_ok=False,
52+
source_file= "eg030_brands_apply_to_template.py",
53+
source_url=DS_CONFIG["github_example_url"] + "eg030_brands_apply_to_template.py",
54+
documentation=DS_CONFIG["documentation"] + eg,
55+
show_doc=DS_CONFIG["documentation"],
3956
)
4057

41-
except ApiException as err:
42-
return process_error(err)
43-
4458

4559
@eg030.route("/eg030", methods=["GET"])
4660
@authenticate(eg=eg)
@@ -52,16 +66,16 @@ def get_view():
5266
"base_path": session["ds_base_path"],
5367
"access_token": session["ds_access_token"], # Represents your {ACCESS_TOKEN}
5468
}
55-
brands, templates = Eg030BrandsApplyToTemplateController.get_data(args)
69+
brands = Eg030BrandsApplyToTemplateController.get_data(args)
5670
return render_template(
5771
"eg030_brands_apply_to_template.html",
5872
title="Applying a brand and template to an envelope",
73+
template_ok="template_id" in session,
5974
source_file= "eg030_brands_apply_to_template.py",
6075
source_url=DS_CONFIG["github_example_url"] + "eg030_brands_apply_to_template.py",
6176
documentation=DS_CONFIG["documentation"] + eg,
6277
show_doc=DS_CONFIG["documentation"],
6378
brands=brands,
64-
templates=templates,
6579
signer_name=DS_CONFIG["signer_name"],
6680
signer_email=DS_CONFIG["signer_email"],
6781
)

app/templates/eg030_brands_apply_to_template.html

Lines changed: 65 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
<h4>30. Apply a brand and template to an envelope</h4>
44

5-
<p>
6-
This code example demonstrates how to apply a brand to a template.
7-
</p>
5+
{% if template_ok %}
6+
<p>
7+
This code example demonstrates how to apply a brand to a template.
8+
</p>
9+
{% endif %}
810

911
{% if show_doc %}
1012
<p><a target='_blank' href='{{ documentation | safe }}'>Documentation</a> about this example.</p>
@@ -19,77 +21,66 @@ <h4>30. Apply a brand and template to an envelope</h4>
1921
View source file <a target="_blank" href="{{ source_url | safe }}">{{ source_file }}</a> on GitHub.
2022
</p>
2123

22-
{% if brands and templates %}
23-
<form class="eg" action="" method="post" data-busy="form">
24-
<div class="form-group">
25-
<label for="signer_email">Signer Email</label>
26-
<input type="email" class="form-control" id="signer_email" name="signer_email"
27-
aria-describedby="emailHelp" placeholder="pat@example.com" required
28-
value="{{ signer_email }}">
29-
<small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
30-
</div>
31-
32-
33-
<div class="form-group">
34-
<label for="signer_name">Signer Name</label>
35-
<input type="text" class="form-control" id="signer_name" placeholder="Pat Johnson" name="signer_name"
36-
value="{{ signer_name }}" required>
37-
</div>
38-
39-
40-
<div class="form-group">
41-
<label for="cc_email">CC Email</label>
42-
<input type="email" class="form-control" id="cc_email" name="cc_email"
43-
aria-describedby="emailHelp" placeholder="pat@example.com">
44-
<small id="emailHelp" class="form-text text-muted">The email and/or name for the cc recipient must be different from yhe signer.</small>
45-
</div>
46-
47-
<div class="form-group">
48-
<label for="cc_name">CC Name</label>
49-
<input type="text" class="form-control" id="cc_name" placeholder="Pat Johnson" name="cc_name">
50-
</div>
51-
52-
<div class="form-group">
53-
<label for="envelope_template">Envelope template</label>
54-
<br>
55-
<select id="envelope_template" name="envelope_template">
56-
{% for template in templates %}
57-
<option value="{{ template.template_id }}">{{ template.name }}</option>
58-
{% endfor %}
59-
</select>
60-
</div>
61-
62-
<div class="form-group">
63-
<label for="brand">Brand</label>
64-
<br>
65-
<select id="brand" name="brand">
66-
{% for brand in brands %}
67-
<option value="{{ brand.brand_id }}">{{ brand.brand_name }}</option>
68-
{% endfor %}
69-
</select>
70-
</div>
71-
72-
<div>
73-
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
74-
<button type="submit" class="btn btn-docu">Submit</button>
75-
</div>
76-
</form>
77-
78-
{% elif not brands %}
79-
<p>Problem: please first create the brand using <a href="eg028">example 24.</a>
80-
<br />
81-
Thank you.
82-
</p>
83-
84-
<form class="eg" action="eg028" method="get">
85-
<button type="submit" class="btn btn-docu">Continue</button>
86-
</form>
87-
88-
{% elif not templates %}
89-
<p>Problem: please first create the template using <a href="eg008">example 8.</a>
90-
<br />
91-
Thank you.
92-
</p>
24+
{% if template_ok %}
25+
{% if brands %}
26+
<form class="eg" action="" method="post" data-busy="form">
27+
<div class="form-group">
28+
<label for="signer_email">Signer Email</label>
29+
<input type="email" class="form-control" id="signer_email" name="signer_email"
30+
aria-describedby="emailHelp" placeholder="pat@example.com" required
31+
value="{{ signer_email }}">
32+
<small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
33+
</div>
34+
35+
36+
<div class="form-group">
37+
<label for="signer_name">Signer Name</label>
38+
<input type="text" class="form-control" id="signer_name" placeholder="Pat Johnson" name="signer_name"
39+
value="{{ signer_name }}" required>
40+
</div>
41+
42+
43+
<div class="form-group">
44+
<label for="cc_email">CC Email</label>
45+
<input type="email" class="form-control" id="cc_email" name="cc_email"
46+
aria-describedby="emailHelp" placeholder="pat@example.com">
47+
<small id="emailHelp" class="form-text text-muted">The email and/or name for the cc recipient must be different from yhe signer.</small>
48+
</div>
49+
50+
<div class="form-group">
51+
<label for="cc_name">CC Name</label>
52+
<input type="text" class="form-control" id="cc_name" placeholder="Pat Johnson" name="cc_name">
53+
</div>
54+
55+
<div class="form-group">
56+
<label for="brand">Brand</label>
57+
<br>
58+
<select id="brand" name="brand">
59+
{% for brand in brands %}
60+
<option value="{{ brand.brand_id }}">{{ brand.brand_name }}</option>
61+
{% endfor %}
62+
</select>
63+
</div>
64+
65+
<div>
66+
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
67+
<button type="submit" class="btn btn-docu">Submit</button>
68+
</div>
69+
</form>
70+
71+
{% else %}
72+
<p>Problem: please first create the brand using <a href="eg028">example 24.</a>
73+
<br />
74+
Thank you.
75+
</p>
76+
77+
<form class="eg" action="eg028" method="get">
78+
<button type="submit" class="btn btn-docu">Continue</button>
79+
</form>
80+
{% endif %}
81+
{% else %}
82+
<p>Problem: please first create the template using <a href="eg008">example 8.</a> <br/>
83+
Thank you.</p>
9384

9485
<form class="eg" action="eg008" method="get">
9586
<button type="submit" class="btn btn-docu">Continue</button>

0 commit comments

Comments
 (0)