def pr_import_prep(data):
 db = current.db
 s3db = current.s3db
 set_record_owner = current.auth.s3_set_record_owner
 update_super = s3db.update_super
 table = s3db.org_organisation
 (resource, tree) = data
 elements = tree.getroot().xpath("/s3xml//resource[@name='pr_contact']/data[@field='pe_id']")
 looked_up = {}
 for element in elements:
  org = element.text
  if (not org):
   continue
  if (org in looked_up):
   element.text = looked_up[org]
   continue
  record = db((table.name == org)).select(table.pe_id, limitby=(0, 1)).first()
  if (not record):
   record_id = table.insert(**{'name': org})
   update_super(table, Storage(id=record_id))
   set_record_owner(table, record_id)
   record = db((table.id == record_id)).select(table.pe_id, limitby=(0, 1)).first()
  pe_id = record.pe_id
  element.text = str(pe_id)
  looked_up[org] = pe_id

def pr_import_prep ( data ) : db = current . db s3db = current . s3db set_record_owner = current . auth . s3_set_record_owner update_super = s3db . update_super table = s3db . org_organisation ( resource , tree ) = data elements = tree . getroot ( ) . xpath ( "/s3xml//resource[@name='pr_contact']/data[@field='pe_id']" ) looked_up = { } for element in elements : org = element . text if ( not org ) : continue if ( org in looked_up ) : element . text = looked_up [ org ] continue record = db ( ( table . name == org ) ) . select ( table . pe_id , limitby = ( 0 , 1 ) ) . first ( ) if ( not record ) : record_id = table . insert ( ** { 'name' : org } ) update_super ( table , Storage ( id = record_id ) ) set_record_owner ( table , record_id ) record = db ( ( table . id == record_id ) ) . select ( table . pe_id , limitby = ( 0 , 1 ) ) . first ( ) pe_id = record . pe_id element . text = str ( pe_id ) looked_up [ org ] = pe_id
called when contacts are imported from csv lookups pseudo-reference integer fields from names i .