Adding multiple users¶
Adding multiple users¶
1# This example creates many new CAD and n_server users in the database.
2
3
4# Create a local variable for the output toolbox
5ot = impact.gui.output_toolbox
6db = impact.active_database
7
8publish_to_enterprise = False
9
10
11# Function for padding numbers to 4 characters
12def left_pad(i):
13 _result = None
14 Str = str(i)
15 if 4 > len(Str):
16 _result = ("0") * (4 - len(Str)) + Str
17 else:
18 _result = Str
19 return _result
20
21
22# Clear the output toolbox
23ot.clear()
24
25# Retrieve the users from the DB
26users = db.users
27
28# Get the first site in the DB (may not be any though)
29sites = db.sites
30
31if sites.count > 0:
32 site = sites.item(1)
33
34# Get the first user group from the DB
35mastersettings = db.find_master_tool_settings(ipMasterSettingType.mstUserGroup)
36usergroup = mastersettings.item(1)
37
38ot.add("UserGroup: " + str(usergroup.name))
39if not site.isNone():
40 ot.add("Site: " + str(site.full_name))
41
42# Create some CAD users
43for i in range(1, 1000 + 1):
44 i_str = left_pad(i)
45 new_user = users.add2("DESIGNER" + str(i_str), "Designer " + str(i_str), "password", "designer" + str(i_str) + "@sabretech.co.nz", ipUserType.utCAD, site, usergroup, publish_to_enterprise)
46
47 if not new_user.isNone():
48 ot.add("Successfully added CAD user " + str(new_user.formatted_name))
49
50# Create some n_server users
51for i in range(1, 4000 + 1):
52 i_str = left_pad(i)
53 new_user = users.add2("WEBCNX" + str(i_str), "WEBcnx " + str(i_str), "password", "webcnx" + str(i_str) + "@sabretech.co.nz", ipUserType.utNServer, site, usergroup, publish_to_enterprise)
54
55 if not new_user.isNone():
56 ot.add("Successfully added NServer " + str(new_user.formatted_name))