Пример #1
0
 def to_sql_filter(self):
     if self.show_all:
         return None
     if self.is_null:
         return ORFilter(
             [ISNULLFilter(field) for field in self.filter.fields])
     return ORFilter([
         INFilter(field,
                  get_INFilter_bindparams(self.filter.slug, self.value))
         for field in self.filter.fields
     ])
Пример #2
0
 def _build_additional_filters(self, filters):
     if len(filters) == 1:
         return self._map_filter_name_to_sql_filter(filters[0])
     return ORFilter([
         self._map_filter_name_to_sql_filter(filter_name)
         for filter_name in filters
     ])
Пример #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():
         if self.filter.get('datatype') in [
                 DATA_TYPE_DATE, DATA_TYPE_DATETIME
         ]:
             return ISNULLFilter(self.filter['field'])
         else:
             return ORFilter([
                 EQFilter(self.filter['field'], self.filter['slug']),
                 ISNULLFilter(self.filter['field']),
             ])
     elif self._is_exists():
         if self.filter.get('datatype') in [
                 DATA_TYPE_DATE, DATA_TYPE_DATETIME
         ]:
             return NOTNULLFilter(self.filter['field'])
         else:
             # 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'])
Пример #4
0
 def to_sql_filter(self):
     if self.show_all:
         return None
     location_id = self.value[0].value
     hierarchy = self.get_hierarchy(location_id)
     if len(hierarchy) == 1:
         f = self.get_hierarchy(location_id)[0]
         return EQFilter(f.column, f.parameter_slug)
     else:
         return ORFilter([
             EQFilter(x.column, x.parameter_slug)
             for x in self.get_hierarchy(location_id)
         ])
Пример #5
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]
Пример #6
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'])
Пример #7
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)
     ])