# subject_record describes the subject of the relationships
# ref_record contains the target values for the various relationships we need to manage
# (to begin with, this is just the slice x person (researcher) and authority x person (pi) relationships)
- def update_driver_relations (self, subject_obj, ref_obj, dbsession):
+ def update_driver_relations (self, api, subject_obj, ref_obj):
type=subject_obj.type
#for (k,v) in subject_obj.__dict__.items(): print k,'=',v
if type=='slice' and hasattr(ref_obj,'researcher'):
- self.update_driver_relation(subject_obj, ref_obj.researcher, 'user', 'researcher', dbsession)
+ self.update_driver_relation(api, subject_obj, ref_obj.researcher, 'user', 'researcher')
elif type=='authority' and hasattr(ref_obj,'pi'):
- self.update_driver_relation(subject_obj,ref_obj.pi, 'user', 'pi', dbsession)
+ self.update_driver_relation(api, subject_obj,ref_obj.pi, 'user', 'pi')
# field_key is the name of one field in the record, typically 'researcher' for a 'slice' record
# hrns is the list of hrns that should be linked to the subject from now on
# target_type would be e.g. 'user' in the 'slice' x 'researcher' example
- def update_driver_relation (self, record_obj, hrns, target_type, relation_name, dbsession):
+ def update_driver_relation (self, api, record_obj, hrns, target_type, relation_name):
+ dbsession=api.dbsession()
# locate the linked objects in our db
subject_type=record_obj.type
subject_id=record_obj.pointer
link_id_tuples = dbsession.query(RegRecord.pointer).filter_by(type=target_type).filter(RegRecord.hrn.in_(hrns)).all()
# sqlalchemy returns named tuples for columns
link_ids = [ tuple.pointer for tuple in link_id_tuples ]
- self.driver.update_relation (subject_type, target_type, relation_name, subject_id, link_ids)
+ api.driver.update_relation (subject_type, target_type, relation_name, subject_id, link_ids)
def Register(self, api, record_dict):
dbsession.commit()
# update membership for researchers, pis, owners, operators
- self.update_driver_relations (record, record, dbsession)
+ self.update_driver_relations (api, record, record)
return record.get_gid_object().save_to_string(save_parents=True)
dbsession.commit()
# update membership for researchers, pis, owners, operators
- self.update_driver_relations (record, new_record, dbsession)
+ self.update_driver_relations (api, record, new_record)
return 1