Пример #1
0
    def session_test(self, session_name):

        session_conf = SESSION_CONFIGS_DICT[session_name]
        app_sequence = session_conf["app_sequence"]
        npar = session_conf["num_demo_participants"]

        call_command('create_session', session_name, str(npar))

        for app in app_sequence:
            app_format = common_internal.app_name_format(app)

            url = "/ExportAppDocs/{}/".format(app)
            response = self.client.get(url)

            # HEADERS CHECK
            content_disposition = response["Content-Disposition"]
            content_type = response["content-type"]

            self.assertEqual(content_type, "text/plain")

            expected_cd = 'attachment; filename="{} - documentation ('.format(
                app_format)
            self.assertTrue(content_disposition.startswith(expected_cd))

            buff = StringIO()
            common_internal.export_docs(buff, app)
            self.assertEqual(response.content, buff.getvalue().encode('utf-8'))
Пример #2
0
    def session_test(self, session_name):

        session_conf = self.get_session_conf(session_name)
        app_sequence = session_conf["app_sequence"]
        npar = session_conf["num_demo_participants"]

        call_command('create_session', session_name, str(npar))

        for app in app_sequence:
            app_format = common_internal.app_name_format(app)

            url = "/ExportAppDocs/{}/".format(app)
            response = self.client.get(url)

            # HEADERS CHECK
            content_disposition = response["Content-Disposition"]
            content_type = response["content-type"]

            self.assertEqual(content_type, "text/plain")

            expected_cd = 'attachment; filename="{} - documentation ('.format(
                app_format)
            self.assertTrue(content_disposition.startswith(expected_cd))

            buff = StringIO()
            common_internal.export_docs(buff, app)
            self.assertEqual(response.content, buff.getvalue().encode('utf-8'))
Пример #3
0
def info_about_session_config(session_config):

    app_sequence = []
    seo = set()
    for app_name in session_config['app_sequence']:
        models_module = get_models_module(app_name)
        num_rounds = models_module.Constants.num_rounds
        formatted_app_name = app_name_format(app_name)
        if num_rounds > 1:
            formatted_app_name = '{} ({} rounds)'.format(
                formatted_app_name, num_rounds
            )
        subsssn = {
            'doc': getattr(models_module, 'doc', ''),
            'source_code': getattr(models_module, 'source_code', ''),
            'bibliography': getattr(models_module, 'bibliography', []),
            'links': sort_links(getattr(models_module, 'links', {})),
            'keywords': keywords_links(getattr(models_module, 'keywords', [])),
            'name': formatted_app_name,
        }
        seo.update(map(lambda (a, b): a, subsssn["keywords"]))
        app_sequence.append(subsssn)
    return {
        'doc': session_config['doc'],
        'app_sequence': app_sequence,
        'page_seo': seo
    }
Пример #4
0
    def docs_as_string(doc_dict):

        first_line = '{}: Documentation'.format(app_name_format(app_name))
        second_line = '*' * len(first_line)

        lines = [
            first_line, second_line, '',
            'Accessed: {}'.format(datetime.date.today().isoformat()), '']

        app_doc = getattr(models_module, 'doc', '')
        if app_doc:
            lines += [app_doc, '']

        for model_name in doc_dict:
            lines.append(model_name)

            for member in doc_dict[model_name]:
                lines.append('\t{}'.format(member))
                for info_type in doc_dict[model_name][member]:
                    lines.append('\t\t{}'.format(info_type))
                    for info_line in doc_dict[model_name][member][info_type]:
                        lines.append(u'{}{}'.format('\t' * 3, info_line))

        output = u'\n'.join(lines)
        return output.replace('\n', line_break).replace('\t', '    ')
Пример #5
0
    def docs_as_string(doc_dict):

        first_line = '{}: Documentation'.format(app_name_format(app_name))
        second_line = '*' * len(first_line)

        lines = [
            first_line, second_line, '',
            'Accessed: {}'.format(datetime.date.today().isoformat()), ''
        ]

        app_doc = getattr(models_module, 'doc', '')
        if app_doc:
            lines += [app_doc, '']

        for model_name in doc_dict:
            lines.append(model_name)

            for member in doc_dict[model_name]:
                lines.append('\t{}'.format(member))
                for info_type in doc_dict[model_name][member]:
                    lines.append('\t\t{}'.format(info_type))
                    for info_line in doc_dict[model_name][member][info_type]:
                        lines.append(u'{}{}'.format('\t' * 3, info_line))

        output = u'\n'.join(lines)
        return output.replace('\n', line_break).replace('\t', '    ')
