def org_site_top_req_priority(row, tablename='org_facility'):
 if (not current.deployment_settings.has_module('req')):
  return None
 try:
  from req import REQ_STATUS_COMPLETE
 except ImportError:
  return None
 if hasattr(row, tablename):
  row = row[tablename]
 try:
  id = row.id
 except AttributeError:
  return None
 s3db = current.s3db
 rtable = s3db.req_req
 stable = s3db[tablename]
 query = (((((rtable.deleted != True) & (stable.id == id)) & (rtable.site_id == stable.site_id)) & (rtable.fulfil_status != REQ_STATUS_COMPLETE)) & (rtable.is_template == False))
 req = current.db(query).select(rtable.id, rtable.priority, orderby=(~ rtable.priority), limitby=(0, 1)).first()
 if req:
  return req.priority
 else:
  return None

def org_site_top_req_priority ( row , tablename = 'org_facility' ) : if ( not current . deployment_settings . has_module ( 'req' ) ) : return None try : from req import REQ_STATUS_COMPLETE except ImportError : return None if hasattr ( row , tablename ) : row = row [ tablename ] try : id = row . id except AttributeError : return None s3db = current . s3db rtable = s3db . req_req stable = s3db [ tablename ] query = ( ( ( ( ( rtable . deleted != True ) & ( stable . id == id ) ) & ( rtable . site_id == stable . site_id ) ) & ( rtable . fulfil_status != REQ_STATUS_COMPLETE ) ) & ( rtable . is_template == False ) ) req = current . db ( query ) . select ( rtable . id , rtable . priority , orderby = ( ~ rtable . priority ) , limitby = ( 0 , 1 ) ) . first ( ) if req : return req . priority else : return None
highest priority of open requests for a site .