code: def sorted_analyses(self, analyses):
          
          analyses = sorted(analyses, key=lambda an: an.getRequestID())
  
          def sorted_by_sortkey(objs):
              return sorted(objs, key=lambda an: an.getPrioritySortkey())
  
          # Now, we need the analyses within a request ID to be sorted by
          # sortkey (sortable_title index), so it will appear in the same
          # order as they appear in Analyses list from AR view
          current_sample_id = None
          current_analyses = []
          sorted_analyses = []
          for analysis in analyses:
              sample_id = analysis.getRequestID()
              if sample_id and current_sample_id != sample_id:
                  # Sort the brains we've collected until now, that
                  # belong to the same Analysis Request
                  current_analyses = sorted_by_sortkey(current_analyses)
                  sorted_analyses.extend(current_analyses)
                  current_sample_id = sample_id
                  current_analyses = []
  
              # Now we are inside the same AR
              current_analyses.append(analysis)
              continue
  
          # Sort the last set of brains we've collected
          current_analyses = sorted_by_sortkey(current_analyses)
          sorted_analyses.extend(current_analyses)
          return sorted_analyses
docs: Sort the analyses by AR ID ascending and subsorted by priority
          sortkey within the AR they belong to