Пример #1
0
def createAttendingAndInvitedAndUserDetailsJsonResponse(status):
    attending = status.attending.all()
    invited = status.invited.all()

    userDetails = list()
    for user in attending:
        userInfo = getUserProfileDetailsJson(user)
        userDetails.append(userInfo)

    for user in invited:
        if user not in attending:
            userInfo = getUserProfileDetailsJson(user)
            userDetails.append(userInfo)

    attending = list(attending.values_list('id', flat=True))
    invited = list(invited.values_list('id', flat=True))
    fbAttending = list(status.fbAttending.values_list('facebookUID', flat=True))
    fbInvited = list(status.fbInvited.values_list('facebookUID', flat=True))

    for fbId in fbAttending:
        attending.append("fb" + fbId)

    for fbId in fbInvited:
        invited.append("fb" + fbId)

    return attending, invited, userDetails
Пример #2
0
def createStatusJsonObject(status, userProfile = None):
    statusData = dict()

    statusData['statusid'] = status.id
    statusData['userid'] = status.user_id
    statusData['userinfo'] = getUserProfileDetailsJson(status.user)
    statusData['text'] = status.text
    statusData['datecreated'] = status.dateCreated.strftime(DATETIME_FORMAT)
    statusData['dateexpires'] = status.expires.strftime(DATETIME_FORMAT)
    statusData['datestarts'] = status.starts.strftime(DATETIME_FORMAT)
    statusData['type'] = status.statusType
    statusData['deleted'] = status.deleted

    attending, invited, userDetails = createAttendingAndInvitedAndUserDetailsJsonResponse(status)
    statusData['invited'] = invited
    statusData['attending'] = attending
    statusData['users'] = userDetails

    statusData['imageorientation'] = status.imageOrientation

    if status.imageUrl:
        statusData['imageurl'] = status.imageUrl

    if status.location:
        statusData['location'] = createLocationJson(status.location)
    if userProfile is not None:
       # if status.visibility == Status.VIS_FRIENDS_OF_FRIENDS or status.visibility == Status.VIS_PUBLIC:
        statusData['mutualfriends'] = UserProfile.getMutualFriends(status.user_id, userProfile.id)

    return statusData
Пример #3
0
def createChatMembersJson(chat):
    membersData = []
    members = chat.members.all()
    for member in members:
        memberData = getUserProfileDetailsJson(member)
        membersData.append(memberData)

    return membersData
def createTestUser(request):
    numberOfFriends = request.REQUEST['numfriends']
    response = dict()

    name = "test%d" % random.randint(1, 10000000)
    email = "*****@*****.**" % name
    firstName = name
    lastName = name
    user = User(username=email, email=email, first_name=firstName,
                last_name=lastName, password=0)

    user.save()
    userProfile = UserProfile(user=user, device='ios')
    userProfile.save()

    numberOfFriends = int(numberOfFriends)
    friends = UserProfile.objects.all().order_by('-id')[:numberOfFriends]

    blockedFriends = userProfile.blockedFriends.all()
    for friend in friends:
        if friend not in friend.friends.all():
            friend.friends.add(userProfile)
            userProfile.friends.add(friend)

    friends = userProfile.friends.all()
    response['friends'] = list()
    for friend in friends:
        friendData = getUserProfileDetailsJson(friend)
        response['friends'].append(friendData)

    statusesResponse, newSince = getNewStatusesJsonResponse(userProfile, None, None, None)
    myStatusesResponse = getMyStatusesJsonResponse(userProfile)
    groupsData = getMyGroupsJsonResponse(userProfile)

    buddyupSettings = getSettingsData(userProfile)

    newSince = datetime.now().strftime(MICROSECOND_DATETIME_FORMAT)
    notifications = getNotificationsJson(userProfile)
    chatData = getNewChatsData(userProfile)

    response['success'] = True
    response['firstname'] = userProfile.user.first_name
    response['lastname'] = userProfile.user.last_name
    response['userid'] = userProfile.id
    response['facebookid'] = userProfile.facebookUID
    response['statuses'] = statusesResponse
    response['groups'] = groupsData
    response['mystatuses'] = myStatusesResponse
    response['chats'] = chatData
    response['newsince'] = newSince
    response['settings'] = buddyupSettings
    response['notifications'] = notifications
    response['favoritesnotifications'] = userProfile.favoritesNotifications

    return HttpResponse(json.dumps(response))
