Beispiel #1
0
    def _get_data(self, slugs=None):
        if self.keys is not None and not self.group_by:
            raise SqlReportException('Keys supplied without group_by.')

        qc = self.query_context
        for c in self.columns:
            if not slugs or c.slug in slugs:
                qc.append_column(c.view)

        session = connection_manager.get_scoped_session(self.engine_id)

        try:
            for qm in qc.query_meta.values():
                date_aggregation_column = None
                if len(qm.columns) == 1:
                    c = self._find_column(qm.columns[0].column_name)
                    if hasattr(c, 'date_aggregation_column'):
                        date_aggregation_column = c.date_aggregation_column
                columns_names = itertools.chain.from_iterable([(col.column_name, col.alias) for col in qm.columns])
                for group_by in self.group_by:
                    if group_by not in columns_names:
                        column = self._find_column_view(group_by)
                        if column:
                            if date_aggregation_column:
                                column.key = date_aggregation_column
                                column.sql_column.column_name = date_aggregation_column
                            qm.append_column(column)

            return qc.resolve(session.connection(), self.filter_values)
        except:
            session.rollback()
            raise
Beispiel #2
0
    def _get_data(self, slugs=None):
        if self.keys is not None and not self.group_by:
            raise SqlReportException('Keys supplied without group_by.')

        qc = self.query_context
        for c in self.columns:
            if not slugs or c.slug in slugs:
                qc.append_column(c.view)

        session = connection_manager.get_scoped_session(self.engine_id)
        try:
            return qc.resolve(session.connection(), self.filter_values)
        except:
            session.rollback()
            raise
Beispiel #3
0
    def _get_data(self, slugs=None):
        if self.keys is not None and not self.group_by:
            raise SqlReportException('Keys supplied without group_by.')

        qc = self.query_context
        for c in self.columns:
            if not slugs or c.slug in slugs:
                qc.append_column(c.view)

        session = connection_manager.get_scoped_session(self.engine_id)
        try:
            return qc.resolve(session.connection(), self.filter_values)
        except:
            session.rollback()
            raise