blob: e0e288d3dcb329675f3cda1b03822e86c3432e06 [file] [log] [blame]
Scott Bakeraf599eb2017-03-21 12:43:26 -07001from synchronizers.new_base.modelaccessor import *
Scott Baker46a3ee92017-05-30 16:44:56 -07002from synchronizers.new_base.policy import Policy
Scott Bakerb63ea792016-08-11 10:24:48 -07003
Scott Baker46a3ee92017-05-30 16:44:56 -07004class SitePolicy(Policy):
5 model_name = "Site"
Scott Bakerb63ea792016-08-11 10:24:48 -07006
Scott Baker46a3ee92017-05-30 16:44:56 -07007 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