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
8# Retrieve the users from the DB
9users = db.users
10
11# Get the first site in the DB (may not be any though)
12sites = db.sites
13
14publish_to_enterprise = False
15
16
17# Function for padding numbers to 4 characters
18def left_pad(i):
19 _result = None
20 Str = Str(i)
21 if 4 > len(Str):
22 _result = ("0") * (4 - len(Str)) + Str
23 return _result
24 else:
25 left_pad = Str
26
27
28# Clear the output toolbox
29ot.clear()
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
42publish_to_enterprise = False
43
44# Create some CAD users
45for i in range(1, 1000 + 1):
46 i_str = left_pad(i)
47 new_user = users.add2("DESIGNER" + i_str, "Designer " + i_str, "password", "designer" + Str(i_str) + "@sabretech.co.nz", ipUserType.utCAD, site, usergroup, publish_to_enterprise)
48
49 if new_user is not None:
50 ot.add("Successfully added CAD user " + Str(new_user.formatted_name))
51
52# Create some n_server users
53for i in range(1, 4000 + 1):
54 i_str = left_pad(i)
55 new_user = users.add2("WEBCNX" + i_str, "WEBcnx " + i_str, "password", "webcnx" + Str(i_str) + "@sabretech.co.nz", ipUserType.utNServer, site, usergroup, publish_to_enterprise)
56
57 if new_user is not None:
58 ot.add("Successfully added NServer " + Str(new_user.formatted_name))