nodes: 0, module; 1, function_definition; 2, function_name:filter_sorted_apps; 3, parameters; 4, block; 5, identifier:admin_apps; 6, identifier:request; 7, expression_statement; 8, expression_statement; 9, for_statement; 10, expression_statement; 11, for_statement; 12, expression_statement; 13, return_statement; 14, comment:"""
      Filter admin_apps to show the ones in ``DASHBOARD_SORTED_APPS`` first,
      and remove them from the subsequent listings.
      """; 15, assignment; 16, identifier:orig_app_spec; 17, attribute; 18, comment:# make a copy that we can write to, to fix deprecations without; 19, comment:# changing settings; 20, block; 21, assignment; 22, identifier:app; 23, identifier:sorted_apps; 24, block; 25, augmented_assignment; 26, identifier:sorted_apps; 27, identifier:sorted_apps; 28, list; 29, identifier:appsettings; 30, identifier:DASHBOARD_SORTED_APPS; 31, expression_statement; 32, comment:# lookup the models from the names; 33, expression_statement; 34, comment:# Only add the panel if at least one model is listed.; 35, if_statement; 36, identifier:used_models; 37, list; 38, expression_statement; 39, identifier:sorted_apps; 40, call; 41, assignment; 42, assignment; 43, subscript; 44, block; 45, augmented_assignment; 46, identifier:_remove_app_models; 47, argument_list; 48, identifier:app_spec; 49, call; 50, subscript; 51, call; 52, identifier:app_spec; 53, string; 54, expression_statement; 55, identifier:used_models; 56, subscript; 57, identifier:admin_apps; 58, identifier:used_models; 59, attribute; 60, argument_list; 61, identifier:app_spec; 62, string; 63, identifier:_build_app_models; 64, argument_list; 65, string_content:models; 66, call; 67, identifier:app; 68, string; 69, identifier:orig_app_spec; 70, identifier:copy; 71, string_content:models; 72, identifier:request; 73, identifier:admin_apps; 74, subscript; 75, keyword_argument; 76, attribute; 77, argument_list; 78, string_content:models; 79, identifier:app_spec; 80, string; 81, identifier:ensure_all_models; 82, True; 83, identifier:sorted_apps; 84, identifier:append; 85, identifier:app_spec; 86, string_content:models
code: def filter_sorted_apps(admin_apps, request):
      """
      Filter admin_apps to show the ones in ``DASHBOARD_SORTED_APPS`` first,
      and remove them from the subsequent listings.
      """
  
      sorted_apps = []
  
      for orig_app_spec in appsettings.DASHBOARD_SORTED_APPS:
          # make a copy that we can write to, to fix deprecations without
          # changing settings
          app_spec = orig_app_spec.copy()
          # lookup the models from the names
          app_spec['models'] = _build_app_models(
              request, admin_apps, app_spec['models'], ensure_all_models=True
          )
          # Only add the panel if at least one model is listed.
          if app_spec['models']:
              sorted_apps.append(app_spec)
  
      used_models = []
      for app in sorted_apps:
          used_models += app['models']
  
      sorted_apps += _remove_app_models(admin_apps, used_models)
  
      return sorted_apps