blob: 98eeaffe4ad60845955f979da1b40c875b65224c [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
Sapan Bhatia085ed482015-01-17 00:56:36 +00005
6 #controller = Controller.get(controller_id)
7
8
Tony Mackc231f212015-01-11 13:55:23 -05009 # relations for all sites
10 ctrls_by_site = defaultdict(list)
11 ctrl_sites = ControllerSite.objects.all()
12 for ctrl_site in ctrl_sites:
13 ctrls_by_site[ctrl_site.site].append(ctrl_site.controller)
14 sites = Site.objects.all()
15 for site in sites:
16 if site not in ctrls_by_site or \
17 controller not in ctrls_by_site[site]:
18 controller_site = ControllerSite(controller=controller, site=site)
Sapan Bhatia085ed482015-01-17 00:56:36 +000019 controller_site.save()
Tony Mackc231f212015-01-11 13:55:23 -050020 # relations for all slices
21 ctrls_by_slice = defaultdict(list)
22 ctrl_slices = ControllerSlice.objects.all()
23 for ctrl_slice in ctrl_slices:
24 ctrls_by_slice[ctrl_slice.slice].append(ctrl_slice.controller)
25 slices = Slice.objects.all()
26 for slice in slices:
27 if slice not in ctrls_by_slice or \
28 controller not in ctrls_by_slice:
29 controller_slice = ControllerSlice(controller=controller, slice=slice)
Sapan Bhatia085ed482015-01-17 00:56:36 +000030 controller_slice.save()
Tony Mackc231f212015-01-11 13:55:23 -050031 # relations for all users
32 ctrls_by_user = defaultdict(list)
33 ctrl_users = ControllerUser.objects.all()
34 for ctrl_user in ctrl_users:
35 ctrls_by_user[ctrl_user.user].append(ctrl_user.controller)
36 users = User.objects.all()
37 for user in users:
38 if user not in ctrls_by_user or \
39 controller not in ctrls_by_user[user]:
40 controller_user = ControllerUser(controller=controller, user=user)
Sapan Bhatia085ed482015-01-17 00:56:36 +000041 controller_user.save()