Пример #1
0
    def _get_index_values(self, result):
        """Get index values from last result, to be used in seeking to the next
        page. Optionally include sort values, if any.
        """
        from webservices.common.models import db
        ret = {
            'last_index': str(paginators.convert_value(
                result,
                self.index_column
            ))
        }

        if self.sort_column:
            key = 'last_{0}'.format(self.sort_column[2])

            # Check to see if we are dealing with a sort column or sort
            # expression.  If we're dealing with a sort expression, we need to
            # override the value serialization with the sort expression
            # information.
            if not self.sort_column[3]:
                ret[key] = paginators.convert_value(
                    result,
                    self.sort_column[0]
                )
            else:
                # Create a new query based on the result returned and replace
                # the SELECT portion with just the sort expression criteria.
                # Also augment the WHERE clause with a match for the value of
                # the index column found in the result so we only retrieve the
                # single row matching the result.
                # NOTE:  This ensures we maintain existing clauses such as the
                # check constraint needed for partitioned tables.
                sort_column_query = self.cursor.with_entities(self.sort_column[0]).filter(
                    getattr(result.__class__, self.index_column.key) == getattr(result, self.index_column.key)
                )

                # Execute the new query to retrieve the value of the sort
                # expression.
                expression_value = db.engine.execute(
                    sort_column_query.statement
                ).scalar()

                # Serialize the value using the mapped marshmallow field
                # defined with the sort expression.
                ret[key] = self.sort_column[4]()._serialize(
                    expression_value,
                    None,
                    None
                )

            if ret[key] is None:
                ret.pop(key)
                ret['sort_null_only'] = True

        return ret
Пример #2
0
    def _get_index_values(self, result):
        """Get index values from last result, to be used in seeking to the next
        page. Optionally include sort values, if any.
        """
        ret = {
            'last_index': str(paginators.convert_value(
                result,
                self.index_column
            ))
        }

        if self.sort_column:
            key = 'last_{0}'.format(self.sort_column[2])

            # Check to see if we are dealing with a sort column or sort
            # expression.  If we're dealing with a sort expression, we need to
            # override the value serialization with the sort expression
            # information.
            if not self.sort_column[3]:
                ret[key] = paginators.convert_value(
                    result,
                    self.sort_column[0]
                )
            else:
                # Create a new query based on the result returned and replace
                # the SELECT portion with just the sort expression criteria.
                # Also augment the WHERE clause with a match for the value of
                # the index column found in the result so we only retrieve the
                # single row matching the result.
                # NOTE:  This ensures we maintain existing clauses such as the
                # check constraint needed for partitioned tables.
                sort_column_query = self.cursor.with_entities(self.sort_column[0]).filter(
                    getattr(result.__class__, self.index_column.key) == getattr(result, self.index_column.key)
                )

                # Execute the new query to retrieve the value of the sort
                # expression.
                expression_value = db.engine.execute(
                    sort_column_query.statement
                ).scalar()

                # Serialize the value using the mapped marshmallow field
                # defined with the sort expression.
                ret[key] = self.sort_column[4]()._serialize(
                    expression_value,
                    None,
                    None
                )

            if ret[key] is None:
                ret.pop(key)
                ret['sort_null_only'] = True

        return ret
Пример #3
0
 def _get_index_values(self, result):
     """Get index values from last result, to be used in seeking to the next
     page. Optionally include sort values, if any.
     """
     ret = {
         'last_index': paginators.convert_value(result, self.index_column)
     }
     if self.sort_column:
         key = 'last_{0}'.format(self.sort_column[0].key)
         ret[key] = paginators.convert_value(result, self.sort_column[0])
         if ret[key] is None:
             ret.pop(key)
             ret['sort_null_only'] = True
     return ret