コード例 #1
0
    def run_session(self, session_config_name, num_participants, case_number):
        self.close_existing_session()

        secret_code = get_admin_secret_code()
        browser_process = self.launch_browser(num_participants, secret_code)

        row_fmt = "{:<%d} {:>2} participants..." % (self.max_name_length + 1)
        sys.stdout.write(row_fmt.format(session_config_name, num_participants))

        session_code = self.create_bb_session(
            session_config_name=session_config_name,
            num_participants=num_participants,
            case_number=case_number,
        )

        time_spent = self.websocket_listen(session_code, num_participants)
        sys.stdout.write('...finished in {} seconds\n'.format(time_spent))

        # TODO:
        # - if Chrome/FF is already running when the browser is launched,
        # this does nothing.
        # also, they report a crash (in Firefox it blocks the app from
        # starting again), in Chrome it's just a side notice
        browser_process.terminate()
        return time_spent
コード例 #2
0
import otree.constants
from otree.channels.utils import auto_advance_group
from otree.common import (
    random_chars_8,
    random_chars_10,
    get_admin_secret_code,
    get_app_label_from_name,
    FieldTrackerWithVarsSupport,
)
from otree.db import models
from otree.models_concrete import RoomToSession
import otree.db.idmap

logger = logging.getLogger('otree')

ADMIN_SECRET_CODE = get_admin_secret_code()


class Session(models.OTreeModel):
    class Meta:
        app_label = "otree"
        # if i don't set this, it could be in an unpredictable order
        ordering = ['pk']

    _ft = FieldTrackerWithVarsSupport()
    vars: dict = models._PickleField(default=dict)
    config: dict = models._PickleField(default=dict, null=True)

    # label of this session instance
    label = models.CharField(max_length=300,
                             null=True,