Beispiel #1
0
    def create_session_then_send_start_link(self, use_browser_bots,
                                            **session_kwargs):
        try:
            session = otree.session.create_session(**session_kwargs)
            if use_browser_bots:
                otree.bots.browser.initialize_session(session_pk=session.pk,
                                                      case_number=None)
            session.save()
        except Exception as e:

            # full error message is printed to console (though sometimes not?)
            error_message = 'Failed to create session: "{}"'.format(e)
            traceback_str = traceback.format_exc()
            self.send_response_to_browser(
                dict(
                    error=error_message,
                    traceback=traceback_str,
                ))
            raise

        session_home_view = 'MTurkCreateHIT' if session.is_mturk(
        ) else 'SessionStartLinks'

        self.send_response_to_browser(
            {'session_url': reverse(session_home_view, args=[session.code])})
Beispiel #2
0
def run_bots(session: Session, case_number=None):
    bot_list = make_bots(session_pk=session.pk,
                         case_number=case_number,
                         use_browser_bots=False)
    if session.get_room() is None:
        session.mock_exogenous_data()
    session.save()
    runner = SessionBotRunner(bots=bot_list)
    runner.play()
Beispiel #3
0
    def _response_when_ready(self):
        session = get_session(self.session_config_name)
        session.demo_already_used = True
        session.save()

        if 'fullscreen' in self.request.GET and self.request.GET['fullscreen']:
            landing_url = reverse('session_fullscreen', args=(session.pk,))
        else:
            landing_url = reverse('session_start_links', args=(session.pk,))
        return HttpResponseRedirect(landing_url)
Beispiel #4
0
    def _response_when_ready(self):
        session = get_session(self.session_config_name)
        session.demo_already_used = True
        session.save()

        if 'fullscreen' in self.request.GET and self.request.GET['fullscreen']:
            landing_url = reverse('session_fullscreen', args=(session.pk, ))
        else:
            landing_url = reverse('session_start_links', args=(session.pk, ))
        return HttpResponseRedirect(landing_url)
Beispiel #5
0
def create_session(message):
    group = Group(message['channels_group_name'])

    kwargs = message['kwargs']

    try:
        session = otree.session.create_session(**kwargs)
        if message['use_browser_bots']:
            otree.bots.browser.initialize_session(
                session_pk=session.pk,
                case_number=None
            )
        session.ready_for_browser = True
        session.save()
    except Exception as e:

        # full error message is printed to console (though sometimes not?)
        error_message = 'Failed to create session: "{}"'.format(e)
        traceback_str = traceback.format_exc()
        group.send(
            {'text': json.dumps(
                {
                    'error': error_message,
                    'traceback': traceback_str,
                })}
        )
        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'})}
        )
Beispiel #6
0
def create_session(message):
    group = Group(message['channels_group_name'])

    kwargs = message['kwargs']

    try:
        session = otree.session.create_session(**kwargs)
        if message['use_browser_bots']:
            otree.bots.browser.initialize_session(
                session_pk=session.pk,
                case_number=None
            )
        session.ready_for_browser = True
        session.save()
    except Exception as e:

        # full error message is printed to console (though sometimes not?)
        error_message = 'Failed to create session: "{}"'.format(e)
        traceback_str = traceback.format_exc()
        group.send(
            {'text': json.dumps(
                {
                    'error': error_message,
                    'traceback': traceback_str,
                })}
        )
        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'})}
        )