Example #1
0
    def create_query_set(self, query_set):
        """
            Creates a QuerySet beginning with the given query_set and apply various filters
        """
        starting_query_set = query_set

        # Filter by bounds if present and selection_options.constrain_to_bounds is True (default True)
        # or if no filters or joins are present (joins are inner joins, so function as filters)
        bounded_query_set = starting_query_set.filter(wkb_geometry__intersects=self.geometry) if \
            self.geometry != DEFAULT_GEOMETRY and (
                self.selection_options.get('constrain_to_bounds', True) or
                not (self.filter or self.joins)) else \
            starting_query_set

        # Filter by filter if present
        if self.filter and self.selection_options.get('constrain_to_query', True):
            # If filters have been specified then perform the query.
            return parse_query(self.config_entity, bounded_query_set, filters=self.filter, joins=self.joins)
        elif self.geometry != DEFAULT_GEOMETRY:
            # Return the result unless neither bounded or filtered.
            # Specifying nothing results in an empty query set (i.e. we don't allow select all)
            return parse_query(self.config_entity, bounded_query_set, joins=self.joins)
        elif self.joins:
            return parse_query(self.config_entity, bounded_query_set, joins=self.joins)
        else:
            query_set.none()
Example #2
0
    def sync_summary_query_set(self, query_set):
        if not self.aggregates and not self.group_bys:
            return None

        # Filter by bounds if present
        bounded_query_set = self.feature_class.objects.filter(wkb_geometry__intersects=self.geometry) \
            if self.geometry != DEFAULT_GEOMETRY else query_set

        # If filters have been specified then perform the query.
        return parse_query(self.config_entity, bounded_query_set, filters=self.filter, joins=self.joins,
                           group_bys=self.group_bys, aggregates=self.aggregates)