def test_filter(self):
     ds = UserDataSource({'user_id': 'user2'},
                         filters=[EQFilter('user', 'user_id')],
                         keys=[["user2"]],
                         group_by=['user'])
     data = ds.get_data()
     self.assertEqual(data, [{
         'cd': 50,
         'indicator_a': 1,
         'indicator_b': 1,
         'user': '******'
     }])
Exemple #2
0
 def to_sql_filter(self):
     if self._is_dyn_date():
         return BasicBetweenFilter(
             self.filter['field'],
             get_INFilter_bindparams(self.filter['slug'],
                                     ['start_date', 'end_date']))
     elif self._is_empty():
         return ORFilter([
             EQFilter(self.filter['field'], self.filter['slug']),
             ISNULLFilter(self.filter['field']),
         ])
     elif self._is_list():
         return self._array_filter(
             self.filter['field'],
             get_INFilter_bindparams(self.filter['slug'],
                                     self.value['operand']))
     else:
         return self._scalar_filter(self.filter['field'],
                                    self.filter['slug'])
Exemple #3
0
 def to_sql_filter(self):
     if self._is_dyn_date():
         return BasicBetweenFilter(
             self.filter['field'],
             get_INFilter_bindparams(self.filter['slug'],
                                     ['start_date', 'end_date']))
     elif self._is_empty():
         return ORFilter([
             EQFilter(self.filter['field'], self.filter['slug']),
             ISNULLFilter(self.filter['field']),
         ])
     elif self._is_exists():
         # this resolves to != '', which also filters out null data in postgres
         return NOTEQFilter(self.filter['field'], self.filter['slug'])
     elif self._is_list():
         return self._array_filter(
             self.filter['field'],
             get_INFilter_bindparams(self.filter['slug'],
                                     self.value['operand']))
     else:
         return self._scalar_filter(self.filter['field'],
                                    self.filter['slug'])
Exemple #4
0
    def to_sql_filter(self):
        if self.show_all:
            return None

        sql_filters = []

        non_null_values = self._get_value_without_nulls()
        if non_null_values:
            in_filter = INFilter(
                self.filter['field'],
                get_INFilter_bindparams(self.filter['slug'], non_null_values)
            )
            if self._ancestor_filter:
                sql_filters.append(ANDFilter([
                    self._ancestor_filter.sql_filter(),
                    in_filter,
                ]))
            else:
                sql_filters.append(in_filter)
        elif self._ancestor_filter:
            sql_filters.append(self._ancestor_filter.sql_filter())

        if self.is_null:
            # combine null and blank fields into a single filter
            sql_filters.append(
                ORFilter([
                    ISNULLFilter(self.filter['field']),
                    EQFilter(self.filter['field'], get_null_empty_value_bindparam(self.filter['slug'])),
                ])
            )

        if len(sql_filters) > 1:
            return ORFilter(
                sql_filters
            )
        else:
            return sql_filters[0]
Exemple #5
0
 def sql_filter(self):
     return EQFilter(self.ancestor_expression['field'],
                     self.ancestor_expression['field'])
Exemple #6
0
 def to_sql_filter(self):
     location_id = self.value[0].value
     return ORFilter([
         EQFilter(x.column, x.parameter_slug)
         for x in self.get_hierarchy(location_id)
     ])