nodes: 0, module; 1, function_definition; 2, function_name:_get_videos_for_filter; 3, parameters; 4, block; 5, identifier:video_filter; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, if_statement; 13, if_statement; 14, return_statement; 15, identifier:sort_field; 16, None; 17, identifier:sort_dir; 18, attribute; 19, identifier:pagination_conf; 20, None; 21, comment:"""
      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.
      """; 22, assignment; 23, assignment; 24, identifier:sort_field; 25, comment:# Refining by edx_video_id ensures a total order; 26, block; 27, identifier:pagination_conf; 28, block; 29, expression_list; 30, identifier:SortDirection; 31, identifier:asc; 32, identifier:videos; 33, call; 34, identifier:paginator_context; 35, dictionary; 36, expression_statement; 37, if_statement; 38, expression_statement; 39, expression_statement; 40, expression_statement; 41, expression_statement; 42, generator_expression; 43, identifier:paginator_context; 44, attribute; 45, argument_list; 46, assignment; 47, comparison_operator:sort_dir == SortDirection.desc; 48, block; 49, assignment; 50, assignment; 51, assignment; 52, assignment; 53, attribute; 54, for_in_clause; 55, attribute; 56, identifier:filter; 57, dictionary_splat; 58, identifier:videos; 59, call; 60, identifier:sort_dir; 61, attribute; 62, expression_statement; 63, identifier:videos_per_page; 64, call; 65, identifier:paginator; 66, call; 67, identifier:videos; 68, call; 69, identifier:paginator_context; 70, dictionary; 71, call; 72, identifier:data; 73, identifier:video; 74, identifier:videos; 75, identifier:Video; 76, identifier:objects; 77, identifier:video_filter; 78, attribute; 79, argument_list; 80, identifier:SortDirection; 81, identifier:desc; 82, assignment; 83, attribute; 84, argument_list; 85, identifier:Paginator; 86, argument_list; 87, attribute; 88, argument_list; 89, pair; 90, pair; 91, pair; 92, identifier:VideoSerializer; 93, argument_list; 94, identifier:videos; 95, identifier:order_by; 96, attribute; 97, string:"edx_video_id"; 98, identifier:videos; 99, call; 100, identifier:pagination_conf; 101, identifier:get; 102, string; 103, identifier:videos; 104, identifier:videos_per_page; 105, identifier:paginator; 106, identifier:page; 107, call; 108, string; 109, attribute; 110, string; 111, attribute; 112, string; 113, identifier:videos_per_page; 114, identifier:video; 115, identifier:sort_field; 116, identifier:value; 117, attribute; 118, argument_list; 119, string_content:videos_per_page; 120, attribute; 121, argument_list; 122, string_content:current_page; 123, identifier:videos; 124, identifier:number; 125, string_content:total_pages; 126, attribute; 127, identifier:num_pages; 128, string_content:items_on_one_page; 129, identifier:videos; 130, identifier:reverse; 131, identifier:pagination_conf; 132, identifier:get; 133, string; 134, identifier:videos; 135, identifier:paginator; 136, string_content:page_number
code: 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