def load(name): r = DBResource.get(name) if not r: raise Exception('Resource {} does not exist in DB'.format(name)) return Resource(r)
def add_events(resource, lst): resource = Resource.get(resource) events = resource.events # TODO: currently we don't track mutable objects events.extend([ev.to_dict() for ev in lst]) resource.events = events # import pdb; pdb.settrace() resource.save_lazy()
def remove_event(ev): to_remove = ev.to_dict() resource = ev.parent resource = Resource.get(resource) # TODO: currently we don't track mutable objects events = resource.events events.remove(to_remove) resource.events = events resource.save_lazy()
def insert(self, changed_resources, changes_graph): changed_resources.append(self.parent_node) try: location_id = Resource.get(self.parent).inputs['location_id'] except (DBLayerNotFound, DBLayerSolarException): location_id = None changes_graph.add_node( self.parent_node, status='PENDING', target=location_id, errmsg='', type='solar_resource', args=[self.parent, self.parent_action])
def insert(self, changed_resources, changes_graph): changed_resources.append(self.parent_node) try: location_id = Resource.get(self.parent).inputs['location_id'] except DBLayerNotFound: location_id = None changes_graph.add_node( self.parent_node, status='PENDING', target=location_id, errmsg='', type='solar_resource', args=[self.parent, self.parent_action])
def insert(self, changed_resources, changes_graph): if self.parent_node in changes_graph: if self.child_node not in changes_graph: try: location_id = Resource.get(self.child).inputs[ 'location_id'] except DBLayerNotFound: location_id = None changes_graph.add_node( self.child_node, status='PENDING', target=location_id, errmsg='', type='solar_resource', args=[self.child, self.child_action]) changes_graph.add_edge( self.parent_node, self.child_node, state=self.state) changed_resources.append(self.child_node)
def all_events(resource): return [create_event(e) for e in Resource.get(resource).events]