zsk-poznan / zastepstwa

Web app for displaying substitute teachers
GNU General Public License v3.0
8 stars 3 forks source link

Importing files #71

Open pniedzwiedzinski opened 4 years ago

pniedzwiedzinski commented 4 years ago

For that, we can use this: https://github.com/django-import-export/django-import-export

I looked through the code and there's a Format API for creating custom parsers. The drawback of this is that there is nothing about that class in the docs. So we could contribute to this project by adding the docs and examples.

I've made some research about this but it's not yet tested:

Format

Example Format (copied from https://github.com/django-import-export/django-import-export/blob/master/import_export/formats/base_formats.py)

class XLS(TablibFormat):
    TABLIB_MODULE = 'tablib.formats._xls'
    CONTENT_TYPE = 'application/vnd.ms-excel'

    def create_dataset(self, in_stream):
        """
        Create dataset from first sheet.
        """
        import xlrd
        xls_book = xlrd.open_workbook(file_contents=in_stream)
        dataset = tablib.Dataset()
        sheet = xls_book.sheets()[0]

        dataset.headers = sheet.row_values(0)
        for i in range(1, sheet.nrows):
            dataset.append(sheet.row_values(i))
        return dataset