Scott Baker | af599eb | 2017-03-21 12:43:26 -0700 | [diff] [blame] | 1 | from synchronizers.new_base.modelaccessor import * |
Scott Baker | b63ea79 | 2016-08-11 10:24:48 -0700 | [diff] [blame] | 2 | |
Scott Baker | af599eb | 2017-03-21 12:43:26 -0700 | [diff] [blame] | 3 | def handle(user): |
Scott Baker | a0a688a | 2017-03-28 11:59:56 -0700 | [diff] [blame] | 4 | controller_users = ControllerUser.objects.filter(user_id=user.id) |
Scott Baker | b63ea79 | 2016-08-11 10:24:48 -0700 | [diff] [blame] | 5 | existing_controllers = [cu.controller for cu in controller_users] |
Scott Baker | a0a688a | 2017-03-28 11:59:56 -0700 | [diff] [blame] | 6 | existing_controller_ids = [c.id for c in existing_controllers] |
Scott Baker | b63ea79 | 2016-08-11 10:24:48 -0700 | [diff] [blame] | 7 | all_controllers = Controller.objects.all() |
| 8 | for controller in all_controllers: |
Scott Baker | a0a688a | 2017-03-28 11:59:56 -0700 | [diff] [blame] | 9 | if controller.id not in existing_controller_ids: |
Scott Baker | b63ea79 | 2016-08-11 10:24:48 -0700 | [diff] [blame] | 10 | ctrl_user = ControllerUser(controller=controller, user=user) |
| 11 | ctrl_user.save() |
| 12 | |