def pr_define_role(pe_id, role=None, role_type=None, entity_type=None, sub_type=None):
 if (not pe_id):
  return
 s3db = current.s3db
 if (role_type not in s3db.pr_role_types):
  role_type = 9
 data = {'pe_id': pe_id, 'role': role, 'role_type': role_type, 'entity_type': entity_type, 'sub_type': sub_type}
 rtable = s3db.pr_role
 if role:
  query = ((rtable.pe_id == pe_id) & (rtable.role == role))
  duplicate = current.db(query).select(rtable.id, rtable.role_type, limitby=(0, 1)).first()
 else:
  duplicate = None
 if duplicate:
  if (duplicate.role_type != role_type):
   if (str(role_type) != str(OU)):
    data['path'] = None
   s3db.pr_role_rebuild_path(duplicate.id, clear=True)
  duplicate.update_record(**data)
  record_id = duplicate.id
 else:
  record_id = rtable.insert(**data)
 return record_id

def pr_define_role ( pe_id , role = None , role_type = None , entity_type = None , sub_type = None ) : if ( not pe_id ) : return s3db = current . s3db if ( role_type not in s3db . pr_role_types ) : role_type = 9 data = { 'pe_id' : pe_id , 'role' : role , 'role_type' : role_type , 'entity_type' : entity_type , 'sub_type' : sub_type } rtable = s3db . pr_role if role : query = ( ( rtable . pe_id == pe_id ) & ( rtable . role == role ) ) duplicate = current . db ( query ) . select ( rtable . id , rtable . role_type , limitby = ( 0 , 1 ) ) . first ( ) else : duplicate = None if duplicate : if ( duplicate . role_type != role_type ) : if ( str ( role_type ) != str ( OU ) ) : data [ 'path' ] = None s3db . pr_role_rebuild_path ( duplicate . id , clear = True ) duplicate . update_record ( ** data ) record_id = duplicate . id else : record_id = rtable . insert ( ** data ) return record_id
back-end method to define a new affiliates-role for a person entity .