'Custom rows lookup
@param key: the key Field
@param values: the values
@param fields: unused (retained for API compatibility)
@param pe_id: whether to include pe_id in the output rows
(True when called from pr_PersonEntityRepresent)'

def lookup_rows(self, key, values, fields=[], pe_id=False):

    s3db = current.s3db
    etable = self.table
    ctable = s3db.hrm_course
    stable = s3db.org_site
    left = [ctable.on((ctable.id == etable.course_id)), stable.on((stable.site_id == etable.site_id))]
    if (len(values) == 1):
        query = (key == values[0])
    else:
        query = key.belongs(values)
    fields = [etable.id, etable.start_date, etable.instructor, etable.person_id, ctable.name, ctable.code, stable.name]
    if pe_id:
        fields.insert(0, etable.pe_id)
    rows = current.db(query).select(left=left, *fields)
    instructors = current.deployment_settings.get_hrm_training_instructors()
    if (instructors in ('internal', 'both')):
        key = str(etable.person_id)
        etable.person_id.represent.bulk([row[key] for row in rows])
    self.queries += 1
    return rows
