def _get_videos_for_filter(video_filter, sort_field=None, sort_dir=SortDirection.asc, pagination_conf=None):
    """
    Returns a generator expression that contains the videos found, sorted by
    the given field and direction, with ties broken by edx_video_id to ensure a
    total order.
    """
    videos = Video.objects.filter(**video_filter)
    paginator_context = {}

    if sort_field:
        # Refining by edx_video_id ensures a total order
        videos = videos.order_by(sort_field.value, "edx_video_id")
        if sort_dir == SortDirection.desc:
            videos = videos.reverse()

    if pagination_conf:
        videos_per_page = pagination_conf.get('videos_per_page')
        paginator = Paginator(videos, videos_per_page)
        videos = paginator.page(pagination_conf.get('page_number'))
        paginator_context = {
            'current_page':   videos.number,
            'total_pages': videos.paginator.num_pages,
            'items_on_one_page':videos_per_page
        }

    return (VideoSerializer(video).data for video in videos), paginator_context
Returns a generator expression that contains the videos found, sorted by
    the given field and direction, with ties broken by edx_video_id to ensure a
    total order.