Пример #6
0
    def session_test(self, session_name):

        session_conf = self.get_session_conf(session_name)
        app_sequence = session_conf["app_sequence"]
        npar = session_conf["num_demo_participants"]

        call_command('create_session', session_name, str(npar))

        for app in app_sequence:
            app_format = common_internal.app_name_format(app)

            url = "/ExportCsv/{}/".format(app)
            response = self.client.get(url)

            # HEADERS CHECK
            content_disposition = response["Content-Disposition"]
            content_type = response["content-type"]

            self.assertEqual(content_type, "text/csv")

            self.assertTrue(
                content_disposition.startswith(
                    'attachment; filename="{} ('.format(app_format)))

            buff = six.StringIO()
            common_internal.export_data(buff, app)
            self.assertEqual(response.content, buff.getvalue())
Пример #7
0
def info_about_session_config(session_config):

    app_sequence = []
    seo = set()
    for app_name in session_config['app_sequence']:
        models_module = get_models_module(app_name)
        num_rounds = models_module.Constants.num_rounds
        formatted_app_name = app_name_format(app_name)
        if num_rounds > 1:
            formatted_app_name = '{} ({} rounds)'.format(
                formatted_app_name, num_rounds)
        subsssn = {
            'doc': getattr(models_module, 'doc', ''),
            'source_code': getattr(models_module, 'source_code', ''),
            'bibliography': getattr(models_module, 'bibliography', []),
            'links': sort_links(getattr(models_module, 'links', {})),
            'keywords': keywords_links(getattr(models_module, 'keywords', [])),
            'name': formatted_app_name,
        }
        seo.update(map(lambda (a, b): a, subsssn["keywords"]))
        app_sequence.append(subsssn)
    return {
        'doc': session_config['doc'],
        'app_sequence': app_sequence,
        'page_seo': seo
    }
Пример #8
0
 def get_context_data(self, **kwargs):
     context = super(ExportIndex, self).get_context_data(**kwargs)
     app_labels = settings.INSTALLED_OTREE_APPS
     app_labels_with_data = []
     for app_label in app_labels:
         model_module = otree.common_internal.get_models_module(app_label)
         if model_module.Player.objects.exists():
             app_labels_with_data.append(app_label)
     apps = [{"name": app_name_format(app_label), "label": app_label} for app_label in app_labels_with_data]
     context.update({"apps": apps})
     return context
Пример #9
0
 def get_context_data(self, **kwargs):
     context = super(ExportIndex, self).get_context_data(**kwargs)
     app_labels = settings.INSTALLED_OTREE_APPS
     app_labels_with_data = []
     for app_label in app_labels:
         model_module = otree.common_internal.get_models_module(app_label)
         if model_module.Player.objects.exists():
             app_labels_with_data.append(app_label)
     apps = [{
         "name": app_name_format(app_label),
         "label": app_label
     } for app_label in app_labels_with_data]
     context.update({'apps': apps})
     return context
Пример #10
0
    def get_context_data(self, **kwargs):
        context = super(ExportIndex, self).get_context_data(**kwargs)

        context['db_is_empty'] = not Participant.objects.exists()

        app_labels = settings.INSTALLED_OTREE_APPS
        app_labels_with_data = []
        for app_label in app_labels:
            model_module = otree.common_internal.get_models_module(app_label)
            if model_module.Player.objects.exists():
                app_labels_with_data.append(app_label)
        apps = [
            {"name": app_name_format(app_label), "label": app_label}
            for app_label in app_labels_with_data
        ]
        context['apps'] = apps
        return context
Пример #11
0
    def get_context_data(self, **kwargs):
        context = super(ExportIndex, self).get_context_data(**kwargs)

        context['db_is_empty'] = not Participant.objects.exists()

        app_labels = settings.INSTALLED_OTREE_APPS
        app_labels_with_data = []
        for app_label in app_labels:
            model_module = otree.common_internal.get_models_module(app_label)
            if model_module.Player.objects.exists():
                app_labels_with_data.append(app_label)
        apps = [{
            "name": app_name_format(app_label),
            "label": app_label
        } for app_label in app_labels_with_data]
        context['apps'] = apps

        context['extensions_views'] = get_extensions_data_export_views()

        return context
