def get_network_for_participant(self, participant):
key = participant.id<EOL>networks_with_space = (<EOL>Network.query.filter_by(full=False).order_by(Network.id).all()<EOL>)<EOL>networks_participated_in = [<EOL>node.network_id<EOL>for node in Node.query.with_entities(Node.network_id)<EOL>.filter_by(participant_id=participant.id)<EOL>.all()<EOL>]<EOL>legal_networks = [<EOL>net for net in networks_with_space if net.id not in networks_participated_in<EOL>]<EOL>if not legal_networks:<EOL><INDENT>self.log("<STR_LIT>", key)<EOL>return None<EOL><DEDENT>self.log(<EOL>"<STR_LIT>".format(<EOL>len(legal_networks), (self.practice_repeats + self.experiment_repeats)<EOL>),<EOL>key,<EOL>)<EOL>legal_practice_networks = [<EOL>net for net in legal_networks if net.role == "<STR_LIT>"<EOL>]<EOL>if legal_practice_networks:<EOL><INDENT>chosen_network = legal_practice_networks[<NUM_LIT:0>]<EOL>self.log(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(<EOL>chosen_network.id<EOL>),<EOL>key,<EOL>)<EOL><DEDENT>else:<EOL><INDENT>chosen_network = self.choose_network(legal_networks, participant)<EOL>self.log(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(<EOL>chosen_network.id<EOL>),<EOL>key,<EOL>)<EOL><DEDENT>return chosen_network<EOL>
Find a network for a participant.

        If no networks are available, None will be returned. By default
        participants can participate only once in each network and participants
        first complete networks with `role="practice"` before doing all other
        networks in a random order.