Package web :: Module fill_data
[hide private]
[frames] | no frames]

Source Code for Module web.fill_data

 1  #!/usr/bin/python 
 2  import db 
 3  import config 
 4  from user.model import User 
 5  from main.model import Computer, OrganizativeUnit 
 6   
 7  orm = db.connect() 
 8   
 9  # useradmin 
10  admin_password = u'1234567' 
11  admin = User(u'admin', admin_password, config.admin_email) 
12  admin.state = u'active' 
13  admin.super_user = True 
14  orm.add(admin) 
15  print ("User '%s' was created with password '%s', use it for login. " 
16      "You can (and should!) of course change it later") % (admin.name, admin_password) 
17   
18  orm.commit() 
19  #testuser 
20  test_user_password = u'1234567' 
21  test_user = User(u'test', test_user_password, config.admin_email) 
22  test_user.state = u'active' 
23  orm.add(test_user) 
24  print ("User '%s' was created with password '%s', use it for login. " 
25      "You can (and should!) of course change it later") % (test_user.name, test_user_password) 
26   
27  # user anonymous is needed so that permissions can be given to it. It will be in "disabled" 
28  # state so it won't be possible to login with it. 
29  anonymous_user = User(u'anonymous', '', config.noreply_email) 
30  orm.add(anonymous_user) 
31   
32  # some ou and computer examples. 
33   
34  uni = OrganizativeUnit(name = u'Universidad', 
35          description = u'Universidad de Sevilla') 
36  orm.add(uni) 
37   
38  facu = OrganizativeUnit(name = u'Facultad', 
39          description = u'Facultad de Informatica') 
40  orm.add(facu) 
41   
42  sugus = OrganizativeUnit(name = u'Aula A3.60', 
43          description = u'Sugus') 
44  orm.add(sugus) 
45   
46  alpha = OrganizativeUnit(name = u'Aula A4.10', 
47          description = u'Sala Alpha') 
48  orm.add(alpha) 
49   
50  fresa = Computer(name = u'fresa', mac = u'00:11:22:33:44:55', 
51          ip = u'192.168.1.2') 
52  orm.add(fresa) 
53   
54  choco = Computer(name = u'chocolate', mac = u'00:11:22:33:44:56', 
55          ip = u'192.168.1.3') 
56  orm.add(choco) 
57   
58  ord1 = Computer(name = u'ord1', mac = u'66:11:22:33:44:55', 
59          ip = u'192.168.10.2') 
60  orm.add(ord1) 
61   
62  ord2 = Computer(name = u'ord2', mac = u'66:11:22:33:44:56', 
63          ip = u'192.168.10.3') 
64  orm.add(ord2) 
65   
66  ord3 = Computer(name = u'ord3', mac = u'66:11:22:33:44:57', 
67          ip = u'192.168.10.4') 
68  orm.add(ord3) 
69   
70  orm.commit() 
71   
72  facu.parent_id = uni.id 
73  sugus.parent_id = facu.id 
74  alpha.parent_id = facu.id 
75  fresa.ou_id = sugus.id 
76  choco.ou_id = sugus.id 
77  ord1.ou_id = alpha.id 
78  ord2.ou_id = alpha.id 
79  ord3.ou_id = alpha.id 
80   
81  test_user.organizative_units = [sugus] 
82   
83  orm.commit() 
84