def getBoundary(self, user_id, distance): ''' Get users whose distance from the root user ('user_id') is exactly same as 'distance' ''' if distance == 0: return [long(user_id)] else: friends = [] # make a query to db con = db.con() with con: cur = con.cursor() cur.execute('''SELECT friend FROM m_cluster WHERE root = %s AND distance = %s''', (user_id, distance)) numrows = int(cur.rowcount) for i in range(numrows): friends.append(cur.fetchone()[0]) return friends
def party(request): current_character = Character.objects.get(player=request.user.id) friend_users = Friendship.objects.friends_of(request.user) msg = message = None if request.GET: msg = request.GET['msg'] friends = list() for friend in friend_users: if friend != request.user: friends.append(Character.objects.get(player=friend)) sent_invites_users = FriendshipRequest.objects.filter(from_user=current_character.player) sent_invites = list() for sent_invite in sent_invites_users: sent_invites.append(Character.objects.get(player = sent_invite.to_user)) received_invites_users = FriendshipRequest.objects.filter(to_user=current_character.player) received_invites = list() for received_invite in received_invites_users: received_invites.append(Character.objects.get(player=received_invite.from_user)) if msg == 'notfound': message = "Sorry, we couldn't find anyone by that name. Please try again with their character's name, username, or an email address." elif msg == 'pending': message = "You have already sent them an invitation. Let's hope they accept soon!" elif msg == 'sent': message = "Your invitation has been sent. Please await a reply." if current_character.party and current_character.party.size() < current_character.party.max_size(): party_room = current_character.party.max_size() - current_character.party.size() elif not current_character.party: party_room = current_character.max_party_size() else: party_room = 0 party_invites = PartyInvite.objects.filter(to_character=current_character) party_invites_sent = PartyInvite.objects.filter(from_character=current_character) party_room -= party_invites_sent.count() if party_room < 0: party_room = 0 notifications = SocialMessage.objects.filter(to_character=current_character) return render_to_response('lok/party.html', {'party_room': party_room, 'message': message, 'character': current_character, 'party_invites': party_invites, 'party_invites_sent': party_invites_sent, 'friends': friends, 'sent_invites': sent_invites, 'received_invites': received_invites, 'notifications': notifications}, context_instance=RequestContext(request))