Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8682090

Browse files
author
Balaji Jayaraman
committed
added delete and restore envelope how to code snippets
1 parent2da957c commit8682090

File tree

10 files changed

+268
-4
lines changed

10 files changed

+268
-4
lines changed

‎app/__init__.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
app.register_blueprint(esignature_views.eg042)
115115
app.register_blueprint(esignature_views.eg043)
116116
app.register_blueprint(esignature_views.eg044)
117+
app.register_blueprint(esignature_views.eg045)
117118

118119
app.register_blueprint(connect_views.cneg001)
119120

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
fromdocusign_esignimportFoldersApi,FoldersRequest
2+
3+
from ...docusignimportcreate_api_client
4+
5+
6+
classEg045DeleteRestoreEnvelopeController:
7+
@staticmethod
8+
defdelete_envelope(args):
9+
#ds-snippet-start:eSign45Step2
10+
api_client=create_api_client(base_path=args["base_path"],access_token=args["access_token"])
11+
folders_api=FoldersApi(api_client)
12+
#ds-snippet-end:eSign45Step2
13+
14+
#ds-snippet-start:eSign45Step3
15+
folders_request=FoldersRequest(
16+
envelope_ids=[args["envelope_id"]]
17+
)
18+
#ds-snippet-end:eSign45Step3
19+
20+
#ds-snippet-start:eSign45Step4
21+
results=folders_api.move_envelopes(account_id=args["account_id"],folder_id=args["delete_folder_id"],folders_request=folders_request)
22+
#ds-snippet-end:eSign45Step4
23+
returnresults
24+
25+
@staticmethod
26+
defmove_envelope_to_folder(args):
27+
api_client=create_api_client(base_path=args["base_path"],access_token=args["access_token"])
28+
folders_api=FoldersApi(api_client)
29+
30+
#ds-snippet-start:eSign45Step6
31+
folders_request=FoldersRequest(
32+
envelope_ids=[args["envelope_id"]],
33+
from_folder_id=args["from_folder_id"]
34+
)
35+
36+
results=folders_api.move_envelopes(account_id=args["account_id"],folder_id=args["folder_id"],folders_request=folders_request)
37+
#ds-snippet-end:eSign45Step6
38+
returnresults
39+
40+
@staticmethod
41+
defget_folders(args):
42+
api_client=create_api_client(base_path=args["base_path"],access_token=args["access_token"])
43+
folders_api=FoldersApi(api_client)
44+
45+
#ds-snippet-start:eSign45Step5
46+
results=folders_api.list(account_id=args["account_id"])
47+
#ds-snippet-end:eSign45Step5
48+
returnresults

‎app/eSignature/utils.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
defget_folder_id_by_name(folders,folder_name):
2+
forfolderinfolders:
3+
iffolder.name.lower()==folder_name.lower():
4+
returnfolder.folder_id
5+
6+
subfolders=folder.folders
7+
ifsubfoldersisnotNoneandlen(subfolders)>0:
8+
folder_id=get_folder_id_by_name(subfolders,folder_name)
9+
iffolder_idisnotNone:
10+
returnfolder_id

