Tony Mack | c231f21 | 2015-01-11 13:55:23 -0500 | [diff] [blame] | 1 | |
| 2 | def handle(controller): |
| 3 | from core.models import Controller, Site, ControllerSite, Slice, ControllerSlice, User, ControllerUser |
| 4 | from collections import defaultdict |
Sapan Bhatia | 085ed48 | 2015-01-17 00:56:36 +0000 | [diff] [blame] | 5 | |
Tony Mack | c231f21 | 2015-01-11 13:55:23 -0500 | [diff] [blame] | 6 | # 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 Bhatia | 085ed48 | 2015-01-17 00:56:36 +0000 | [diff] [blame] | 16 | controller_site.save() |
Tony Mack | c231f21 | 2015-01-11 13:55:23 -0500 | [diff] [blame] | 17 | # 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 Bhatia | 085ed48 | 2015-01-17 00:56:36 +0000 | [diff] [blame] | 27 | controller_slice.save() |
Tony Mack | c231f21 | 2015-01-11 13:55:23 -0500 | [diff] [blame] | 28 | # 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 Bhatia | 085ed48 | 2015-01-17 00:56:36 +0000 | [diff] [blame] | 38 | controller_user.save() |