Ejemplo n.º 1
0
    def get(self, session=None):
        """ List existing shows """
        args = series_list_parser.parse_args()

        # Filter params
        configured = args['in_config']
        premieres = args['premieres']
        status = args['status']
        days = args['days']

        # Pagination and sorting params
        page = args['page']
        per_page = args['per_page']
        sort_by = args['sort_by']
        sort_order = args['order']

        # Handle max size limit
        if per_page > 100:
            per_page = 100

        descending = sort_order == 'desc'

        # Data params
        lookup = args.get('lookup')
        begin = args.get('begin')
        latest = args.get('latest')

        start = per_page * (page - 1)
        stop = start + per_page

        kwargs = {
            'configured': configured,
            'premieres': premieres,
            'status': status,
            'days': days,
            'start': start,
            'stop': stop,
            'sort_by': sort_by,
            'descending': descending,
            'session': session
        }

        total_items = series.get_series_summary(count=True, **kwargs)

        if not total_items:
            return jsonify([])

        series_list = []
        for s in series.get_series_summary(**kwargs):
            series_object = series_details(s, begin, latest)
            series_list.append(series_object)

        # Total number of pages
        total_pages = int(ceil(total_items / float(per_page)))

        if total_pages < page and total_pages != 0:
            raise NotFoundError('page %s does not exist' % page)

        # Actual results in page
        actual_size = min(per_page, len(series_list))

        # Do relevant lookups
        if lookup:
            api_client = APIClient()
            for endpoint in lookup:
                base_url = '/%s/series/' % endpoint
                for show in series_list:
                    pos = series_list.index(show)
                    series_list[pos].setdefault('lookup', {})
                    url = base_url + show['name'] + '/'
                    result = api_client.get_endpoint(url)
                    series_list[pos]['lookup'].update({endpoint: result})

        # Get pagination headers
        pagination = pagination_headers(total_pages, total_items, actual_size, request)

        # Created response
        rsp = jsonify(series_list)

        # Add link header to response
        rsp.headers.extend(pagination)
        return rsp
Ejemplo n.º 2
0
    def get(self, session=None):
        """ List existing shows """
        args = series_list_parser.parse_args()

        # Filter params
        configured = args['in_config']
        premieres = args['premieres']
        status = args['status']
        days = args['days']

        # Pagination and sorting params
        page = args['page']
        per_page = args['per_page']
        sort_by = args['sort_by']
        sort_order = args['order']

        # Handle max size limit
        if per_page > 100:
            per_page = 100

        descending = bool(sort_order == 'desc')

        # Data params
        lookup = args.get('lookup')
        begin = args.get('begin')
        latest = args.get('latest')

        start = per_page * (page - 1)
        stop = start + per_page

        kwargs = {
            'configured': configured,
            'premieres': premieres,
            'status': status,
            'days': days,
            'start': start,
            'stop': stop,
            'sort_by': sort_by,
            'descending': descending,
            'session': session
        }

        total_items = series.get_series_summary(count=True, **kwargs)

        if not total_items:
            return jsonify([])

        series_list = []
        for s in series.get_series_summary(**kwargs):
            series_object = series_details(s, begin, latest)
            series_list.append(series_object)

        # Total number of pages
        total_pages = int(ceil(total_items / float(per_page)))

        if total_pages < page and total_pages != 0:
            raise NotFoundError('page %s does not exist' % page)

        # Actual results in page
        actual_size = min(per_page, len(series_list))

        # Do relevant lookups
        if lookup:
            api_client = APIClient()
            for endpoint in lookup:
                base_url = '/%s/series/' % endpoint
                for show in series_list:
                    pos = series_list.index(show)
                    series_list[pos].setdefault('lookup', {})
                    url = base_url + show['name'] + '/'
                    result = api_client.get_endpoint(url)
                    series_list[pos]['lookup'].update({endpoint: result})

        # Get pagination headers
        pagination = pagination_headers(total_pages, total_items, actual_size,
                                        request)

        # Created response
        rsp = jsonify(series_list)

        # Add link header to response
        rsp.headers.extend(pagination)
        return rsp
Ejemplo n.º 3
0
    def get(self, session=None):
        """ List existing shows """
        args = series_list_parser.parse_args()

        # Filter params
        configured = args["in_config"]
        premieres = args["premieres"]
        status = args["status"]
        days = args["days"]

        # Pagination and sorting params
        page = args["page"]
        per_page = args["per_page"]
        sort_by = args["sort_by"]
        sort_order = args["order"]

        # Handle max size limit
        if per_page > 100:
            per_page = 100

        descending = bool(sort_order == "desc")

        # Data params
        lookup = args.get("lookup")
        begin = args.get("begin")
        latest = args.get("latest")

        start = per_page * (page - 1)
        stop = start + per_page

        kwargs = {
            "configured": configured,
            "premieres": premieres,
            "status": status,
            "days": days,
            "start": start,
            "stop": stop,
            "sort_by": sort_by,
            "descending": descending,
            "session": session,
        }

        total_items = series.get_series_summary(count=True, **kwargs)

        if not total_items:
            return jsonify([])

        series_list = []
        for s in series.get_series_summary(**kwargs):
            series_object = series_details(s, begin, latest)
            series_list.append(series_object)

        # Total number of pages
        total_pages = int(ceil(total_items / float(per_page)))

        if total_pages < page and total_pages != 0:
            raise NotFoundError("page %s does not exist" % page)

        # Actual results in page
        actual_size = min(per_page, len(series_list))

        # Do relevant lookups
        if lookup:
            api_client = APIClient()
            for endpoint in lookup:
                base_url = "/%s/series/" % endpoint
                for show in series_list:
                    pos = series_list.index(show)
                    series_list[pos].setdefault("lookup", {})
                    url = base_url + show["name"] + "/"
                    result = api_client.get_endpoint(url)
                    series_list[pos]["lookup"].update({endpoint: result})

        # Get pagination headers
        pagination = pagination_headers(total_pages, total_items, actual_size, request)

        # Created response
        rsp = jsonify(series_list)

        # Add link header to response
        rsp.headers.extend(pagination)
        return rsp