How to use the otree.channels.utils function in otree

To help you get started, we’ve selected a few otree examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github oTree-org / otree-core / otree / bots / browser_launcher.py View on Github external
def websocket_listen(self, session_code, num_participants):
        # seems that urljoin doesn't work with ws:// urls
        # so do the ws replace after URLjoin
        websocket_url = urljoin(
            self.server_url,
            channel_utils.browser_bots_launcher_path(session_code)
        )
        websocket_url = websocket_url.replace(
            'http://', 'ws://').replace('https://', 'wss://')

        ws_client = OtreeWebSocketClient(
            websocket_url,
            session_size=num_participants,
        )
        ws_client.connect()
        ws_client.run_forever()
github oTree-org / otree-core / otree / views / abstract.py View on Github external
def socket_url(self):
        '''called from template. can't start with underscore because used
        in template
        '''
        return channel_utils.auto_advance_path(
            participant_code=self.participant.code,
            page_index=self._index_in_pages
        )
github oTree-org / otree-core / otree / channels / consumers.py View on Github external
def group_name(self, session_code):
        return channel_utils.browser_bots_launcher_group(session_code)
github oTree-org / otree-core / otree / bots / browser.py View on Github external
def send_completion_message(*, session_code, participant_code):
    group_name = channel_utils.browser_bots_launcher_group(session_code)

    channel_utils.sync_group_send_wrapper(
        group=group_name,
        type='send_completion_message',
        event={'text': participant_code},
    )
github oTree-org / otree-core / otree / views / admin.py View on Github external
def socket_url(self):
        return channel_utils.wait_for_session_path(self._pre_create_id)
github oTree-org / otree-core / otree / bots / browser.py View on Github external
def send_completion_message(*, session_code, participant_code):
    group_name = channel_utils.browser_bots_launcher_group(session_code)

    channel_utils.sync_group_send_wrapper(
        group=group_name,
        type='send_completion_message',
        event={'text': participant_code},
    )
github oTree-org / otree-core / otree / views / abstract.py View on Github external
def _gbat_get_channels_group_name(self):
            return channel_utils.gbat_group_name(
                session_pk=self._session_pk, page_index=self._index_in_pages,
            )
github oTree-org / otree-core / otree / channels / consumers.py View on Github external
})}
        )
        FailedSessionCreation.objects.create(
            pre_create_id=kwargs['pre_create_id'],
            message=error_message[:FAILURE_MESSAGE_MAX_LENGTH],
            traceback=traceback_str
        )
        raise

    group.send(
        {'text': json.dumps(
            {'status': 'ready'})}
    )

    if 'room_name' in kwargs:
        Group(channel_utils.room_participants_group_name(kwargs['room_name'])).send(
            {'text': json.dumps(
                {'status': 'session_ready'})}
        )
github oTree-org / otree-core / otree / common_internal.py View on Github external
def create_session_and_redirect(session_kwargs, *, use_browser_bots):
    pre_create_id = uuid.uuid4().hex
    session_kwargs['pre_create_id'] = pre_create_id
    channels_group_name = channel_utils.create_session_group_name(
        pre_create_id)
    channels.Channel('otree.create_session').send({
        'kwargs': session_kwargs,
        'channels_group_name': channels_group_name,
        'use_browser_bots': use_browser_bots,
    })

    wait_for_session_url = reverse(
        'WaitUntilSessionCreated', args=(pre_create_id,)
    )
    return HttpResponseRedirect(wait_for_session_url)
github oTree-org / otree-core / otree / views / participant.py View on Github external
# mode
            if missing_label or invalid_label and not room.use_secure_urls:
                return render_to_response(
                    "otree/RoomInputLabel.html",
                    {'invalid_label': invalid_label}
                )

            if room.use_secure_urls:
                hash = self.request.GET.get('hash')
                if hash != make_hash(label):
                    return HttpResponseNotFound('Invalid hash parameter.')

        session = room.get_session()
        if session is None:
            self.tab_unique_id = otree.common_internal.random_chars_10()
            self._socket_url = channel_utils.room_participant_path(
                self.room_name,
                label,
                # random chars in case the participant has multiple tabs open
                self.tab_unique_id
            )
            return render_to_response(
                "otree/WaitPageRoom.html",
                {
                    'view': self, 'title_text': _('Please wait'),
                    'body_text': _('Waiting for your session to begin')
                }
            )

        if label:
            cookies = None
        else: