示例#1
0
    def query(self):
        """
        Return the main query used to find objects

        e.g:

            query = DBSESSION().query(distinct(UserDatas.id), UserDatas)
            query = query.filter(UserDatas.name.startswith('test'))
            query = query.outerjoin(UserDatas.conseiller)
            query = query.filter(User.lastname=='A manager')
            query = query.filter(
                UserDatas.id.in_(
                    [list of ids retrieved from independant queries]
                )
            )

        """
        self.already_joined = []
        if self.root:
            main_query = DBSESSION().query(distinct(self.model.id), self.model)
        else:
            main_query = DBSESSION().query(distinct(self.model.id))

        # Pour chaque critère sur lesquels on va ajouter des filtres, on a
        # besoin d'être sûr que la classe concernée est bien requêtée, il faut
        # donc ajouter des outerjoins pour chaque classe liée.

        # NOTE: on ne gère pas les alias (les joins sur deux tables identiques
        # pour deux relations différentes)
        for criterion in self.query_helpers:
            # On génère le filtre
            filter_ = criterion.gen_filter()
            having = criterion.gen_having_clause()

            # si il y a un filtre ...
            if filter_ is not None:
                main_query = self.join(main_query, criterion)
                main_query = main_query.filter(filter_)

            elif having is not None:
                main_query = self.join(main_query, criterion)
                main_query = main_query.group_by(self.model.id)
                main_query = main_query.having(having)

        if self.query_factories:
            ids = list(self._get_ids_from_factories())
            main_query = main_query.filter(self.model.id.in_(ids))

        return main_query
示例#2
0
    def query(self):
        """
        Return the main query used to find objects

        e.g:

            query = DBSESSION().query(distinct(UserDatas.id), UserDatas)
            query = query.filter(UserDatas.name.startswith('test'))
            query = query.outerjoin(UserDatas.conseiller)
            query = query.filter(User.lastname=='A manager')
            query = query.filter(
                UserDatas.id.in_(
                    [list of ids retrieved from independant queries]
                )
            )

        """
        self.already_joined = []
        if self.root:
            main_query = DBSESSION().query(distinct(self.model.id), self.model)
        else:
            main_query = DBSESSION().query(distinct(self.model.id))

        # Pour chaque critère sur lesquels on va ajouter des filtres, on a
        # besoin d'être sûr que la classe concernée est bien requêtée, il faut
        # donc ajouter des outerjoins pour chaque classe liée.

        # NOTE: on ne gère pas les alias (les joins sur deux tables identiques
        # pour deux relations différentes)
        for criterion in self.query_helpers:
            # On génère le filtre
            filter_ = criterion.gen_filter()
            having = criterion.gen_having_clause()

            # si il y a un filtre ...
            if filter_ is not None:
                main_query = self.join(main_query, criterion)
                main_query = main_query.filter(filter_)

            elif having is not None:
                main_query = self.join(main_query, criterion)
                main_query = main_query.group_by(self.model.id)
                main_query = main_query.having(having)

        if self.query_factories:
            ids = list(self._get_ids_from_factories())
            main_query = main_query.filter(self.model.id.in_(ids))

        return main_query
示例#3
0
def add_custom_datas_headers(writer, query):
    """
    Add custom headers that are not added through automation
    """
    # Compte analytique
    query = DBSESSION().query(
        func.count(COMPANY_EMPLOYEE.c.company_id).label('nb'))
    query = query.group_by(COMPANY_EMPLOYEE.c.account_id)
    code_compta_count = query.order_by(desc("nb")).first()
    if code_compta_count:
        code_compta_count = code_compta_count[0]
        for index in range(0, code_compta_count):
            new_header = {
                'label': "Compte_analytique {0}".format(index + 1),
                'name': "code_compta_{0}".format(index + 1),
            }
            writer.add_extra_header(new_header)

    return writer
示例#4
0
def add_custom_datas_headers(writer, query):
    """
    Add custom headers that are not added through automation
    """
    # Compte analytique
    query = DBSESSION().query(
        func.count(COMPANY_EMPLOYEE.c.company_id).label('nb')
    )
    query = query.group_by(COMPANY_EMPLOYEE.c.account_id)
    code_compta_count = query.order_by(desc("nb")).first()
    if code_compta_count:
        code_compta_count = code_compta_count[0]
        for index in range(0, code_compta_count):
            new_header = {
                'label': "Compte_analytique {0}".format(index + 1),
                'name': "code_compta_{0}".format(index + 1),
            }
            writer.add_extra_header(new_header)

    return writer