Class XlsFile¶
-
class
jmb.core.utils.data_import.
XlsFile
(filename=None, file_contents=None, auto=False, sheet_index=0, opts=None, model=None)[source]¶ Parameters: - 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)
Class CsvFile¶
Class Sheet¶
-
class
jmb.core.utils.data_import.
Sheet
(model, opts)[source]¶ Abstract sheet
-
clean_field_name
(value)[source]¶ 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)[source]¶ implement here your import
Parameters: - row – a namedtuple. Names are the names in the original columns
- kw –
a dict suitable to feed
defaults
keyword attribute ofget_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
-
field_list
= None¶ a list of field names. Optional. When present it will be used to name each column instead of looking at the column header. Field name here is the row attribute (eg: row.first_name)
-
fields_map
= None¶ a dict mapping field names to column headers, as an example, if field_name has {‘first_name’ : ‘Nome’} it means that
read()
will set:kw['first_name'] = row.Nome
-
get_fk_as_dict
(model, value=u'id', key=u'name')[source]¶ Return a dict of all values of a (possible) fk as dict
Parameters: - 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
)
-
nullable_field_list
= None¶ Fields listed in this list will be set None if empty specifically needed to prevent unique problems
-