Ejemplo n.º 1
0
def friends():
    user = DB.find_one(collection="Profile",
                       query={"email": current_user.email})
    if user is None:
        flash('Please create your profile first!')
        return redirect(url_for('edit_profile'))
    # all users
    users = list(DB.find_all(collection="Profile"))

    myFriendList = []
    mySentList = []
    for f in user['friends']:
        profile = DB.find_one(collection="Profile",
                              query={'_id': f['friend_id']})
        if f['status'] == 'accepted':
            myFriendList.append(profile)
        else:
            mySentList.append(profile)
    incoming = DB.find(collection="Profile",
                       query={
                           "friends": {
                               "$elemMatch": {
                                   "friend_id": user['_id'],
                                   "status": "pending"
                               }
                           }
                       })
    requests = get_cursor(cursor_obj=incoming,
                          key="friends",
                          subkey="friend_id",
                          subkey2="status",
                          query=user['_id'],
                          query2="pending")

    return render_template('friend.html',
                           title='Friend List',
                           users=users,
                           myFriendList=myFriendList,
                           mySentList=mySentList,
                           requests=requests)
Ejemplo n.º 2
0
 def Init():
     if len(Agent.agents) == 0:
         Agent.agents = list(DB.find_all('Agents'))