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 SitePolicy(Policy): |
| 5 | model_name = "Site" |
Scott Baker | b63ea79 | 2016-08-11 10:24:48 -0700 | [diff] [blame] | 6 | |
Scott Baker | 46a3ee9 | 2017-05-30 16:44:56 -0700 | [diff] [blame] | 7 | def handle_create(self, site): |
| 8 | return self.handle_update(site) |
| 9 | |
| 10 | def handle_update(self, site): |
| 11 | # site = Site.get(site_id) |
| 12 | # make sure site has a ControllerSite record for each controller |
| 13 | ctrl_sites = ControllerSite.objects.filter(site_id=site.id) |
| 14 | existing_controllers = [cs.controller for cs in ctrl_sites] |
| 15 | existing_controller_ids = [c.id for c in existing_controllers] |
| 16 | |
| 17 | all_controllers = Controller.objects.all() |
| 18 | for ctrl in all_controllers: |
| 19 | if ctrl.id not in existing_controller_ids: |
| 20 | ctrl_site = ControllerSite(controller=ctrl, site=site) |
| 21 | ctrl_site.save() |
| 22 | |