@auth.requires_login()
def retrieve_users():
    """
        Show the list of registered users
    """

    atable = db.auth_user
    frtable = db.friend_requests
    ftable = db.friends
    q = request.get_vars.get("q", None)

    query = (atable.first_name.contains(q)) | \
            (atable.last_name.contains(q)) | \
            (atable.stopstalk_handle.contains(q))

    for site in current.SITES:
        field_name = site.lower() + "_handle"
        query |= (atable[field_name].contains(q))

    # Don't show the logged in user in the search
    query &= (atable.id != session.user_id)

    # Don't show users who have sent friend requests
    # to the logged in user
    tmprows = db(frtable.to_h == session.user_id).select(frtable.from_h)
    for row in tmprows:
        query &= (atable.id != row.from_h)

    # Columns of auth_user to be retrieved
    columns = [atable.id,
               atable.first_name,
               atable.last_name,
               atable.stopstalk_handle]

    for site in current.SITES:
        columns.append(atable[site.lower() + "_handle"])

    rows = db(query).select(*columns)

    t = TABLE(_class="striped centered")
    tr = TR(TH("Name"),
            TH("StopStalk Handle"))

    for site in current.SITES:
        tr.append(TH(site + " Handle"))

    tr.append(TH("Friendship Status"))
    thead = THEAD()
    thead.append(tr)
    t.append(thead)

    tbody = TBODY()

    query = (ftable.user_id == session["user_id"])
    friends = db(query).select(atable.id,
                               join=ftable.on(ftable.friend_id == atable.id))
    friends = [x["id"] for x in friends]

    for user in rows:

        tr = TR()
        tr.append(TD(A(user.first_name + " " + user.last_name,
                       _href=URL("user", "profile",
                                 args=[user.stopstalk_handle],
                                 extension=False),
                       _target="_blank")))
        tr.append(TD(user.stopstalk_handle))

        for site in current.SITES:
            tr.append(TD(user[site.lower() + "_handle"]))

        # Check if the current user is already a friend or not
        if friends not in user.id:
            r = db((frtable.from_h == session.user_id) &
                   (frtable.to_h == user.id)).count()
            if r == 0:
                tr.append(TD(BUTTON(I(_class="fa fa-user-plus fa-3x"),
                                    _class="tooltipped btn-floating btn-large waves-effect waves-light green",
                                    data={"position": "bottom",
                                          "delay": "50",
                                          "tooltip": "Send friend request",
                                          "user-id": str(user.id),
                                          "type": "add-friend"})))
            else:
                tr.append(TD(BUTTON(I(_class="fa fa-user-plus fa-3x"),
                                    _class="tooltipped btn-floating btn-large disabled",
                                    data={"position": "bottom",
                                          "delay": "50",
                                          "tooltip": "Send friend request",
                                          "type": "disabled"})))
        else:
            tr.append(TD(BUTTON(I(_class="fa fa-user-times fa-3x"),
                                _class="tooltipped btn-floating btn-large waves-effect waves-light black",
                                data={"position": "bottom",
                                      "delay": "50",
                                      "tooltip": "Friend request pending",
                                      "user-id": str(user.id),
                                      "type": "unfriend"})))
        tbody.append(tr)

    t.append(tbody)
    return dict(t=t)

# ----------------------------------------------------------------------------
dataset/ETHPy150Open stopstalk/stopstalk-deployment/controllers/default.py/retrieve_users/swapped operands of `not in`