Tony Mack | 04ae02d | 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 | 485490d | 2015-01-17 00:56:36 +0000 | [diff] [blame] | 5 | |
| 6 | #controller = Controller.get(controller_id) |
| 7 | |
| 8 | |
Tony Mack | 04ae02d | 2015-01-11 13:55:23 -0500 | [diff] [blame] | 9 | # 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 Bhatia | 485490d | 2015-01-17 00:56:36 +0000 | [diff] [blame] | 19 | controller_site.save() |
Tony Mack | 04ae02d | 2015-01-11 13:55:23 -0500 | [diff] [blame] | 20 | # 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 Bhatia | 485490d | 2015-01-17 00:56:36 +0000 | [diff] [blame] | 30 | controller_slice.save() |
Tony Mack | 04ae02d | 2015-01-11 13:55:23 -0500 | [diff] [blame] | 31 | # 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 Bhatia | 485490d | 2015-01-17 00:56:36 +0000 | [diff] [blame] | 41 | controller_user.save() |