88
99
1010class Eg004AddUsersViaBulkImportController :
11+ @staticmethod
12+ def get_example_csv ():
13+ """
14+ Creates an example of a CSV file, such as that needs to be sent to the Docusign server
15+ """
16+
17+ # Returns an example of a CSV file
18+ return (
19+ "AccountID,UserName,UserEmail,PermissionSet\n "
20+ f"{ session ['ds_account_id' ]} ,Example User1,exampleuser1@example.com,DS Admin\n "
21+ f"{ session ['ds_account_id' ]} ,Example User2,exampleuser2@example.com,DS Admin\n "
22+ )
1123
1224 @staticmethod
1325 def worker (self , request ):
@@ -35,7 +47,16 @@ def worker(self, request):
3547 uploaded_file = request .files ['csv_file' ]
3648 csv_folder_path = path .abspath (path .join (path .dirname (path .realpath (__file__ )), "csv" ))
3749 csv_file_path = path .join (csv_folder_path , "uploaded_file.csv" )
38- uploaded_file .save (csv_file_path )
50+
51+ if uploaded_file and not uploaded_file .filename == '' :
52+ uploaded_file .save (csv_file_path )
53+ else :
54+ content = Eg004AddUsersViaBulkImportController .get_example_csv ()
55+
56+ modified_content = content .replace ("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" , session ["ds_account_id" ])
57+
58+ with open (csv_file_path , "w" ) as file :
59+ file .write (modified_content )
3960
4061 # Creating an import API object
4162 #ds-snippet-start:Admin4Step3
@@ -57,19 +78,6 @@ def worker(self, request):
5778
5879 return response
5980
60- @staticmethod
61- def get_example_csv ():
62- """
63- Creates an example of a CSV file, such as that needs to be sent to the Docusign server
64- """
65-
66- # Returns an example of a CSV file
67- return (
68- "AccountID,UserName,UserEmail,PermissionSet\n "
69- f"{ session ['ds_account_id' ]} ,Example User1,exampleuser1@example.com,DS Admin\n "
70- f"{ session ['ds_account_id' ]} ,Example User2,exampleuser2@example.com,DS Admin\n "
71- )
72-
7381 @staticmethod
7482 def check_status ():
7583 """Check request status"""
0 commit comments