Class XlsFile

class jmb.core.utils.data_import.XlsFile(filename=None, file_contents=None, auto=False, sheet_index=0, opts=None, model=None)[sorgente]
Parametri
  • filename – the cvs file to open

  • auto_fields – (boolean) se True, i nomi delle colonne saranno desunti dalla prima riga

  • sheet_index – indice del foglio da usare (default: 0)

get_cell_value(cell)[sorgente]

Return the best guess for the correct value

get_rows(sheet_index=0, sheet=None)[sorgente]
Parametri
  • sheet_index – the index of the sheet to read

  • sheet – a possible sheet object as returned by sheet_by_index

get_sheet_as_list(sheet_name=None, all_sheets=True)[sorgente]

get named sheet or all sheets

get_tuples_from_row(Row, row)[sorgente]
Parametri
  • Row – typename

  • row – iterable

xldate2date(cell)[sorgente]

Returna un datetime.date dal valore della cella

xls2csv()[sorgente]

Really poor version of csv file

Class CsvFile

class jmb.core.utils.data_import.CsvFile(filename, auto=False, delimiter=';', opts=None, model=None)[sorgente]
Parametri
  • filename – the cvs file to open

  • auto_fields – (boolean) se True, i nomi delle colonne saranno desunti dalla prima riga

  • delimiter – delimitatore di campi (default ,)

get_tuples_from_row(Row, row)[sorgente]
Parametri
  • Row – typename

  • row – iterable

Class Sheet

class jmb.core.utils.data_import.Sheet(model, opts)[sorgente]

Abstract sheet

clean_field_name(value)[sorgente]

Clean each column heading to make it a suitable field_name. By default strip empty spaces, non ascii chars, parenthesis :param value: the column header

do(row, kw, j)[sorgente]

implement here your import

Parametri
  • row – a namedtuple. Names are the names in the original columns

  • kw

    a dict suitable to feed defaults keyword attribute of get_or_create if fields_map is provided:

    def do(self, row, kw):
        Contact.objects.get_or_create(cod=row.cod, defaults=kw)
    

  • j – integer 1-based counting read rows

get_fk_as_dict(model, value='id', key='name')[sorgente]

Return a dict of all values of a (possible) fk as dict

Parametri
  • model – the django db model

  • value – the field to use as value of the dict (default id) Note: will be lowered

  • key – the field to use as key of the dict (defaykt name)

handle_exception(e, row, kw, j)[sorgente]

Handle exception of the execution of do()

read(limit=0, start=0)[sorgente]

Loop on all rows of a sheet

Parametri
  • start – start reading at line nr. start

  • limit – limit number of rows to read to limit

setup()[sorgente]

Setup env possibly used in self.do