# Path: mfr/extensions/tabular/utilities.py
# def data_population(in_data, headers=None):
#     """Convert a list of lists into a list of dicts associating each
#     cell with its column header and row
#     :param data: two dimensional list of data
#     :param fields: column headers
#     :return: JSON representation of rows
#     """
#     headers = headers or in_data[0]
# 
#     return [
#         dict([(header, row[cindex])
#             for cindex, header in enumerate(headers)])
#         for row in in_data
#     ]
# 
# def header_population(headers):
#     """make column headers from a list
#     :param headers: list of column headers
#     :return: a list of dictionaries
#     """
#     return [{'id': field, 'name': field, 'field': field, 'sortable': True} for field in headers]


import ezodf
from collections import OrderedDict
from ..utilities import data_population, header_population
""" This library works for some ods files but not others. Because it doesn't
work consistently, we have disabled this for the moment."""



def ods_ezodf(fp):
    """Read and convert a ods file to JSON format using the ezodf library
    :param fp: File pointer object
    :return: tuple of table headers and data
    """

    workbook = ezodf.opendoc(fp.name)
    sheets = OrderedDict()

    for sheet in workbook.sheets:
        list_data = [[cell.value for cell in row] for row in sheet.rows()]

        header = header_population(list_data[0])

# Path: mfr/extensions/tabular/utilities.py
# def data_population(in_data, headers=None):
#     """Convert a list of lists into a list of dicts associating each
#     cell with its column header and row
#     :param data: two dimensional list of data
#     :param fields: column headers
#     :return: JSON representation of rows
#     """
#     headers = headers or in_data[0]
# 
#     return [
#         dict([(header, row[cindex])
#             for cindex, header in enumerate(headers)])
#         for row in in_data
#     ]
# 
# def header_population(headers):
#     """make column headers from a list
#     :param headers: list of column headers
#     :return: a list of dictionaries
#     """
#     return [{'id': field, 'name': field, 'field': field, 'sortable': True} for field in headers]


# Path: mfr/extensions/tabular/libs/ezodf_tools.py
import ezodf
from collections import OrderedDict
from ..utilities import data_population, header_population

""" This library works for some ods files but not others. Because it doesn't
work consistently, we have disabled this for the moment."""



def ods_ezodf(fp):
    """Read and convert a ods file to JSON format using the ezodf library
    :param fp: File pointer object
    :return: tuple of table headers and data
    """

    workbook = ezodf.opendoc(fp.name)
    sheets = OrderedDict()

    for sheet in workbook.sheets:
        list_data = [[cell.value for cell in row] for row in sheet.rows()]

        header = header_population(list_data[0])

        data = data_population(list_data)