From 10b8a37e47291cf435e2d3fda56113ce68db0373 Mon Sep 17 00:00:00 2001
From: Oleksii Semko
Date: Fri, 24 Jan 2020 19:13:11 +0200
Subject: [PATCH 1/3] 024 brand creating
---
app/eg024_brand_creating.py | 165 ++++++++++++++++++++++++
app/templates/eg024_brand_creating.html | 46 +++++++
app/templates/home.html | 12 ++
app/views.py | 8 +-
4 files changed, 230 insertions(+), 1 deletion(-)
create mode 100644 app/eg024_brand_creating.py
create mode 100644 app/templates/eg024_brand_creating.html
diff --git a/app/eg024_brand_creating.py b/app/eg024_brand_creating.py
new file mode 100644
index 00000000..cb57a79e
--- /dev/null
+++ b/app/eg024_brand_creating.py
@@ -0,0 +1,165 @@
+"""Example 024: Creating a brand"""
+
+import json
+from os import path
+
+from docusign_esign import ApiClient, AccountsApi, Brand
+from docusign_esign.client.api_exception import ApiException
+from flask import render_template, url_for, redirect, session, flash, request
+
+from app import app, ds_config, views
+
+eg = 'eg024' # reference and url for this example
+
+LANGUAGES = {
+ "Arabic": "ar",
+ "Armenian": "hy",
+ "Bahasa Indonesia": "id",
+ "Bahasa Malay": "ms",
+ "Bulgarian": "bg",
+ "Chinese Simplified": "zh_CN",
+ "Chinese Traditional": "zh_TW",
+ "Croatian": "hr",
+ "Czech": "cs",
+ "Danish": "da",
+ "Dutch": "nl",
+ "English UK": "en_GB",
+ "English US": "en",
+ "Estonian": "et",
+ "Farsi": "fa",
+ "Finnish": "fi",
+ "French": "fr",
+ "French Canada": "fr_CA",
+ "German": "de",
+ "Greek": "el",
+ "Hebrew": "he",
+ "Hindi": "hi",
+ "Hungarian": "hu",
+ "Italian": "it",
+ "Japanese": "ja",
+ "Korean": "ko",
+ "Latvian": "lv",
+ "Lithuanian": "lt",
+ "Norwegian": "no",
+ "Polish": "pl",
+ "Portuguese": "pt",
+ "Portuguese Brasil": "pt_BR",
+ "Romanian": "ro",
+ "Russian": "ru",
+ "Serbian": "sr",
+ "Slovak": "sk",
+ "Slovenian": "sl",
+ "Spanish": "es",
+ "Spanish Latin America": "es_MX",
+ "Swedish": "sv",
+ "Thai": "th",
+ "Turkish": "tr",
+ "Ukrainian": "uk",
+ "Vietnamese": "vi"
+ }
+
+
+def controller():
+ """Controller router using the HTTP method"""
+ if request.method == "GET":
+ return get_controller()
+ elif request.method == "POST":
+ return create_controller()
+ else:
+ return render_template("404.html"), 404
+
+
+def create_controller():
+ """
+ 1. Check the token
+ 2. Call the worker method
+ 3. Render response
+ """
+ minimum_buffer_min = 3
+ if views.ds_token_ok(minimum_buffer_min):
+ # Step 1: Obtain your OAuth token
+ args = {
+ 'account_id': '213', # represent your {ACCOUNT_ID}
+ 'base_path': session['ds_base_path'],
+ 'access_token': session['ds_access_token'], # represent your {ACCESS_TOKEN}
+ 'brand_name': request.form.get('brand_name'),
+ 'default_language': request.form.get('default_language')
+ }
+ try:
+ # Step 2: Call the worker method to create a new brand
+ response = worker(args)
+ brand_id = response.brands[0].brand_id
+ app.logger.info(f"Brand has been created. Brand id {brand_id}")
+
+ # Step 3: Render response
+ return render_template('example_done.html',
+ title='Brand creating',
+ h1='Brand creating',
+ message=f"""The brand has been created and sent!
+ Brand ID {brand_id}."""
+ )
+
+ except ApiException as err:
+ error_body_json = err and hasattr(err, 'body') and err.body
+ # We can pull the DocuSign error code and message from the response body
+ error_body = json.loads(error_body_json)
+ error_code = error_body and 'errorCode' in error_body and error_body['errorCode']
+ error_message = error_body and "message" in error_body and error_body["message"]
+ # In production, you may want to provide customized error messages and
+ # remediation advice to the user
+ return render_template('error.html',
+ err=err,
+ error_code=error_code,
+ error_message=error_message
+ )
+
+ else:
+ flash("Sorry, you need to re-authenticate.")
+ # We could store the parameters of the requested operation so it could be restarted
+ # automatically. But since it should be rare to have a token issue here,
+ # we'll make the user re-enter the form data after authentication
+ session["eg"] = url_for(eg)
+ return redirect(url_for("ds_must_authenticate"))
+
+
+def worker(args):
+ """
+ 1. Create api client with headers
+ 2. Create a brand object
+ 3. Post the brand using SDK
+ """
+
+ # Step 1: create API client
+ api_client = ApiClient()
+ api_client.host = args['base_path']
+ api_client.set_default_header(header_name="Authorization", header_value=f"Bearer {args['access_token']}")
+
+ # Step 2: Create a brand object
+ brand = Brand(
+ brand_name=args['brand_name'],
+ default_brand_language=args['default_language'],
+ )
+
+ # Step 3: a) Call the eSignature SDK
+ # b) Display the JSON response
+ account_api = AccountsApi(api_client)
+ response = account_api.create_brand(account_id=args['account_id'], brand=brand)
+ return response
+
+
+def get_controller():
+ """Responds with the form for the example"""
+
+ if views.ds_token_ok():
+ return render_template("eg024_brand_creating.html",
+ title="Brand creating",
+ source_file=path.basename(__file__),
+ source_url=ds_config.DS_CONFIG["github_example_url"] + path.basename(__file__),
+ documentation=ds_config.DS_CONFIG["documentation"] + eg,
+ show_doc=ds_config.DS_CONFIG["documentation"],
+ languages=LANGUAGES
+ )
+ else:
+ # Save the current operation so it will be resumed after authentication
+ session["eg"] = url_for(eg)
+ return redirect(url_for("ds_must_authenticate"))
diff --git a/app/templates/eg024_brand_creating.html b/app/templates/eg024_brand_creating.html
new file mode 100644
index 00000000..e8656b82
--- /dev/null
+++ b/app/templates/eg024_brand_creating.html
@@ -0,0 +1,46 @@
+ {% extends "base.html" %} {% block content %}
+
+24. Create a new brand
+
+ The brand includes a Brand Name Configure Brands
+
+
+ This code example demonstrates how to create a brand.
+
+
+{% if show_doc %}
+ Documentation about this example.
+{% endif %}
+
+
+ API method used:
+ AccountBrands::create.
+
+
+
+ View source file {{ source_file }} on GitHub.
+
+
+
+
+{% endblock %}
diff --git a/app/templates/home.html b/app/templates/home.html
index 6db4eabf..16164d1e 100644
--- a/app/templates/home.html
+++ b/app/templates/home.html
@@ -231,6 +231,18 @@
+
+ Brands
+
+
+
+ Creating a brand
+
+
+ API method used:
+ AccountBrands::create.
+
+
diff --git a/app/views.py b/app/views.py
index 70912997..a791c2ae 100644
--- a/app/views.py
+++ b/app/views.py
@@ -16,7 +16,8 @@
eg016_set_tab_values, eg017_set_template_tab_values, \
eg018_envelope_custom_field_data, eg019_access_code_authentication, \
eg020_sms_authentication, eg021_phone_authentication, \
- eg022_kba_authentication, eg023_idv_authentication
+ eg022_kba_authentication, eg023_idv_authentication, \
+ eg024_brand_creating
@app.route("/")
@@ -149,6 +150,11 @@ def eg023():
return eg023_idv_authentication.controller()
+@app.route("/eg024", methods=["GET", "POST"])
+def eg024():
+ return eg024_brand_creating.controller()
+
+
@app.route("/ds_return")
def ds_return():
event = request.args.get("event")
From 0a20435a75981087280c56f735cec3c59ae05f4e Mon Sep 17 00:00:00 2001
From: Oleksii Semko
Date: Mon, 27 Jan 2020 13:12:18 +0200
Subject: [PATCH 2/3] implemented brands apply to envelope example
---
app/eg025_brands_apply_to_envelope.py | 212 ++++++++++++++++++
.../eg025_brands_apply_to_envelope.html | 56 +++++
app/templates/home.html | 11 +-
app/views.py | 7 +-
4 files changed, 284 insertions(+), 2 deletions(-)
create mode 100644 app/eg025_brands_apply_to_envelope.py
create mode 100644 app/templates/eg025_brands_apply_to_envelope.html
diff --git a/app/eg025_brands_apply_to_envelope.py b/app/eg025_brands_apply_to_envelope.py
new file mode 100644
index 00000000..a4f891f1
--- /dev/null
+++ b/app/eg025_brands_apply_to_envelope.py
@@ -0,0 +1,212 @@
+"""Example 025: Applying a brand to an envelope"""
+
+from flask import render_template, url_for, redirect, session, flash, request
+from os import path
+from app import app, ds_config, views
+import base64
+import json
+import re
+from docusign_esign import ApiClient, EnvelopesApi, Document, Signer, SignHere, EnvelopeDefinition, Tabs, Recipients, \
+ AccountsApi
+from docusign_esign.client.api_exception import ApiException
+
+eg = 'eg025' # reference and url for this example
+demo_docs_path = path.abspath(path.join(path.dirname(path.realpath(__file__)), "static/demo_documents"))
+doc_file = "World_Wide_Corp_lorem.pdf"
+
+
+def controller():
+ """Controller router using the HTTP method"""
+ if request.method == "GET":
+ return get_controller()
+ elif request.method == "POST":
+ return create_controller()
+ else:
+ return render_template("404.html"), 404
+
+
+def create_controller():
+ """
+ 1. Check the token
+ 2. Call the worker method
+ 3. Render response
+ """
+ minimum_buffer_min = 3
+ if views.ds_token_ok(minimum_buffer_min):
+
+ # More data validation would be a good idea here
+ # Strip anything other than the characters listed
+ pattern = re.compile("([^\w \-\@\.\,])+")
+ signer_email = pattern.sub("", request.form.get("signer_email"))
+ signer_name = pattern.sub("", request.form.get("signer_name"))
+
+ # Step 1: Obtain your OAuth token
+ args = {
+ 'account_id': session['ds_account_id'], # represent your {ACCOUNT_ID}
+ 'base_path': session['ds_base_path'],
+ 'access_token': session['ds_access_token'], # represent your {ACCESS_TOKEN}
+ 'envelope_args': {
+ 'signer_name': signer_name,
+ 'signer_email': signer_email,
+ 'brand_id': request.form.get('brand')
+ }
+
+ }
+ try:
+ # Step 2: Call the worker method to apply brand to the envelope
+ response = worker(args)
+ envelope_id = response.envelope_id
+ app.logger.info(f"Brand has been applied to envelope. Envelope id {envelope_id}")
+
+ # Step 3: Render a response
+ return render_template('example_done.html',
+ title='Brand applying to envelope',
+ h1='Brand applying to envelope',
+ message=f"""The brand has been applied to envelope!
+ Envelope ID: {envelope_id}."""
+ )
+
+ except ApiException as err:
+ error_body_json = err and hasattr(err, 'body') and err.body
+ # We can pull the DocuSign error code and message from the response body
+ error_body = json.loads(error_body_json)
+ error_code = error_body and 'errorCode' in error_body and error_body['errorCode']
+ error_message = error_body and "message" in error_body and error_body["message"]
+ # In production, you may want to provide customized error messages and
+ # remediation advice to the user
+ return render_template('error.html',
+ err=err,
+ error_code=error_code,
+ error_message=error_message
+ )
+
+ else:
+ flash("Sorry, you need to re-authenticate.")
+ # We could store the parameters of the requested operation so it could be restarted
+ # automatically. But since it should be rare to have a token issue here,
+ # we'll make the user re-enter the form data after authentication
+ session["eg"] = url_for(eg)
+ return redirect(url_for("ds_must_authenticate"))
+
+
+def worker(args):
+ """
+ 1. Call create_api_client method
+ 2. Call make_envelope method
+ 3. Apply the brand to the envelope using SDK
+ """
+
+ # Step 1: Call create_api_client method
+ api_client = create_api_client(args)
+
+ # Step 2: Call make_envelope method
+ envelope_api = EnvelopesApi(api_client)
+ envelope_definition = make_envelope(args['envelope_args'])
+
+ # Step 3: Apply the brand to the envelope using SDK
+ response = envelope_api.create_envelope(args['account_id'], envelope_definition=envelope_definition)
+
+ return response
+
+
+def create_api_client(args):
+ """Create api client and construct API headers"""
+ api_client = ApiClient()
+ api_client.host = args['base_path']
+ api_client.set_default_header(header_name="Authorization", header_value=f"Bearer {args['access_token']}")
+
+ return api_client
+
+
+def make_envelope(args):
+ """
+ Creates envelope
+ """
+
+ # Open example file
+ with open(path.join(demo_docs_path, doc_file), "rb") as file:
+ content_bytes = file.read()
+ base64_file_content = base64.b64encode(content_bytes).decode("ascii")
+
+ document = Document(
+ document_base64=base64_file_content,
+ name='lorem',
+ file_extension='pdf',
+ document_id=1
+ )
+
+ signer = Signer(
+ email=args['signer_email'],
+ name=args['signer_name'],
+ recipient_id="1",
+ routing_order="1"
+ )
+
+ sign_here = SignHere(
+ anchor_string='/sn1/',
+ anchor_units='pixels',
+ anchor_y_offset="572",
+ anchor_x_offset="75"
+ )
+
+ signer.tabs = Tabs(sign_here_tabs=[sign_here])
+
+ envelope_definition = EnvelopeDefinition(
+ email_subject='Please Sign',
+ documents=[document],
+ recipients=Recipients(signers=[signer]),
+ status='sent',
+ brand_id=args['brand_id'],
+ )
+
+ return envelope_definition
+
+
+def get_brands():
+ """Retrieve all brands using the AccountBrands::List"""
+ args = {
+ 'account_id': session['ds_account_id'], # represent your {ACCOUNT_ID}
+ 'base_path': session['ds_base_path'],
+ 'access_token': session['ds_access_token'], # represent your {ACCESS_TOKEN}
+
+ }
+ api_client = create_api_client(args)
+ try:
+ account_api = AccountsApi(api_client)
+ response = account_api.list_brands(args['account_id'])
+ return response.brands
+ except ApiException as err:
+ error_body_json = err and hasattr(err, 'body') and err.body
+ # We can pull the DocuSign error code and message from the response body
+ error_body = json.loads(error_body_json)
+ error_code = error_body and 'errorCode' in error_body and error_body['errorCode']
+ error_message = error_body and "message" in error_body and error_body["message"]
+ # In production, you may want to provide customized error messages and
+ # remediation advice to the user
+ return render_template('error.html',
+ err=err,
+ error_code=error_code,
+ error_message=error_message
+ )
+
+
+def get_controller():
+ """Responds with the form for the example"""
+ if views.ds_token_ok():
+ # Get all brands to render it in the template
+ brands = get_brands()
+
+ return render_template("eg025_brands_apply_to_envelope.html",
+ title="Applying a brand to a template",
+ source_file=path.basename(__file__),
+ source_url=ds_config.DS_CONFIG["github_example_url"] + path.basename(__file__),
+ documentation=ds_config.DS_CONFIG["documentation"] + eg,
+ show_doc=ds_config.DS_CONFIG["documentation"],
+ brands=brands,
+ signer_name=ds_config.DS_CONFIG["signer_name"],
+ signer_email=ds_config.DS_CONFIG["signer_email"]
+ )
+ else:
+ # Save the current operation so it will be resumed after authentication
+ session["eg"] = url_for(eg)
+ return redirect(url_for("ds_must_authenticate"))
diff --git a/app/templates/eg025_brands_apply_to_envelope.html b/app/templates/eg025_brands_apply_to_envelope.html
new file mode 100644
index 00000000..50f47600
--- /dev/null
+++ b/app/templates/eg025_brands_apply_to_envelope.html
@@ -0,0 +1,56 @@
+ {% extends "base.html" %} {% block content %}
+
+ 25. {{ title }}
+
+ The envelope includes a pdf document.
+
+
+
+ This code example demonstrates how to apply a brand to an envelope.
+
+
+ {% if show_doc %}
+ Documentation about this example.
+ {% endif %}
+
+
+ Api method used:
+ Envelopes::Create and
+ AccountBrands::List
+
+
+
+ View source file {{ source_file }} on GitHub.
+
+
+
+{% endblock %}
\ No newline at end of file
diff --git a/app/templates/home.html b/app/templates/home.html
index 16164d1e..51686413 100644
--- a/app/templates/home.html
+++ b/app/templates/home.html
@@ -231,7 +231,6 @@
+ Applies brand to an envelop
+
+
+ API method used:
+ Envelopes::Create and
+ AccountBrands::List
+
+
diff --git a/app/views.py b/app/views.py
index a791c2ae..8d1667e3 100644
--- a/app/views.py
+++ b/app/views.py
@@ -17,7 +17,7 @@
eg018_envelope_custom_field_data, eg019_access_code_authentication, \
eg020_sms_authentication, eg021_phone_authentication, \
eg022_kba_authentication, eg023_idv_authentication, \
- eg024_brand_creating
+ eg024_brand_creating, eg025_brands_apply_to_envelope
@app.route("/")
@@ -155,6 +155,11 @@ def eg024():
return eg024_brand_creating.controller()
+@app.route("/eg025", methods=["GET", "POST"])
+def eg025():
+ return eg025_brands_apply_to_envelope.controller()
+
+
@app.route("/ds_return")
def ds_return():
event = request.args.get("event")
From 7f1d033fad7b5880e5c4f9d8e2fc3bffcdc3064b Mon Sep 17 00:00:00 2001
From: Oleksii Semko
Date: Mon, 27 Jan 2020 19:09:19 +0200
Subject: [PATCH 3/3] implemented brands apply to template example
---
app/eg026_brands_apply_to_template.py | 218 ++++++++++++++++++
.../eg026_brands_apply_to_template.html | 78 +++++++
app/templates/home.html | 12 +
app/views.py | 8 +-
4 files changed, 315 insertions(+), 1 deletion(-)
create mode 100644 app/eg026_brands_apply_to_template.py
create mode 100644 app/templates/eg026_brands_apply_to_template.html
diff --git a/app/eg026_brands_apply_to_template.py b/app/eg026_brands_apply_to_template.py
new file mode 100644
index 00000000..3cac66db
--- /dev/null
+++ b/app/eg026_brands_apply_to_template.py
@@ -0,0 +1,218 @@
+"""Example 026: Applying a brand to an envelope"""
+
+from flask import render_template, url_for, redirect, session, flash, request
+from os import path
+from app import app, ds_config, views
+import json
+import re
+from docusign_esign import ApiClient, EnvelopesApi, EnvelopeDefinition, TemplateRole, AccountsApi, TemplatesApi
+from docusign_esign.client.api_exception import ApiException
+
+eg = 'eg026' # reference and url for this example
+
+
+def controller():
+ """Controller router using the HTTP method"""
+ if request.method == "GET":
+ return get_controller()
+ elif request.method == "POST":
+ return create_controller()
+ else:
+ return render_template("404.html"), 404
+
+
+def create_controller():
+ """
+ 1. Check the token
+ 2. Call the worker method
+ 3. Render a response
+ """
+ minimum_buffer_min = 3
+ if views.ds_token_ok(minimum_buffer_min):
+
+ # More data validation would be a good idea here
+ # Strip anything other than the characters listed
+ pattern = re.compile("([^\w \-\@\.\,])+")
+ signer_email = pattern.sub("", request.form.get("signer_email"))
+ signer_name = pattern.sub("", request.form.get("signer_name"))
+ cc_email = request.form.get('cc_email')
+ cc_name = request.form.get('cc_name')
+
+ if cc_email and cc_name:
+ cc_email = pattern.sub("", cc_email)
+ cc_name = pattern.sub("", cc_name)
+
+ # Step 1: Obtain your OAuth token
+ args = {
+ 'account_id': session['ds_account_id'], # represent your {ACCOUNT_ID}
+ 'base_path': session['ds_base_path'],
+ 'access_token': session['ds_access_token'], # represent your {ACCESS_TOKEN}
+ 'envelope_args': {
+ 'signer_name': signer_name,
+ 'signer_email': signer_email,
+ 'cc_name': cc_name,
+ 'cc_email': cc_email,
+ 'brand_id': request.form.get('brand'),
+ 'template_id': request.form.get('envelope_template')
+ }
+ }
+ try:
+ # Step 2: Call the worker method to apply the brand to the template
+ response = worker(args)
+ envelope_id = response.envelope_id
+ app.logger.info(f"Brand has been applied to envelope. Envelope id {envelope_id}")
+
+ return render_template('example_done.html',
+ title='Brand applying to a template',
+ h1='Brand applying to a template',
+ message=f"""The brand has been applied to the template!
+ Envelope ID: {envelope_id}."""
+ )
+
+ except ApiException as err:
+ error_body_json = err and hasattr(err, 'body') and err.body
+ # We can pull the DocuSign error code and message from the response body
+ error_body = json.loads(error_body_json)
+ error_code = error_body and 'errorCode' in error_body and error_body['errorCode']
+ error_message = error_body and "message" in error_body and error_body["message"]
+ # In production, you may want to provide customized error messages and
+ # remediation advice to the user
+ return render_template('error.html',
+ err=err,
+ error_code=error_code,
+ error_message=error_message
+ )
+
+ else:
+ flash("Sorry, you need to re-authenticate.")
+ # We could store the parameters of the requested operation so it could be restarted
+ # automatically. But since it should be rare to have a token issue here,
+ # we'll make the user re-enter the form data after authentication
+ session["eg"] = url_for(eg)
+ return redirect(url_for("ds_must_authenticate"))
+
+
+def worker(args):
+ """
+ 1. Call create_api_client method
+ 2. Call make_envelope method
+ 3. Apply the brand to the envelope using SDK
+ """
+
+ # Step 1: Call create_api_client method
+ api_client = create_api_client(args)
+
+ # Step 2: Call make_envelope method to create an envelope definition with Signer
+ envelope_api = EnvelopesApi(api_client)
+ envelope_definition = make_envelope(args['envelope_args'])
+
+ # Step 3: Apply the brand to the envelope using SDK
+ response = envelope_api.create_envelope(args['account_id'], envelope_definition=envelope_definition)
+
+ return response
+
+
+def create_api_client(args):
+ """Create api client and construct API headers"""
+ api_client = ApiClient()
+ api_client.host = args['base_path']
+ api_client.set_default_header(header_name="Authorization", header_value=f"Bearer {args['access_token']}")
+
+ return api_client
+
+
+def make_envelope(args):
+ """
+ Creates envelope
+ args -- parameters for the envelope:
+ signer_email, signer_name, signer_client_id
+ returns an envelope definition
+ """
+ # Create the envelope definition
+ envelope_definition = EnvelopeDefinition(
+ status='sent',
+ template_id=args['template_id'],
+ brand_id=args['brand_id']
+ )
+
+ signer = TemplateRole(
+ email=args['signer_email'],
+ name=args['signer_name'],
+ role_name='signer'
+ )
+
+ # In case, we have cc we add him to envelope definition
+ if args['cc_email'] and args['cc_name']:
+ cc = TemplateRole(
+ email=args['cc_email'],
+ name=args['cc_name'],
+ role_name='cc'
+ )
+
+ envelope_definition.template_roles = [signer, cc]
+
+ else:
+ envelope_definition.template_roles = [signer]
+
+ return envelope_definition
+
+
+def get_data():
+ """Retrieve brands and envelope templates"""
+ args = {
+ 'account_id': session['ds_account_id'], # represent your {ACCOUNT_ID}
+ 'base_path': session['ds_base_path'],
+ 'access_token': session['ds_access_token'], # represent your {ACCESS_TOKEN}
+ }
+ api_client = create_api_client(args)
+
+ try:
+ """Retrieve all brands using the AccountBrands::List"""
+ account_api = AccountsApi(api_client)
+ brands = account_api.list_brands(args['account_id']).brands
+
+ """Retrieve all templates using the Templates::List"""
+ template_api = TemplatesApi(api_client)
+ envelope_templates = template_api.list_templates(args['account_id']).envelope_templates
+
+ return brands, envelope_templates
+
+ except ApiException as err:
+ error_body_json = err and hasattr(err, 'body') and err.body
+ # We can pull the DocuSign error code and message from the response body
+ error_body = json.loads(error_body_json)
+ error_code = error_body and 'errorCode' in error_body and error_body['errorCode']
+ error_message = error_body and "message" in error_body and error_body["message"]
+ # In production, you may want to provide customized error messages and
+ # remediation advice to the user
+ return render_template('error.html',
+ err=err,
+ error_code=error_code,
+ error_message=error_message
+ )
+
+
+def get_controller():
+ """Responds with the form for the example"""
+ if views.ds_token_ok():
+ brands, templates = get_data()
+ return render_template("eg026_brands_apply_to_template.html",
+ title="Applying a brand to a template",
+ source_file=path.basename(__file__),
+ source_url=ds_config.DS_CONFIG["github_example_url"] + path.basename(__file__),
+ documentation=ds_config.DS_CONFIG["documentation"] + eg,
+ show_doc=ds_config.DS_CONFIG["documentation"],
+ brands=brands,
+ templates=templates,
+ signer_name=ds_config.DS_CONFIG["signer_name"],
+ signer_email=ds_config.DS_CONFIG["signer_email"],
+ )
+ else:
+ # Save the current operation so it will be resumed after authentication
+ session["eg"] = url_for(eg)
+ return redirect(url_for("ds_must_authenticate"))
+
+
+
+
+
diff --git a/app/templates/eg026_brands_apply_to_template.html b/app/templates/eg026_brands_apply_to_template.html
new file mode 100644
index 00000000..c4b706f7
--- /dev/null
+++ b/app/templates/eg026_brands_apply_to_template.html
@@ -0,0 +1,78 @@
+ {% extends "base.html" %} {% block content %}
+
+ 26. {{ title }}
+
+
+ This code example demonstrates how to apply a brand to a template.
+
+
+ {% if show_doc %}
+ Documentation about this example.
+ {% endif %}
+
+
+ Api method used:
+ Envelopes::Create,
+ AccountBrands::List and
+ Templates::List
+
+
+
+ View source file {{ source_file }} on GitHub.
+
+
+
+{% endblock %}
\ No newline at end of file
diff --git a/app/templates/home.html b/app/templates/home.html
index 51686413..0db818a6 100644
--- a/app/templates/home.html
+++ b/app/templates/home.html
@@ -231,6 +231,7 @@ 23. Send an envelope with ID Verification Au
Envelopes::create.
+
Brands
24. Create a new Brand
@@ -252,6 +253,17 @@ 25. Applying a brand to an envelope
AccountBrands::List
+ 26. Applying a brand to a template
+
+ Applies brand to a template
+
+
+ API method used:
+ Envelopes::Create,
+ AccountBrands::List and
+ Templates::List
+
+
diff --git a/app/views.py b/app/views.py
index 8d1667e3..dc7e2f00 100644
--- a/app/views.py
+++ b/app/views.py
@@ -17,7 +17,8 @@
eg018_envelope_custom_field_data, eg019_access_code_authentication, \
eg020_sms_authentication, eg021_phone_authentication, \
eg022_kba_authentication, eg023_idv_authentication, \
- eg024_brand_creating, eg025_brands_apply_to_envelope
+ eg024_brand_creating, eg025_brands_apply_to_envelope, \
+ eg026_brands_apply_to_template
@app.route("/")
@@ -160,6 +161,11 @@ def eg025():
return eg025_brands_apply_to_envelope.controller()
+@app.route("/eg026", methods=["GET", "POST"])
+def eg026():
+ return eg026_brands_apply_to_template.controller()
+
+
@app.route("/ds_return")
def ds_return():
event = request.args.get("event")