def synchronize(cls): """synchronize the target database with the database at rovor.byu.edu""" # this is going to be kind of slow. Ideally we would # set up a system so that each server notifies the other # when there is a change remote_objs = obsDB.get_objs()["objects"] for obj in remote_objs: if not cls.objects.filter(simbadName=obj["simbadName"]).exists(): cls.objects.create(name=obj["name"], simbadName=obj["simbadName"])
def synchronize(cls): '''synchronize the target database with the database at rovor.byu.edu''' #this is going to be kind of slow. Ideally we would #set up a system so that each server notifies the other #when there is a change remote_objs = obsDB.get_objs()['objects'] for obj in remote_objs: if not cls.objects.filter(simbadName=obj['simbadName']).exists(): cls.objects.create(name=obj['name'], simbadName=obj['simbadName'])
def synchronize2(cls): """possibly better synchronization function, not tested""" remote_objs = obsDB.get_objs()["objects"] local_objs = dict((o.simbadName, o) for o in cls.objects.all()) for obj in remote_objs: if obj["simbadName"] in local_objs: del local_objs[obj["simbadName"]] else: cls.objects.create(name=obj["name"], simbadName=obj["simbadName"]) # now push the rest to the remote server for obj in local_objs.values(): # ideally we would use the coords and simbadName as well # but we need a richer interface for adding objects on # ObsDB for that obsDB.addObject(obj.name)
def synchronize2(cls): '''possibly better synchronization function, not tested''' remote_objs = obsDB.get_objs()['objects'] local_objs = dict((o.simbadName, o) for o in cls.objects.all()) for obj in remote_objs: if obj['simbadName'] in local_objs: del local_objs[obj['simbadName']] else: cls.objects.create(name=obj['name'], simbadName=obj['simbadName']) #now push the rest to the remote server for obj in local_objs.values(): #ideally we would use the coords and simbadName as well #but we need a richer interface for adding objects on #ObsDB for that obsDB.addObject(obj.name)