Пример #12
0
    def docs_as_lists(doc_dict):
        header = ["Model", "Field", "Type", "Description"]
        body = [['{}: Documentation'.format(app_name_format(app_name))],
                ['*' * 15],
                ['Accessed: {}'.format(datetime.date.today().isoformat())],
                ['']]

        app_doc = getattr(models_module, 'doc', '')
        if app_doc:
            body += [app_doc, '']

        for model_name in doc_dict:
            for member in doc_dict[model_name]:
                # lines.append('\t{}'.format(member))
                for info_type in doc_dict[model_name][member]:
                    # lines.append('\t\t{}'.format(info_type))
                    for info_line in doc_dict[model_name][member][info_type]:
                        # lines.append(u'{}{}'.format('\t' * 3, info_line))
                        body += [[model_name, member, info_type, info_line]]

        return header, body
Пример #13
0
def info_about_session_config(session_config):
    app_sequence = []
    for app_name in session_config['app_sequence']:
        models_module = get_models_module(app_name)
        num_rounds = models_module.Constants.num_rounds
        formatted_app_name = app_name_format(app_name)
        if num_rounds > 1:
            formatted_app_name = '{} ({} rounds)'.format(
                formatted_app_name, num_rounds)
        subsssn = {
            'doc': getattr(models_module, 'doc', ''),
            'bibliography': getattr(models_module, 'bibliography', []),
            'name': formatted_app_name,
        }
        app_sequence.append(subsssn)
    return {
        'doc': session_config['doc'],
        'app_sequence': app_sequence,
        'name': session_config['name'],
        'display_name': session_config['display_name'],
        'lcm': get_lcm(session_config)
    }
Пример #14
0
def info_about_session_config(session_config):
    app_sequence = []
    for app_name in session_config['app_sequence']:
        models_module = get_models_module(app_name)
        num_rounds = models_module.Constants.num_rounds
        formatted_app_name = app_name_format(app_name)
        if num_rounds > 1:
            formatted_app_name = '{} ({} rounds)'.format(
                formatted_app_name, num_rounds
            )
        subsssn = {
            'doc': getattr(models_module, 'doc', ''),
            'bibliography': getattr(models_module, 'bibliography', []),
            'name': formatted_app_name,
        }
        app_sequence.append(subsssn)
    return {
        'doc': session_config['doc'],
        'app_sequence': app_sequence,
        'name': session_config['name'],
        'display_name': session_config['display_name'],
        'lcm': get_lcm(session_config)
    }
Пример #15
0
    def test_export(self):

        session_config_name = 'export'
        app_name = 'tests.export'
        num_participants = 3
        num_sessions = 2

        # 3 sessions, 3 participants each is good to test alignment
        for i in range(num_sessions):
            otree.session.create_session(
                session_config_name=session_config_name,
                num_participants=num_participants,
            )

        formatted_app_name = common_internal.app_name_format(app_name)

        url = "/ExportCSV/{}/".format(app_name)
        response = self.client.get(url)

        # HEADERS CHECK
        content_disposition = response["Content-Disposition"]
        content_type = response["content-type"]

        self.assertEqual(content_type, "text/csv")

        self.assertTrue(
            content_disposition.startswith(
                'attachment; filename="{} ('.format(formatted_app_name)))

        csv_text = response.content.decode('utf-8')

        rows = [row for row in csv_text.split('\n') if row.strip()]

        # 1 row for each player + header row
        self.assertEqual(
            len(rows),
            num_sessions * num_participants * Constants.num_rounds + 1)

        header_row = rows[0]

        for expected_text in [
            'Participant.id_in_session',
            'Player.id_in_group',
            'Player.payoff',
            'Group.group_field',
            'Subsession.subsession_field',
            'Subsession.round_number',
            'Session.code',
        ]:
            self.assertIn(expected_text, header_row)

        # 3.14 should be in the CSV without any currency formatting
        for expected_text in ['should be in export CSV', ',3.14,']:
            self.assertIn(expected_text, csv_text)

        # True/False should be converted to 1/0
        self.assertNotIn('False', csv_text)

        # test alignment
        for row in rows[1:]:
            participant_code = re.search(',ALIGN_TO_PARTICIPANT_(\w+),', row).group(1)
            self.assertIn(r',{},'.format(participant_code), row)

            session_code = re.search(',ALIGN_TO_SESSION_(\w+),', row).group(1)
            self.assertIn(',{},'.format(session_code), row)

            group_id = re.search(',GROUP_(\d+),', row).group(1)
            self.assertIn(',ALIGN_TO_GROUP_{},'.format(group_id), row)

            subsession_id = re.search(',SUBSESSION_(\d+),', row).group(1)
            self.assertIn(',ALIGN_TO_SUBSESSION_{},'.format(subsession_id), row)