def from_appstruct(self, appstruct): if 'id' in appstruct: if appstruct['id'] != self.id: print "ID in appstruct does not match: {} - {}".format(type(appstruct['id']), type(self.id)) raise ValueError if 'dc' in appstruct: self.dc = appstruct['dc'] self.name = appstruct['name'] self.oneliner = appstruct['oneliner'] self.description = appstruct['description'] self.website = appstruct['website'] if 'logo_path' in appstruct: self.logo = appstruct['logo_path'] new_poc_ids = set([p['id'] for p in appstruct['pocs'] if p['id'] != -1]) cur_poc_ids = set([p.id for p in self.pocs]) del_poc_ids = cur_poc_ids - new_poc_ids if len(del_poc_ids): for poc in self.pocs: if poc.id in del_poc_ids: DBSession.delete(poc) for poc in appstruct['pocs']: if poc['id'] in cur_poc_ids: cur_poc = [p for p in self.pocs if p.id == poc['id']][0] cur_poc.from_appstruct(poc) else: npoc = POC() npoc.from_appstruct(poc) self.pocs.append(npoc)
def from_appstruct(self, appstruct): super(Village, self).from_appstruct(appstruct) self.hrsofoperation = appstruct['hrsofoperation'] self.spacereq = appstruct['spacereq'] self.tables = appstruct['tables'] self.chairs = appstruct['chairs'] self.signage = appstruct['signage'] self.projectors = appstruct['projectors'] self.screens = appstruct['screens'] self.numparticipants = appstruct['numparticipants'] self.years = appstruct['years'] self.quiet_time = appstruct['quiet_time'] self.sharing = appstruct['sharing'] new_power_ids = set([p['id'] for p in appstruct['power'] if p['id'] != -1]) cur_power_ids = set([p.id for p in self.power]) del_power_ids = cur_power_ids - new_power_ids if len(del_power_ids): for power in self.power: if power.id in del_power_ids: DBSession.delete(power) for power in appstruct['power']: if power['id'] in cur_power_ids: cur_power = [p for p in event.power if p.id == power['id']][0] cur_power.from_appstruct(power) else: npower = Power() npower.from_appstruct(power) self.power.append(npower) new_drop_ids = set([d['id'] for d in appstruct['drops'] if d['id'] != -1]) cur_drop_ids = set([d.id for d in self.drops]) del_drop_ids = cur_drop_ids - new_drop_ids if len(del_drop_ids): for drop in self.drops: if drop.id in del_drop_ids: DBSession.delete(drop) for drop in appstruct['drops']: if drop['id'] in cur_drop_ids: cur_drop = [d for d in self.drops if d.id == drop['id']][0] cur_drop.from_appstruct(drop) else: ndrop = WiredInternet() ndrop.from_appstruct(drop) self.drops.append(ndrop) new_ap_ids = set([a['id'] for a in appstruct['aps'] if a['id'] != -1]) cur_ap_ids = set([a.id for a in self.aps]) del_ap_ids = cur_ap_ids - new_ap_ids if len(del_ap_ids): for ap in self.aps: if ap.id in del_ap_ids: DBSession.delete(ap) for ap in appstruct['aps']: if ap['id'] in cur_ap_ids: cur_ap = [a for a in self.aps if a.id == ap['id']][0] cur_ap.from_appstruct(appstruct) else: nap = AccessPoint() nap.from_appstruct(ap) self.aps.append(nap)