blob: 9415bb50c09ec3732808591723391f658a54702c [file] [log] [blame]
Tony Mackc231f212015-01-11 13:55:23 -05001
2def handle(controller):
3 from core.models import Controller, Site, ControllerSite, Slice, ControllerSlice, User, ControllerUser
4 from collections import defaultdict
5 # relations for all sites
6 ctrls_by_site = defaultdict(list)
7 ctrl_sites = ControllerSite.objects.all()
8 for ctrl_site in ctrl_sites:
9 ctrls_by_site[ctrl_site.site].append(ctrl_site.controller)
10 sites = Site.objects.all()
11 for site in sites:
12 if site not in ctrls_by_site or \
13 controller not in ctrls_by_site[site]:
14 controller_site = ControllerSite(controller=controller, site=site)
15 controller_site.save()
16 # relations for all slices
17 ctrls_by_slice = defaultdict(list)
18 ctrl_slices = ControllerSlice.objects.all()
19 for ctrl_slice in ctrl_slices:
20 ctrls_by_slice[ctrl_slice.slice].append(ctrl_slice.controller)
21 slices = Slice.objects.all()
22 for slice in slices:
23 if slice not in ctrls_by_slice or \
24 controller not in ctrls_by_slice:
25 controller_slice = ControllerSlice(controller=controller, slice=slice)
26 controller_slice.save()
27 # relations for all users
28 ctrls_by_user = defaultdict(list)
29 ctrl_users = ControllerUser.objects.all()
30 for ctrl_user in ctrl_users:
31 ctrls_by_user[ctrl_user.user].append(ctrl_user.controller)
32 users = User.objects.all()
33 for user in users:
34 if user not in ctrls_by_user or \
35 controller not in ctrls_by_user[user]:
36 controller_user = ControllerUser(controller=controller, user=user)
37 controller_user.save()
38
39
40
41