示例#1
0
    def p_simple_expr_key(self, p):
        """
        simple_expr : KEY STRING
        """
        key, value = p[1], p[2]

        if key == 'from':
            try:
                from_clause = QUERY_PARSER.parse('select * from ' +
                                                 value).from_clause
                c_from = query_compile.compile_from(from_clause, ENV_ENTRIES)
            except (query_compile.CompilationError,
                    query_parser.ParseError) as exception:
                raise FilterException('from', str(exception))
            p[0] = c_from.c_expr
            return

        match = Match(value)

        def _key(entry):
            if hasattr(entry, key):
                return match(str(getattr(entry, key) or ''))
            if key in entry.meta:
                return match(str(entry.meta.get(key)))
            return False

        p[0] = _key
示例#2
0
def get_matching_entries(entries, options_map, query):
    query_text = 'SELECT * ' + query
    parser = query_parser.Parser()
    parsed_query = parser.parse(query_text)
    c_from = None
    if parsed_query.from_clause:
        c_from = query_compile.compile_from(parsed_query.from_clause, query_env.FilterEntriesEnvironment())
    c_where = None
    if parsed_query.where_clause:
        c_where = query_compile.compile_expression(parsed_query.where_clause, query_env.FilterPostingsEnvironment())

    # Figure out if we need to compute balance.
    balance = None
    if c_where and query_execute.uses_balance_column(c_where):
        balance = inventory.Inventory()

    context = query_execute.RowContext()
    context.balance = balance
    

    # Initialize some global properties for use by some of the accessors.
    context.options_map = options_map
    context.account_types = options.get_account_types(options_map)
    context.open_close_map = getters.get_account_open_close(entries)
    #context.commodity_map = getters.get_commodity_map(entries)
    context.price_map = prices.build_price_map(entries) 

    if c_from is not None:
        filtered_entries = query_execute.filter_entries(c_from, entries, options_map)
    else:
        filtered_entries = entries
    return filtered_entries
示例#3
0
文件: filters.py 项目: mhansen/fava
 def set(self, value):
     if value == self.value:
         return False
     self.value = value
     if not self.value:
         return True
     try:
         from_clause = self.parser.parse('select * from ' +
                                         value).from_clause
         self.c_from = query_compile.compile_from(from_clause,
                                                  self.env_entries)
     except (query_compile.CompilationError,
             query_parser.ParseError) as exception:
         raise FilterException('from', str(exception))
     return True
示例#4
0
文件: filters.py 项目: yagebu/fava
 def set(self, value):
     if value == self.value:
         return False
     self.value = value
     if not self.value:
         return True
     try:
         from_clause = self.parser.parse(
             'select * from ' + value).from_clause
         self.c_from = query_compile.compile_from(
             from_clause, self.env_entries)
     except (query_compile.CompilationError,
             query_parser.ParseError) as exception:
         raise FilterException('from', str(exception))
     return True