def get_report_and_states(report_id): if content_type == '': raise Http404 if '.' in content_type: app,model = content_type.split('.') ct = get_object_or_404(ContentType, app_label=app, model=model) else: ct = get_object_or_404(ContentType, pk=int(content_type)) is_custom = False if report_id == '-1': default = StateReport.objects.default(ct) report_id = default.id is_custom = default.menu_order == -1 if is_custom: machine = get_machine(ct) checkboxes = [p[0][5:] for p in request.GET.items() if p[0][:5] == 'ITEM_'] report = default all_states = [{'obj': state, 'enabled': state[1] in checkboxes, 'count': State.objects.filter(state_id=state[0]).count()} for state in machine.states] states = State.objects.none() for checkbox in checkboxes: state_id = machine.states_dict_code[checkbox][0] states = states | State.objects.filter(state_id=state_id) else: all_states = [] report = get_object_or_404(StateReport, pk=report_id) states = report.states return report, states, all_states, ct, is_custom