Пример #5
0
    def getMutualFriends(userId1, userId2):
        user1 = UserProfile.getUser(userId1)
        user2 = UserProfile.getUser(userId2)
        mutualFriends = UserProfile.objects.filter(friends=user1).filter(friends=user2)
        if(userId1 > userId2):
            key =  str(userId2) + '_' + str(userId1)
        else:
            key = str(userId1) + '_' + str(userId2)
        mutualFriendsList = cache.get(key)
        if mutualFriendsList is None:
            mutualFriendsList =  mutualFriends.all()

        mutualFriendsData = list()

        for mutualFriend in mutualFriendsList:
            mutualFriendData = getUserProfileDetailsJson(mutualFriend)
            mutualFriendsData.append(mutualFriendData)

        return mutualFriendsData
def refreshFacebookFriends(request):
    response = dict()

    userid = request.REQUEST.get('userid', None)
    accessToken = request.REQUEST.get('accesstoken')

    try:
        userProfile = UserProfile.getUser(userid)
    except UserProfile.DoesNotExist:
        return errorResponse("Invalid user id")

    facebookProfile = FacebookProfile(userProfile, accessToken)
    friends = facebookProfile.getFacebookFriends()

    response['users'] = []
    for friend in friends:
        response['users'].append(getUserProfileDetailsJson(friend))

    response['success'] = True

    return HttpResponse(json.dumps(response))
def getFriends(request):
    response = dict()

    userid = request.REQUEST['userid']

    try:
        userProfile = UserProfile.getUser(userid)
    except UserProfile.DoesNotExist:
        return errorResponse("Invalid user id")

    # blockedFriends = userProfile.blockedFriends.all()
    friendsData = list()

    for friend in userProfile.friends.all():
        # blocked = False
        # if friend in blockedFriends:
        #     blocked = True
        friendData = getUserProfileDetailsJson(friend)
        friendsData.append(friendData)

    response['success'] = True
    response['users'] = friendsData

    return HttpResponse(json.dumps(response))
def facebookLogin(request):
    """

    :param request:
    :return:
    """
    response = dict()

    device = request.REQUEST['device']
    facebookAuthKey = request.REQUEST['fbauthkey']
    lat = request.REQUEST.get('lat', None)
    lng = request.REQUEST.get('lng', None)

    if device != 'ios' and device != 'android':
        return errorResponse('Invalid device: ' + device)

    try:
        facebookProfile, newUser = FacebookProfile.getFacebookUserFromAuthKey(facebookAuthKey, device)
        userProfile = facebookProfile.userProfile
    except facebook.GraphAPIError:
        return errorResponse("Invalid Facebook AUTH Key")

    response['friends'] = []

    facebookFriends = facebookProfile.getFacebookFriends()

    blockedFriends = userProfile.blockedFriends.all()
    for friend in facebookFriends:
        blocked = False
        if friend in blockedFriends:
            blocked = True

        friendData = getUserProfileDetailsJson(friend)
        response['friends'].append(friendData)

    # Check all buddyup friends and add them if they weren't already included in facebook friends check
    friends = userProfile.friends.all()
    for friend in friends:
        if friend not in facebookFriends:
            blocked = False
            if friend in blockedFriends:
                blocked = True

            friendData = getUserProfileDetailsJson(friend)
            response['friends'].append(friendData)

    statusesResponse, newSince = getNewStatusesJsonResponse(userProfile, None, lat, lng)
    myStatusesResponse = getMyStatusesJsonResponse(userProfile)

    settings = getSettingsData(userProfile)

    newSince = datetime.now().strftime(MICROSECOND_DATETIME_FORMAT)
    notifications = getNotificationsJson(userProfile)
    chatData = getNewChatsData(userProfile)

    if newUser:
        createFriendJoinedNotification(userProfile)
        Group.objects.create(name="Favorites", user=userProfile)

    groupsData = getMyGroupsJsonResponse(userProfile)


    response['success'] = True
    response['firstname'] = userProfile.user.first_name
    response['lastname'] = userProfile.user.last_name
    response['userid'] = userProfile.id
    response['facebookid'] = userProfile.facebookUID
    response['statuses'] = statusesResponse
    response['groups'] = groupsData
    response['mystatuses'] = myStatusesResponse
    response['chats'] = chatData
    response['newsince'] = newSince
    response['settings'] = settings
    response['notifications'] = notifications
    response['favoritesnotifications'] = userProfile.favoritesNotifications

    return HttpResponse(json.dumps(response))