def _get_debug_tables(self, vars_for_template): tables = [] if vars_for_template: # use repr() so that we can distinguish strings from numbers # and can see currency types, etc. items = [(k, repr(v)) for (k, v) in vars_for_template.items()] rows = sorted(items) tables.append(DebugTable(title='vars_for_template', rows=rows)) player = self.player participant = self.participant basic_info_table = DebugTable( title='Basic info', rows=[ ('ID in group', player.id_in_group), ('Group', player.group_id), ('Round number', player.round_number), ('Participant', participant._id_in_session()), ('Participant label', participant.label or ''), ('Session code', participant._session_code), ], ) tables.append(basic_info_table) return tables
def get_context_data(self, **kwargs): cleaned_data = kwargs['form'].cleaned_data models_module = get_models_module(cleaned_data['app_name']) subsession = models_module.Subsession.objects.get( session=self.session, round_number=cleaned_data['round_number'] ) vars_for_admin_report = subsession.vars_for_admin_report() or {} self.debug_tables = [ DebugTable( title='vars_for_admin_report', rows=vars_for_admin_report.items() ) ] # determine whether to display debug tables self.is_debug = settings.DEBUG app_label = subsession._meta.app_config.label user_template = select_template( [f'{app_label}/admin_report.html', f'{app_label}/AdminReport.html'] ) context = super().get_context_data( subsession=subsession, Constants=models_module.Constants, user_template=user_template, **kwargs, ) # it's passed by parent class assert 'session' in context # this should take priority, in the event of a clash between # a user-defined var and a built-in one context.update(vars_for_admin_report) return context
def get_context_data(self, **kwargs): form = kwargs['form'] models_module = get_models_module(form.app_name.data) subsession = models_module.Subsession.objects_get( session=self.session, round_number=form.round_number.data) vars_for_admin_report = subsession.vars_for_admin_report() or {} self.debug_tables = [ DebugTable(title='vars_for_admin_report', rows=vars_for_admin_report.items()) ] app_label = subsession.get_folder_name() user_template = get_template_name_if_exists([ f'{app_label}/admin_report.html', f'{app_label}/AdminReport.html' ]) context = super().get_context_data( subsession=subsession, Constants=models_module.Constants, user_template=user_template, **kwargs, ) # it's passed by parent class assert 'session' in context # this should take priority, in the event of a clash between # a user-defined var and a built-in one context.update(vars_for_admin_report) return context