Пример #1
0
    def query(self, filters=None, order_column='', order_direction='',
              page=None, page_size=None):

        query = self.session.query(self.obj)
        if filters:
            query = filters.apply_all(query)
        if order_column != '':
            query = query.order_by(order_column + ' ' + order_direction)
        if page:
            query = query.offset(page * page_size)
        if page_size:
            query = query.limit(page_size)
        return query.all()
Пример #2
0
    def query(self, filters=None, order_column='', order_direction='',
              page=None, page_size=None):

        if filters:
            objs = filters.apply_all(self.obj.objects)
        else:
            objs = self.obj.objects
        count = len(objs)
        start, stop = 0, count
        if page:
            start = page * page_size
        if page_size:
            stop = start + page_size
        if order_column != '':
            if order_direction == 'asc':
                objs = objs.order_by('-{0}'.format(order_column))
            else:
                objs = objs.order_by('+{0}'.format(order_column))
        return count, objs[start:stop]
Пример #3
0
 def _get_base_query(query=None, filters=None, order_column='', order_direction=''):
     if filters:
         query = filters.apply_all(query)
     if order_column != '':
         query = query.order_by(order_column + ' ' + order_direction)
     return query