blob: 6d73e0c2822c4761b9d2451ce32b1937046740bd [file] [log] [blame]
Tony Mack04ae02d2015-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 Bhatia485490d2015-01-17 00:56:36 +00005
Tony Mack04ae02d2015-01-11 13:55:23 -05006 # relations for all sites
7 ctrls_by_site = defaultdict(list)
8 ctrl_sites = ControllerSite.objects.all()
9 for ctrl_site in ctrl_sites:
10 ctrls_by_site[ctrl_site.site].append(ctrl_site.controller)
11 sites = Site.objects.all()
12 for site in sites:
13 if site not in ctrls_by_site or \
14 controller not in ctrls_by_site[site]:
15 controller_site = ControllerSite(controller=controller, site=site)
Sapan Bhatia485490d2015-01-17 00:56:36 +000016 controller_site.save()
Tony Mack04ae02d2015-01-11 13:55:23 -050017 # relations for all slices
18 ctrls_by_slice = defaultdict(list)
19 ctrl_slices = ControllerSlice.objects.all()
20 for ctrl_slice in ctrl_slices:
21 ctrls_by_slice[ctrl_slice.slice].append(ctrl_slice.controller)
22 slices = Slice.objects.all()
23 for slice in slices:
24 if slice not in ctrls_by_slice or \
25 controller not in ctrls_by_slice:
26 controller_slice = ControllerSlice(controller=controller, slice=slice)
Sapan Bhatia485490d2015-01-17 00:56:36 +000027 controller_slice.save()
Tony Mack04ae02d2015-01-11 13:55:23 -050028 # relations for all users
29 ctrls_by_user = defaultdict(list)
30 ctrl_users = ControllerUser.objects.all()
31 for ctrl_user in ctrl_users:
32 ctrls_by_user[ctrl_user.user].append(ctrl_user.controller)
33 users = User.objects.all()
34 for user in users:
35 if user not in ctrls_by_user or \
36 controller not in ctrls_by_user[user]:
37 controller_user = ControllerUser(controller=controller, user=user)
Sapan Bhatia485490d2015-01-17 00:56:36 +000038 controller_user.save()