import itertools
from operator import attrgetter

from dataactcore.models.lookups import FILE_TYPE


def get_report_path(job, report_type):
    """
    Return the filename for the error report.
    Does not include the folder to avoid conflicting with the S3 getSignedUrl method.
    """
    path = 'submission_{}_{}_{}_report.csv'.format(job.submission_id, job.file_type.name, report_type)
    return path


def get_cross_report_name(submissionId, source_file, target_file):
    """Return filename for a cross file error report."""
    return "submission_{}_cross_{}_{}.csv".format(submissionId, source_file, target_file)


def get_cross_warning_report_name(submissionId, source_file, target_file):
    """Return filename for a cross file warning report."""
    return "submission_{}_cross_warning_{}_{}.csv".format(submissionId, source_file, target_file)

def get_cross_file_pairs():
    """
    Create a list that represents each possible combination of files used
    in cross file validations.

    Returns:
        a list of tuples, where the first tuple represents file #1 in a pair
        and the second tuple represent file #2 in a pair
    """
    # make sure the list is sorted by files' order attributes to ensure that files
    # in pairs are always listed in the same order
    crossfile_sorted = sorted([f for f in FILE_TYPE if f.crossfile], key=attrgetter('order'))
    # create unique combinations of all files eligible for cross-file validation
    crossfile_combos = itertools.combinations(crossfile_sorted, 2)
    return list(map(list, crossfile_combos))

@@ -289,122 +289,124 @@
     
-path = 'submission_%7B%7D_%7B%7D_%7B%7D_report.csv'.format(job.submission_id, job.file_type.name, report_type)%0A    return path
+return report_file_name(job.submission_id, report_type == 'warning',%0A                            job.file_type.name)
 %0A%0A%0Ad
@@ -432,33 +432,34 @@
 _name(submission
-I
+_i
 d, source_file, 
@@ -544,46 +544,24 @@
 urn 
-%22submission_%7B%7D_cross_%7B%7D_%7B%7D.csv%22.format
+report_file_name
 (sub
@@ -559,35 +559,43 @@
 _name(submission
-I
+_i
 d,
+ False,
  source_file, ta
@@ -643,33 +643,34 @@
 _name(submission
-I
+_i
 d, source_file, 
@@ -757,37 +757,354 @@
 urn 
-%22submission_%7B%7D_cross_warning_
+report_file_name(submission_id, True, source_file, target_file)%0A%0A%0Adef report_file_name(submission_id, warning, file_type, cross_type=None):%0A    %22%22%22Format the csv file name for the requested file.%0A    @todo: unify these file names%22%22%22%0A    if cross_type:%0A        report_type_str = 'warning_' if warning else ''%0A        return %22submission_%7B%7D_cross_%7B%7D
 %7B%7D_%7B
@@ -1117,16 +1117,29 @@
 .format(
+%0A            
 submissi
@@ -1144,37 +1144,234 @@
 sion
-Id, source_file, target_file)
+_id, report_type_str, file_type, cross_type)%0A    else:%0A        report_type_str = 'warning' if warning else 'error'%0A        return %22submission_%7B%7D_%7B%7D_%7B%7D_report.csv%22.format(%0A            submission_id, file_type, report_type_str)%0A
 %0A%0Ade

Add unified method for generating report filenames