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)
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)