from corehq.apps.reports.datatables import DataTablesColumn, DataTablesHeader
from corehq.apps.reports.generic import GenericTabularReport
from corehq.apps.reports.standard import CustomProjectReport, DatespanMixin


class MultiTabularReport(DatespanMixin, CustomProjectReport, GenericTabularReport):
    report_template_path = 'inddex/multi_report.html'
    exportable = True
    export_only = False

    @property
    def data_providers(self):
        # data providers should supply a title, slug, headers, and rows
        return []

    @property
    def report_context(self):
        context = {
            'name': self.name,
            'export_only': self.export_only
        }
        if not self.needs_filters:
            context['data_providers'] = [{
                'title': data_provider.title,
                'slug': data_provider.slug,
                'headers': DataTablesHeader(
                    *(DataTablesColumn(header) for header in data_provider.headers),
                ),
                'rows': data_provider.rows,
            } for data_provider in self.data_providers]
        return context

    @property
    def export_table(self):
        return [
            [dp.slug, [dp.headers] + dp.rows]
            for dp in self.data_providers
        ]

@@ -1,28 +1,57 @@
+from itertools import chain%0A%0A
 from corehq.apps.reports.dat
@@ -399,16 +399,42 @@
  = True%0A
+    exportable_all = True%0A
     expo
@@ -1256,16 +1256,22 @@
 p.slug, 
+chain(
 %5Bdp.head
@@ -1278,18 +1278,17 @@
 ers%5D
- +
+,
  dp.rows
 %5D%0A  
@@ -1283,16 +1283,17 @@
  dp.rows
+)
 %5D%0A      

Move export to a background process