Scott Baker | af599eb | 2017-03-21 12:43:26 -0700 | [diff] [blame] | 1 | from synchronizers.new_base.modelaccessor import * |
Scott Baker | 46a3ee9 | 2017-05-30 16:44:56 -0700 | [diff] [blame] | 2 | from synchronizers.new_base.policy import Policy |
Scott Baker | b63ea79 | 2016-08-11 10:24:48 -0700 | [diff] [blame] | 3 | |
Scott Baker | 46a3ee9 | 2017-05-30 16:44:56 -0700 | [diff] [blame] | 4 | class UserPolicy(Policy): |
| 5 | model_name = "User" |
| 6 | |
| 7 | def handle_create(self, user): |
| 8 | return self.handle_update(user) |
| 9 | |
| 10 | def handle_update(self, user): |
| 11 | controller_users = ControllerUser.objects.filter(user_id=user.id) |
| 12 | existing_controllers = [cu.controller for cu in controller_users] |
| 13 | existing_controller_ids = [c.id for c in existing_controllers] |
| 14 | all_controllers = Controller.objects.all() |
| 15 | for controller in all_controllers: |
| 16 | if controller.id not in existing_controller_ids: |
| 17 | ctrl_user = ControllerUser(controller=controller, user=user) |
| 18 | ctrl_user.save() |
Scott Baker | b63ea79 | 2016-08-11 10:24:48 -0700 | [diff] [blame] | 19 | |