def channel_details(chanid): if chanid == "_all": query = Video.select() else: chan = Channel.get(id=chanid) query = Video.select().filter(channel=chan) query = query.order_by(Video.publishdate.desc()) search = request.args.get('search', "") if len(search) > 0: query = query.where(Video.title.contains(search)) # Query based on status status = request.args.get('status', "") if len(status) > 0: status = status.strip().split(",") x = Video.status == status[0] for st in status[1:]: x = x | (Video.status == st) query = query.where(x) # 25 videos per page, with no less than 5 per page paginator = Paginator(query, per_page=25, orphans=5) # Get page parameter page_num = request.args.get('page', '1') if int(page_num) < 1: page_num = 1 try: page = paginator.page(page_num) except PageNotAnInteger: page = paginator.page(1) except EmptyPage: page = paginator.page(paginator.num_pages) out_videos = [] for v in page: out_videos.append({ 'id': v.id, 'title': v.title, 'imgs': v.img, 'url': v.url, 'description': v.description, 'publishdate': str(v.publishdate), 'status': v.status, # FIXME: Data duplication, only used for "all" channel view 'channel': _channel_info_dict(v.channel), }) if chanid == '_all': channel = None else: channel = _channel_info_dict(chan) page_info = { 'total': paginator.num_pages, 'current': page.number, 'has_next': page.has_next(), 'has_previous': page.has_previous(), } return json.dumps({ 'channel': channel, 'videos': out_videos, 'pagination': page_info })
def channel_details(chanid): if chanid == "_all": query = Video.select() else: chan = Channel.get(id=chanid) query = Video.select().filter(channel = chan) query = query.order_by(Video.publishdate.desc()) search = request.args.get('search', "") if len(search) > 0: query = query.where(Video.title.contains(search)) # Query based on status status = request.args.get('status', "") if len(status) > 0: status = status.strip().split(",") x = Video.status == status[0] for st in status[1:]: x = x | (Video.status == st) query = query.where(x) # 25 videos per page, with no less than 5 per page paginator = Paginator(query, per_page=25, orphans=5) # Get page parameter page_num = request.args.get('page', '1') if int(page_num) < 1: page_num = 1 try: page = paginator.page(page_num) except PageNotAnInteger: page = paginator.page(1) except EmptyPage: page = paginator.page(paginator.num_pages) out_videos = [] for v in page: out_videos.append({ 'id': v.id, 'title': v.title, 'imgs': v.img, 'url': v.url, 'description': v.description, 'publishdate': str(v.publishdate), 'status': v.status, # FIXME: Data duplication, only used for "all" channel view 'channel': _channel_info_dict(v.channel), }) if chanid == '_all': channel = None else: channel = _channel_info_dict(chan) page_info = { 'total': paginator.num_pages, 'current': page.number, 'has_next': page.has_next(), 'has_previous': page.has_previous(), } return json.dumps( {'channel': channel, 'videos': out_videos, 'pagination': page_info})