Exemplo n.º 1
0
def _get_query(model, where):
    """
    Return a query on the given model

    :param cls model: The model to get items from
    :param list where: List of criteria in dict form
    :returns: A SQLA query
    :rtype: obj
    """
    from autonomie.models.statistics import StatisticEntry
    from autonomie.views.statistics import (
        CRITERION_MODELS,
        get_inspector,
    )
    from autonomie.statistics import EntryQueryFactory

    entry = StatisticEntry(title="script related entry", description="")

    for criterion_dict in where:
        criterion_factory = CRITERION_MODELS[criterion_dict['type']]
        entry.criteria.append(criterion_factory(**criterion_dict))

    inspector = get_inspector(model)
    query_factory = EntryQueryFactory(model, entry, inspector)
    return query_factory.query()
Exemplo n.º 2
0
def _get_query(model, where):
    """
    Return a query on the given model

    :param cls model: The model to get items from
    :param list where: List of criteria in dict form
    :returns: A SQLA query
    :rtype: obj
    """
    from autonomie.models.statistics import StatisticEntry
    from autonomie.views.statistics import (
        CRITERION_MODELS,
        get_inspector,
    )
    from autonomie.statistics import EntryQueryFactory

    entry = StatisticEntry(title="script related entry", description="")

    for criterion_dict in where:
        criterion_factory = CRITERION_MODELS[criterion_dict['type']]
        entry.criteria.append(criterion_factory(**criterion_dict))

    inspector = get_inspector()
    query_factory = EntryQueryFactory(model, entry, inspector)
    return query_factory.query()
Exemplo n.º 3
0
def get_query(model, where):
    """
    Return a query on the given model based on a filter list


    E.g :

        get_query(
            UserDatas,
            [
                {
                    "key":"created_at",
                    "method":"dr",
                    "type":"date",
                    "search1":"1999-01-01",
                    "search2":"2016-12-31"
                }
            ]
        )

    Filter syntax

        key

            The model attribute

        method

            See autonomie.statistics.__init__.py for keywords and their meaning

        type

            One of
                string
                number
                bool

        search1

            The first search entry

        search2

            Regarding the method of this filter, we may need a second parameter



    :param cls model: The model to get items from
    :param list where: List of criteria in dict form
    :returns: A SQLA query
    :rtype: obj
    """
    entry = StatisticEntry(title="script related entry", description="")

    for criterion_dict in where:
        criterion_factory = CRITERION_MODELS[criterion_dict['type']]
        entry.criteria.append(criterion_factory(**criterion_dict))

    inspector = get_inspector(model)
    query_factory = EntryQueryFactory(model, entry, inspector)
    return query_factory.query()
Exemplo n.º 4
0
 def query(self):
     inspector = get_inspector()
     query_factory = EntryQueryFactory(UserDatas, self.context, inspector)
     query = query_factory.query()
     return query
Exemplo n.º 5
0
 def query(self):
     inspector = get_inspector()
     query_factory = EntryQueryFactory(UserDatas, self.context, inspector)
     query = query_factory.query()
     return query