def paginate_queryset(query_params, queryset):
    """
    Utility function to slice a queryset if pagination parameters
    'page' and 'size' are provided.
    """
    num_models = len(queryset)
    # slicing empty or singleton querysets does not return queryset.
    if num_models <= 1:
        return queryset
    page = query_params.get('page')
    size = query_params.get('size')
    page = int(page) - 1 if page else 0
    size = int(size) if size else num_models
    return queryset[page * size : page * size + size]