Exemple #1
0
    def _run_report(spec, engine_id=None):
        data_source = ConfigurableReportDataSource.from_spec(spec, include_prefilters=True)
        if engine_id:
            data_source.data_source.override_engine_id(engine_id)
        data_source.set_filter_values(filter_values)
        if sort_column:
            data_source.set_order_by(
                [(data_source.top_level_columns[int(sort_column)].column_id, sort_order.upper())]
            )

        if params:
            datatables_params = DatatablesParams.from_request_dict(params)
            start = datatables_params.start
            limit = datatables_params.count
        else:
            start, limit = None, None
        page = list(data_source.get_data(start=start, limit=limit))
        total_records = data_source.get_total_records()
        json_response = {
            'aaData': page,
            "iTotalRecords": total_records,
        }
        total_row = data_source.get_total_row() if data_source.has_total_row else None
        if total_row is not None:
            json_response["total_row"] = total_row
        return json_response
Exemple #2
0
    def _run_report(spec, engine_id=None):
        data_source = ConfigurableReportDataSource.from_spec(spec, include_prefilters=True)
        if engine_id:
            data_source.override_engine_id(engine_id)
        data_source.set_filter_values(filter_values)
        if sort_column:
            data_source.set_order_by(
                [(data_source.top_level_columns[int(sort_column)].column_id, sort_order.upper())]
            )

        if params:
            datatables_params = DatatablesParams.from_request_dict(params)
            start = datatables_params.start
            limit = datatables_params.count
        else:
            start, limit = None, None
        page = list(data_source.get_data(start=start, limit=limit))
        total_records = data_source.get_total_records()
        json_response = {
            'aaData': page,
            "iTotalRecords": total_records,
        }
        total_row = data_source.get_total_row() if data_source.has_total_row else None
        if total_row is not None:
            json_response["total_row"] = total_row
        return json_response
Exemple #3
0
    def get_ajax(self, params):
        sort_column = params.get('iSortCol_0')
        sort_order = params.get('sSortDir_0', 'ASC')
        echo = int(params.get('sEcho', 1))
        datatables_params = DatatablesParams.from_request_dict(params)

        try:
            data_source = self.data_source
            if len(data_source.inner_columns
                   ) > 50 and not DISABLE_COLUMN_LIMIT_IN_UCR.enabled(
                       self.domain):
                raise UserReportsError(
                    _("This report has too many columns to be displayed"))
            data_source.set_filter_values(self.filter_values)

            if sort_column and echo != 1:
                data_source.set_order_by([
                    (data_source.top_level_columns[int(sort_column)].column_id,
                     sort_order.upper())
                ])

            page = list(
                data_source.get_data(start=datatables_params.start,
                                     limit=datatables_params.count))
            page = self.sanitize_page(page)
            total_records = data_source.get_total_records()
            total_row = data_source.get_total_row(
            ) if data_source.has_total_row else None
        except UserReportsError as e:
            if settings.DEBUG:
                raise
            return self.render_json_response({
                'error': str(e),
                'aaData': [],
                'iTotalRecords': 0,
                'iTotalDisplayRecords': 0,
            })
        except TableNotFoundWarning:
            if self.spec.report_meta.created_by_builder:
                msg = _(
                    "The database table backing your report does not exist yet. "
                    "Please wait while the report is populated.")
            else:
                msg = _(
                    "The database table backing your report does not exist yet. "
                    "You must rebuild the data source before viewing the report."
                )
            return self.render_json_response({'warning': msg})

        json_response = {
            'aaData': page,
            "sEcho": params.get('sEcho', 0),
            "iTotalRecords": total_records,
            "iTotalDisplayRecords": total_records,
        }
        if total_row is not None:
            json_response["total_row"] = total_row
        return self.render_json_response(json_response)
Exemple #4
0
    def get_ajax(self, params):
        try:
            data_source = self.data_source
            if len(data_source.inner_columns) > 50 and not DISABLE_COLUMN_LIMIT_IN_UCR.enabled(self.domain):
                raise UserReportsError(_("This report has too many columns to be displayed"))
            data_source.set_filter_values(self.filter_values)

            sort_column = params.get('iSortCol_0')
            sort_order = params.get('sSortDir_0', 'ASC')
            echo = int(params.get('sEcho', 1))
            if sort_column and echo != 1:
                data_source.set_order_by(
                    [(data_source.top_level_columns[int(sort_column)].column_id, sort_order.upper())]
                )

            datatables_params = DatatablesParams.from_request_dict(params)
            page = list(data_source.get_data(start=datatables_params.start, limit=datatables_params.count))
            total_records = data_source.get_total_records()
            total_row = data_source.get_total_row() if data_source.has_total_row else None
        except UserReportsError as e:
            if settings.DEBUG:
                raise
            return self.render_json_response({
                'error': e.message,
                'aaData': [],
                'iTotalRecords': 0,
                'iTotalDisplayRecords': 0,
            })
        except TableNotFoundWarning:
            if self.spec.report_meta.created_by_builder:
                msg = _(
                    "The database table backing your report does not exist yet. "
                    "Please wait while the report is populated."
                )
            else:
                msg = _(
                    "The database table backing your report does not exist yet. "
                    "You must rebuild the data source before viewing the report."
                )
            return self.render_json_response({
                'warning': msg
            })

        json_response = {
            'aaData': page,
            "sEcho": params.get('sEcho', 0),
            "iTotalRecords": total_records,
            "iTotalDisplayRecords": total_records,
        }
        if total_row is not None:
            json_response["total_row"] = total_row
        return self.render_json_response(json_response)
 def pagination(self):
     if self._pagination is None:
         self._pagination = DatatablesParams.from_request_dict(
             self.request.POST if self.request.method ==
             'POST' else self.request.GET)
     return self._pagination
Exemple #6
0
 def pagination(self):
     if self._pagination is None:
         self._pagination = DatatablesParams.from_request_dict(
             self.request.POST if self.request.method == 'POST' else self.request.GET
         )
     return self._pagination