'Get the user_id for a person_id
@param person_id: the pr_person record ID, or a user email address
@param pe_id: the person entity ID, alternatively'

def s3_get_user_id(self, person_id=None, pe_id=None):

    result = None
    if (isinstance(person_id, basestring) and (not person_id.isdigit())):
        utable = self.settings.table_user
        query = (utable.email == person_id)
        user = current.db(query).select(utable.id, limitby=(0, 1)).first()
        if user:
            result = user.id
    else:
        s3db = current.s3db
        ltable = s3db.pr_person_user
        if person_id:
            ptable = s3db.pr_person
            query = ((ptable.id == person_id) & (ptable.pe_id == ltable.pe_id))
        else:
            query = (ltable.pe_id == pe_id)
        link = current.db(query).select(ltable.user_id, limitby=(0, 1)).first()
        if link:
            result = link.user_id
    return result
