import_utils

Utility classes to import files into Camelot

class camelot.view.import_utils.ColumnMapping(column, rows, default_field=None)[source]

Object that maps a column in the rows to import to a field of the data model.

Parameters:
  • column – a number that indicates which column is mapped
  • rows – the list of RowData objects to import, the list should not be empty
  • default_field – the default field that is mapped, or None
class camelot.view.import_utils.ColumnMappingAdmin(admin, entity=<class 'camelot.view.import_utils.ColumnMapping'>, field_choices=[])[source]

Admin class that allows the user to manipulate the column mappings

Parameters:
  • admin – the admin object of the model in which to import
  • entity – the class that is used to define the column mapping
  • field_choices – the list of fields out of which the user can select
class camelot.view.import_utils.ColumnSelectionAdmin(admin, entity=<class 'camelot.view.import_utils.ColumnMapping'>, field_choices=[])[source]

Admin to edit a ColumnMapping class without data preview

class camelot.view.import_utils.MatchNames[source]

Use the data in the current row to determine field names

class camelot.view.import_utils.RowData(row_number, row_data)[source]

Class representing the data in a single row of the imported file as an object with attributes column_0, column_1, ..., each representing the data in a single column of that row.

since the imported file might contain less columns than expected in some rows, the RowData object returns None for not existing attributes

Parameters:row_data – a list containing the data [column_0_data, column_1_data, ...] for a single row
class camelot.view.import_utils.RowDataAdmin(admin, column_mappings)[source]

Decorator that transforms the Admin of the class to be imported to an Admin of the RowData objects to be used when previewing and validating the data to be imported.

based on the field attributes of the original mode, it will turn the background color pink if the data is invalid for being imported.

Parameters:
  • admin – the camelot.admin.object_admin.ObjectAdmin admin object of the objects that will be imported
  • column_mappings – list of ColumnMapping object that maps the columns in the row data to fields of the objects.
flush(obj)[source]

When flush is called, don’t do anything, since we’ll only save the object when importing them for real

get_all_fields_and_attributes()[source]

reimplementation needed to support replace field contents during import

get_validator(model)[source]

Creates a validator that validates the data to be imported, the validator will check if the background of the cell is pink, and if it is it will mark that object as invalid.

class camelot.view.import_utils.UTF8Recoder(f, encoding)[source]

Iterator that reads an encoded stream and reencodes the input to UTF-8.

class camelot.view.import_utils.UnicodeReader(f, dialect=<class csv.excel at 0x1144cf050>, encoding='utf-8', **kwds)[source]

A CSV reader which will iterate over lines in the CSV file “f”, which is encoded in the given encoding.

class camelot.view.import_utils.XlsReader(filename)[source]

Read an XLS/XLSX file and iterator over its lines.

The iterator returns each line of the excel as a list of strings.

The to_string field attribute is supposed to be able to interprete those strings and create a valid datatype.

Parameters:filename – the name of the xls or xlsx file
get_format_string(xf_index)[source]
Returns:the string that specifies the format of a cell
camelot.view.import_utils.column_name(column)[source]

Create a column name starting from an index starting at 0 eg : column=0 -> name=’A’