Ejemplo n.º 1
0
    def add_contact_from_db_row(self, row):
        contact = Contact()
        for field, value in row.iteritems():
            contact.__setattr__(field, value)

        contact.author = user_manager.get_user_by_id(contact.author_id)

        if contact.connected_user_id:
            contact.connected_user = user_manager.get_user_by_id(contact.connected_user_id)

        self.active_contacts[contact.id] = contact
        return contact
Ejemplo n.º 2
0
    def add_game_from_db_row(self, row):
        game = Game()
        for field, value in row.iteritems():
            game.__setattr__(field, value)

        if game.master_id:
            game.master = user_manager.get_user_by_id(game.master_id)

        for contact_row in db.query("SELECT * FROM " + CONTACT_TABLE_NAME + " WHERE game_id = %s AND is_active=1", game.id):
            contact = self.add_contact_from_db_row(contact_row)
            game.add_active_contact(contact)
            contact.game = game
            if contact.is_accepted and (not game.last_accepted_contact or game.last_accepted_contact.connected_at <= contact.connected_at):
                game.last_accepted_contact = contact

            if contact.is_accepted:
                self.create_contact_check_task(contact)

        for word_row in db.query("SELECT word FROM " + CONTACT_TABLE_NAME + " WHERE game_id = %s AND is_active=0", game.id):
            game.add_used_word(word_row.word)

        self.current_game_in_room[game.room_id] = game

        return game