‎app/eSignature/views/__init__.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,4 @@
4141
from .eg042_document_generationimporteg042
4242
from .eg043_shared_accessimporteg043
4343
from .eg044_focused_viewimporteg044
44+
from .eg045_delete_restore_envelopeimporteg045
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
""" Example 045: Delete and undelete an Envelope """
2+
3+
fromosimportpath
4+
5+
fromdocusign_esign.client.api_exceptionimportApiException
6+
fromflaskimportrender_template,session,Blueprint,request,redirect
7+
8+
from ..examples.eg045_delete_restore_envelopeimportEg045DeleteRestoreEnvelopeController
9+
from ..utilsimportget_folder_id_by_name
10+
from ...docusignimportauthenticate,ensure_manifest,get_example_by_number
11+
from ...ds_configimportDS_CONFIG
12+
from ...error_handlersimportprocess_error
13+
from ...constsimportpattern,API_TYPE
14+
15+
example_number=45
16+
api=API_TYPE["ESIGNATURE"]
17+
eg=f"eg0{example_number}"# reference (and url) for this example
18+
restore_endpoint=f"{eg}restore"
19+
delete_folder_id="recyclebin"
20+
restore_folder_id="sentitems"
21+
eg045=Blueprint(eg,__name__)
22+
23+
@eg045.route(f"/{eg}",methods=["POST"])
24+
@authenticate(eg=eg,api=api)
25+
@ensure_manifest(manifest_url=DS_CONFIG["example_manifest_url"])
26+
defdelete_envelope():
27+
"""
28+
1. Get required arguments
29+
2. Call the worker method
30+
3. Render success response
31+
"""
32+
33+
# 1. Get required arguments
34+
args= {
35+
"account_id":session["ds_account_id"],
36+
"base_path":session["ds_base_path"],
37+
"access_token":session["ds_access_token"],
38+
"envelope_id":pattern.sub("",request.form.get("envelope_id")),
39+
"delete_folder_id":delete_folder_id
40+
}
41+
try:
42+
# 2. Call the worker method
43+
Eg045DeleteRestoreEnvelopeController.delete_envelope(args)
44+
exceptApiExceptionaserr:
45+
returnprocess_error(err)
46+
47+
session["envelope_id"]=args["envelope_id"]# Save for use by second part of example
48+
49+
# 3. Render success response
50+
example=get_example_by_number(session["manifest"],example_number,api)
51+
additional_page_data=next(
52+
(pforpinexample["AdditionalPage"]ifp["Name"]=="envelope_is_deleted"),
53+
None
54+
)
55+
returnrender_template(
56+
"example_done.html",
57+
title=example["ExampleName"],
58+
message=additional_page_data["ResultsPageText"].format(args["envelope_id"]),
59+
redirect_url=restore_endpoint
60+
)
61+
62+
@eg045.route(f"/{restore_endpoint}",methods=["POST"])
63+
@authenticate(eg=eg,api=api)
64+
@ensure_manifest(manifest_url=DS_CONFIG["example_manifest_url"])
65+
defrestore_envelope():
66+
"""
67+
1. Get required arguments
68+
2. Call the worker method
69+
3. Render success response
70+
"""
71+
72+
# 1. Get required arguments
73+
folder_name=pattern.sub("",request.form.get("folder_name"))
74+
args= {
75+
"account_id":session["ds_account_id"],
76+
"base_path":session["ds_base_path"],
77+
"access_token":session["ds_access_token"],
78+
"envelope_id":pattern.sub("",session.get("envelope_id")),
79+
"from_folder_id":delete_folder_id
80+
}
81+
82+
example=get_example_by_number(session["manifest"],example_number,api)
83+
try:
84+
# 2. Call the worker method
85+
folders=Eg045DeleteRestoreEnvelopeController.get_folders(args)
86+
args["folder_id"]=get_folder_id_by_name(folders.folders,folder_name)
87+
88+
ifargs["folder_id"]isNone:
89+
additional_page_data=next(
90+
(pforpinexample["AdditionalPage"]ifp["Name"]=="folder_does_not_exist"),
91+
None
92+
)
93+
94+
returnrender_template(
95+
"example_done.html",
96+
title=example["ExampleName"],
97+
message=additional_page_data["ResultsPageText"].format(folder_name),
98+
redirect_url=restore_endpoint
99+
)
100+
101+
Eg045DeleteRestoreEnvelopeController.move_envelope_to_folder(args)
102+
exceptApiExceptionaserr:
103+
returnprocess_error(err)
104+
105+
# 3. Render success response with envelopeId
106+
returnrender_template(
107+
"example_done.html",
108+
title=example["ExampleName"],
109+
message=example["ResultsPageText"].format(session.get("envelope_id",""),args["folder_id"],folder_name)
110+
)
111+
112+
@eg045.route(f"/{eg}",methods=["GET"])
113+
@ensure_manifest(manifest_url=DS_CONFIG["example_manifest_url"])
114+
@authenticate(eg=eg,api=api)
115+
defget_view():
116+
"""responds with the form for the example"""
117+
example=get_example_by_number(session["manifest"],example_number,api)
118+
119+
returnrender_template(
120+
"eSignature/eg045_delete_envelope.html",
121+
title=example["ExampleName"],
122+
example=example,
123+
envelope_id=session.get("envelope_id",""),
124+
submit_button_text=session["manifest"]["SupportingTexts"]["HelpingTexts"]["SubmitButtonDeleteText"],
125+
source_file="eg045_delete_restore_envelope.py",
126+
source_url=DS_CONFIG["github_example_url"]+"eg045_delete_restore_envelope.py",
127+
documentation=DS_CONFIG["documentation"]+eg,
128+
show_doc=DS_CONFIG["documentation"],
129+
signer_name=DS_CONFIG["signer_name"],
130+
signer_email=DS_CONFIG["signer_email"]
131+
)
132+
133+
@eg045.route(f"/{restore_endpoint}",methods=["GET"])
134+
@ensure_manifest(manifest_url=DS_CONFIG["example_manifest_url"])
135+
@authenticate(eg=eg,api=api)
136+
defget_restore_view():
137+
"""responds with the form for the example"""
138+
example=get_example_by_number(session["manifest"],example_number,api)
139+
140+
ifnotsession.get("envelope_id"):
141+
returnredirect(eg)
142+
143+
returnrender_template(
144+
"eSignature/eg045_restore_envelope.html",
145+
title=example["ExampleName"],
146+
example=example,
147+
envelope_id=session.get("envelope_id"),
148+
submit_button_text=session["manifest"]["SupportingTexts"]["HelpingTexts"]["SubmitButtonRestoreText"],
149+
source_file="eg045_delete_restore_envelope.py",
150+
source_url=DS_CONFIG["github_example_url"]+"eg045_delete_restore_envelope.py",
151+
documentation=DS_CONFIG["documentation"]+eg,
152+
show_doc=DS_CONFIG["documentation"],
153+
signer_name=DS_CONFIG["signer_name"],
154+
signer_email=DS_CONFIG["signer_email"]
155+
)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!-- extend base layout --> {% extends "base.html" %} {% block content %}
2+
3+
{% include 'example_info.html' %}
4+
5+
{% set form_index = 0 %}
6+
{% set envelope_id_index = 0 %}
7+
8+
<formclass="eg"action=""method="post"data-busy="form">
9+
{% if 'FormName' in example['Forms'][form_index] %}
10+
<p>{{ example['Forms'][form_index]['FormName'] | safe }}</p>
11+
{% endif %}
12+
13+
<divclass="form-group">
14+
<labelfor="envelope_id">{{ example['Forms'][form_index]['Inputs'][envelope_id_index]['InputName'] }}</label>
15+
<inputtype="text"class="form-control"id="envelope_id"name="envelope_id"
16+
aria-describedby="envelope_id_help"placeholder="{{ example['Forms'][form_index]['Inputs'][envelope_id_index]['InputPlaceholder'] }}"required
17+
value="{{ envelope_id }}"/>
18+
<smallid="envelope_id_help"class="form-text text-muted">{{ session['manifest']['SupportingTexts']['HelpingTexts']['DefaultEnvelopeId'] | safe}}</small>
19+
</div>
20+
<inputtype="hidden"name="csrf_token"value="{{ csrf_token() }}"/>
21+
{% include 'submit_button.html' %}
22+
</form>
23+
24+
{% endblock %}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!-- extend base layout --> {% extends "base.html" %} {% block content %}
2+
3+
<h4>{{ title }}</h4>
4+
<p>{{ example["ExampleDescription"] | safe }}</p>
5+
<p>{{ session["manifest"]["SupportingTexts"]["HelpingTexts"]["EnvelopeWillBeRestored"].format(envelope_id) | safe }}</p>
6+
7+
{% set form_index = 0 %}
8+
{% set folder_name_index = 1 %}
9+
10+
<formclass="eg"action=""method="post"data-busy="form">
11+
{% if 'FormName' in example['Forms'][form_index] %}
12+
<p>{{ example['Forms'][form_index]['FormName'] | safe }}</p>
13+
{% endif %}
14+
15+
<divclass="form-group">
16+
<labelfor="folder_name">{{ example['Forms'][form_index]['Inputs'][folder_name_index]['InputName'] }}</label>
17+
<inputtype="text"class="form-control"id="folder_name"name="folder_name"
18+
placeholder="{{ example['Forms'][form_index]['Inputs'][folder_name_index]['InputPlaceholder'] }}"required/>
19+
</div>
20+
21+
<inputtype="hidden"name="csrf_token"value="{{ csrf_token() }}"/>
22+
{% include 'submit_button.html' %}
23+
</form>
24+
25+
{% endblock %}

‎app/templates/example_info.html‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ <h4>{{ title }}</h4>
55
<p><atarget='_blank'href='{{ documentation | safe }}'>Documentation</a> about this example.</p>
66
{% endif %}
77

8-
{% if "Note" in example %}
9-
<p>{{ example["Note"] | safe }}</p>
8+
{% if "Notes" in example %}
9+
<p>{{ example["Notes"] | safe }}</p>
1010
{% endif %}
1111

1212
{% if example["LinksToAPIMethod"] | length> 0 %}

‎app/templates/submit_button.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<buttontype="submit"class="btn btn-docu">{{ session['manifest']['SupportingTexts']['SubmitButton'] }}</button>
1+
<buttontype="submit"class="btn btn-docu">{{submit_button_text if submit_button_text elsesession['manifest']['SupportingTexts']['SubmitButton'] }}</button>

‎requirements.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ cffi==1.17.1
44
chardet==5.2.0
55
Click
66
cryptography==45.0.3
7-
docusign-esign==5.0.0
7+
docusign-esign==5.3.0
88
docusign-rooms==1.3.0
99
docusign-monitor==1.2.0
1010
docusign-click==1.4.0

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp