def index(self, list_type=1, direction='dsc', order_by='id', page=1, format=None): "Page through lists" total_found = 0 search_time = 0 num_items = session.get('lists_num_items', 10) if direction == 'dsc': sort = desc(order_by) else: sort = order_by qry = request.GET.get('q', None) kwds = {} if qry: kwds['presliced_list'] = True conn = SphinxClient() sphinxopts = extract_sphinx_opts(config['sphinx.url']) conn.SetServer(sphinxopts.get('host', '127.0.0.1')) conn.SetMatchMode(SPH_MATCH_EXTENDED2) conn.SetFilter('list_type', [ int(list_type), ]) if not c.user.is_superadmin: conn.SetFilter('user_id', [ c.user.id, ]) if page == 1: conn.SetLimits(0, num_items, 500) else: page = int(page) offset = (page - 1) * num_items conn.SetLimits(offset, num_items, 500) try: results = conn.Query(qry, 'lists, lists_rt') except (socket.timeout, struct.error): redirect(request.path_qs) if results and results['matches']: ids = [hit['id'] for hit in results['matches']] total_found = results['total_found'] search_time = results['time'] items = Session.query(List)\ .filter(List.list_type == list_type)\ .filter(List.id.in_(ids))\ .order_by(sort)\ .all() listcount = total_found else: items = [] itemcount = 0 listcount = 0 else: items = Session.query(List)\ .filter(List.list_type == list_type)\ .order_by(sort) itemcount = Session.query(List.id)\ .filter(List.list_type == list_type) if not c.user.is_superadmin: items = items.filter(List.user_id == c.user.id) itemcount = itemcount.filter(List.user_id == c.user.id) listcount = itemcount.count() # pylint: disable-msg=W0142 records = paginate.Page(items, page=int(page), items_per_page=num_items, item_count=listcount, **kwds) if format == 'json': response.headers['Content-Type'] = 'application/json' data = convert_list_to_json(records, list_type) return data c.list_type = list_type c.page = records c.direction = direction c.order_by = order_by c.q = qry c.total_found = total_found c.search_time = search_time return self.render('/lists/index.html')
def index(self, list_type=1, direction='dsc', order_by='id', page=1, format=None): "Page through lists" total_found = 0 search_time = 0 num_items = session.get('lists_num_items', 10) if direction == 'dsc': sort = desc(order_by) else: sort = order_by q = request.GET.get('q', None) kwds = {} if q: kwds['presliced_list'] = True conn = SphinxClient() conn.SetMatchMode(SPH_MATCH_EXTENDED2) conn.SetFilter('list_type', [int(list_type),]) if page == 1: conn.SetLimits(0, num_items, 500) else: page = int(page) offset = (page - 1) * num_items conn.SetLimits(offset, num_items, 500) results = conn.Query(q, 'lists, lists-rt') if results and results['matches']: ids = [hit['id'] for hit in results['matches']] total_found = results['total_found'] search_time = results['time'] items = Session.query(List)\ .filter(List.list_type == list_type)\ .filter(List.id.in_(ids))\ .order_by(sort)\ .all() listcount = total_found else: items = [] itemcount = 0 listcount = 0 else: items = Session.query(List)\ .filter(List.list_type == list_type)\ .order_by(sort) itemcount = Session.query(List.id)\ .filter(List.list_type == list_type) if c.user.account_type != 1 and itemcount: items = items.filter(List.user_id == c.user.id) itemcount = itemcount.filter(List.user_id == c.user.id) if not 'listcount' in locals(): listcount = itemcount.count() records = paginate.Page(items, page=int(page), items_per_page=num_items, item_count=listcount, **kwds) if format == 'json': response.headers['Content-Type'] = 'application/json' data = convert_list_to_json(records, list_type) return data c.list_type = list_type c.page = records c.direction = direction c.order_by = order_by c.q = q c.total_found = total_found c.search_time = search_time return render('/lists/index.html')
def index(self, list_type=1, direction='dsc', order_by='id', page=1, format=None): "Page through lists" total_found = 0 search_time = 0 num_items = session.get('lists_num_items', 10) if direction == 'dsc': sort = desc(order_by) else: sort = order_by qry = request.GET.get('q', None) kwds = {} if qry: kwds['presliced_list'] = True conn = SphinxClient() sphinxopts = extract_sphinx_opts(config['sphinx.url']) conn.SetServer(sphinxopts.get('host', '127.0.0.1')) conn.SetMatchMode(SPH_MATCH_EXTENDED2) conn.SetFilter('list_type', [int(list_type), ]) if not c.user.is_superadmin: conn.SetFilter('user_id', [c.user.id, ]) if page == 1: conn.SetLimits(0, num_items, 500) else: page = int(page) offset = (page - 1) * num_items conn.SetLimits(offset, num_items, 500) try: results = conn.Query(qry, 'lists, lists_rt') except (socket.timeout, struct.error): redirect(request.path_qs) if results and results['matches']: ids = [hit['id'] for hit in results['matches']] total_found = results['total_found'] search_time = results['time'] items = Session.query(List)\ .filter(List.list_type == list_type)\ .filter(List.id.in_(ids))\ .order_by(sort)\ .all() listcount = total_found else: items = [] itemcount = 0 listcount = 0 else: items = Session.query(List)\ .filter(List.list_type == list_type)\ .order_by(sort) itemcount = Session.query(List.id)\ .filter(List.list_type == list_type) if not c.user.is_superadmin: items = items.filter(List.user_id == c.user.id) itemcount = itemcount.filter(List.user_id == c.user.id) listcount = itemcount.count() # pylint: disable-msg=W0142 records = paginate.Page(items, page=int(page), items_per_page=num_items, item_count=listcount, **kwds) if format == 'json': response.headers['Content-Type'] = 'application/json' data = convert_list_to_json(records, list_type) return data c.list_type = list_type c.page = records c.direction = direction c.order_by = order_by c.q = qry c.total_found = total_found c.search_time = search_time return self.render('/lists/index.html')