Exemplo n.º 1
0
    def _run_report(backend_to_use):
        data_source = ReportFactory.from_spec(spec,
                                              include_prefilters=True,
                                              backend=backend_to_use)
        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
Exemplo n.º 2
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
        if data_source.data_source.config.backend_id == UCR_LABORATORY_BACKEND:
            compare_ucr_dbs.delay(self.domain, self.report_config_id,
                                  self.filter_values, sort_column, sort_order,
                                  params)
        return self.render_json_response(json_response)
Exemplo n.º 3
0
    def get_ajax(self, request):
        try:
            data_source = self.data_source
            if len(data_source.columns) > 50:
                raise UserReportsError(_("This report has too many columns to be displayed"))
            data_source.set_filter_values(self.filter_values)

            sort_column = request.GET.get('iSortCol_0')
            sort_order = request.GET.get('sSortDir_0', 'ASC')
            echo = int(request.GET.get('sEcho', 1))
            if sort_column and echo != 1:
                data_source.set_order_by(
                    [(data_source.column_configs[int(sort_column)].column_id, sort_order.upper())]
                )
            total_records = data_source.get_total_records()
        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
            })

        # todo: this is ghetto pagination - still doing a lot of work in the database
        datatables_params = DatatablesParams.from_request_dict(request.GET)
        end = min(datatables_params.start + datatables_params.count, total_records)
        data = list(data_source.get_data())
        page = data[datatables_params.start:end]

        json_response = {
            'aaData': page,
            "sEcho": self.request_dict.get('sEcho', 0),
            "iTotalRecords": total_records,
            "iTotalDisplayRecords": total_records,
        }
        if data_source.has_total_row:
            json_response.update({
                "total_row": get_total_row(
                    data, data_source.aggregation_columns, data_source.column_configs,
                    get_expanded_columns(data_source.column_configs, data_source.config)
                ),
            })
        return self.render_json_response(json_response)
Exemplo n.º 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
        if data_source.data_source.config.backend_id == UCR_LABORATORY_BACKEND:
            compare_ucr_dbs.delay(
                self.domain, self.report_config_id, self.filter_values,
                sort_column, sort_order, params
            )
        return self.render_json_response(json_response)
Exemplo n.º 5
0
    def get_ajax(self, request):
        try:
            data_source = self.data_source
            if len(data_source.columns) > 50:
                raise UserReportsError(_("This report has too many columns to be displayed"))
            data_source.set_filter_values(self.filter_values)

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

            datatables_params = DatatablesParams.from_request_dict(request.GET)
            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": self.request_dict.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)
Exemplo n.º 6
0
    def get_ajax(self, request):
        try:
            data_source = self.data_source
            if len(data_source.columns) > 50:
                raise UserReportsError(_("This report has too many columns to be displayed"))
            data_source.set_filter_values(self.filter_values)

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

            datatables_params = DatatablesParams.from_request_dict(request.GET)
            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": self.request_dict.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)
Exemplo n.º 7
0
    def get_ajax(self, request, domain=None, **kwargs):
        data = self.data_source
        data.set_filter_values(self.filter_values)
        total_records = data.get_total_records()

        # todo: this is ghetto pagination - still doing a lot of work in the database
        datatables_params = DatatablesParams.from_request_dict(request.GET)
        end = min(datatables_params.start + datatables_params.count, total_records)
        page = list(data.get_data())[datatables_params.start:end]
        return self.render_json_response({
            'aaData': page,
            "sEcho": self.request_dict.get('sEcho', 0),
            "iTotalRecords": total_records,
            "iTotalDisplayRecords": total_records,
        })
Exemplo n.º 8
0
    def get_ajax(self, request, domain=None, **kwargs):
        try:
            data = self.data_source
            data.set_filter_values(self.filter_values)
            data.set_order_by([(o['field'], o['order']) for o in self.spec.sort_expression])
            total_records = data.get_total_records()
        except UserReportsError as e:
            if settings.DEBUG:
                raise
            return self.render_json_response({
                'error': e.message,
            })
        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
            })

        # todo: this is ghetto pagination - still doing a lot of work in the database
        datatables_params = DatatablesParams.from_request_dict(request.GET)
        end = min(datatables_params.start + datatables_params.count, total_records)
        page = list(data.get_data())[datatables_params.start:end]
        return self.render_json_response({
            'aaData': page,
            "sEcho": self.request_dict.get('sEcho', 0),
            "iTotalRecords": total_records,
            "iTotalDisplayRecords": total_records,
        })
Exemplo n.º 9
0
 def pagination(self):
     if self._pagination is None:
         self._pagination = DatatablesParams.from_request_dict(self.request.REQUEST)
     return self._pagination
Exemplo n.º 10
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
Exemplo n.º 11
0
 def pagination(self):
     if self._pagination is None:
         self._pagination = DatatablesParams.from_request_dict(
             self.request.REQUEST)
     return self._pagination
Exemplo n.º 12
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