Tools to import data from a CSV file.
Bases: exceptions.StandardError
Exception raised when an import of a CSV file fails.
Bases: object
Preview of a CSV file.
Parameters: |
|
---|
headers of the CSV file
headers translated according to known_headers, an header that can not be translated is replaced by None
first non-headers rows of the file (at most two rows)
Bases: object
Abstract class to import data from a CSV file.
Parameters: |
|
---|
For “end users”, this class has two useful methods:
- get_preview() to generate a Preview of the file
- import_csv() to import the csv file
An implementation must overwrite the methods get_headers_set() and parse_row() and redefine the attribute REQUIRED_HEADERS.
Headers that must be present in the csv file
Returns a set of all possible headers.
Note
This method is abstract and must be implemented.
Returns a message explaining which headers are required.
Imports the csv file. headers is the list of headers as given by the user. Columns whose header is None are ignored. headers must contains all values of REQUIRED_HEADERS.
If one or several errors occur (missing headers, row which can not be parsed), a CSVImportError is raised with all detected errors.
Returns: | A list of PLMObjectController of all created objects. |
---|
Method called once all rows have been successfully parsed.
By default, this method sends all blocked mails.
Appends errors to the list of errors which occured at the line line.
Method called by import_csv() for each row.
Parameters: |
|
---|
This method must be overwritten. Implementation can use the methods get_value(), get_values(), and store_errors() to retrieve values and store detected errors.
Warning
All Controller created should not send emails since an error may occur and thus, all modifications would be cancelled. To block mails, call Controller.block_mails(). You can released all blocked mails by appending the controller to objects. import_csv() will send mails if no errors occurred.
Example:
ctrl = get_obj(type, reference, revision, user)
ctrl.block_mails()
...
if ok:
self.objects.append(ctrl)
Bases: plmapp.csvimport.CSVImporter
An CSVImporter that creates PLMObject from a csv file.
The CSV must contain the following columns:
- type
- reference
- revision
- name
- group (name of the group, not its id)
- lifecycle (name of the lifecycle, not its id)
Moreover, it must have a column for each required field of defined types.
Headers that must be present in the csv file
Bases: plmapp.csvimport.CSVImporter
A CSVImporter that builds a bom from a CSV file.
The CSV must contain the following columns:
- parent-type
- parent-reference
- parent-revision
- child-type
- child-reference
- child-revision
- quantity
- order
Bases: plmapp.csvimport.CSVImporter
A CSVImporter that sponsors users from a CSV file.
The CSV must contain the following columns:
- username
- first_name
- last_name
- groups (multiple groups can be separeted by a “/”)
- language
Dictionary (name -> CSVImporter’s subclass) of known CSVImporter