Package s3 :: Module s3import :: Class S3ImportJob
[frames] | no frames]

Class S3ImportJob

source code

Class to import an element tree into the database

Instance Methods
 
__init__(self, table, tree=None, files=None, job_id=None, strategy=None, update_policy=None, conflict_policy=None, last_sync=None, onconflict=None)
Constructor
source code
 
uidmap(self)
Map uuid/tuid => element, for faster reference lookups
source code
 
add_item(self, element=None, original=None, components=None, parent=None, joinby=None)
Parse and validate an XML element and add it as new item to the job.
source code
 
lookahead(self, element, table=None, fields=None, tree=None, directory=None, lookup=None)
Find referenced elements in the tree
source code
 
load_item(self, row)
Load an item from the item table (counterpart to add_item when restoring a job from the database)
source code
 
resolve(self, item_id, import_list)
Resolve the reference list of an item
source code
 
commit(self, ignore_errors=False, log_items=None)
Commit the import job to the DB
source code
 
store(self)
Store this job and all its items in the job table
source code
 
get_tree(self)
Reconstruct the element tree of this job
source code
 
delete(self)
Delete this job and all its items from the job table
source code
 
restore_references(self)
Restore the job's reference structure after loading items from the item table
source code
Class Methods
 
define_job_table(cls) source code
 
define_item_table(cls) source code
Class Variables
  JOB_TABLE_NAME = "s3_import_job"
  ITEM_TABLE_NAME = "s3_import_item"
Method Details

__init__(self, table, tree=None, files=None, job_id=None, strategy=None, update_policy=None, conflict_policy=None, last_sync=None, onconflict=None)
(Constructor)

source code 

Constructor

Parameters:
  • tree - the element tree to import
  • files - files attached to the import (for upload fields)
  • job_id - restore job from database (record ID or job_id)
  • strategy - the import strategy
  • update_policy - the update policy
  • conflict_policy - the conflict resolution policy
  • last_sync - the last synchronization time stamp (datetime)
  • onconflict - custom conflict resolver function

uidmap(self)

source code 

Map uuid/tuid => element, for faster reference lookups

Decorators:
  • @property

add_item(self, element=None, original=None, components=None, parent=None, joinby=None)

source code 

Parse and validate an XML element and add it as new item to the job.

Parameters:
  • element - the element
  • original - the original DB record (if already available, will otherwise be looked-up by this function)
  • components - a dictionary of components (as in S3Resource) to include in the job (defaults to all defined components)
  • parent - the parent item (if this is a component)
  • joinby - the component join key(s) (if this is a component)
Returns:
a unique identifier for the new item, or None if there was an error. self.error contains the last error, and self.error_tree an element tree with all failing elements including error attributes.

lookahead(self, element, table=None, fields=None, tree=None, directory=None, lookup=None)

source code 

Find referenced elements in the tree

Parameters:
  • element - the element
  • table - the DB table
  • fields - the FK fields in the table
  • tree - the import tree
  • directory - a dictionary to lookup elements in the tree (will be filled in by this function)

load_item(self, row)

source code 

Load an item from the item table (counterpart to add_item when restoring a job from the database)

resolve(self, item_id, import_list)

source code 

Resolve the reference list of an item

Parameters:
  • item_id - the import item UID
  • import_list - the ordered list of items (UIDs) to import

commit(self, ignore_errors=False, log_items=None)

source code 

Commit the import job to the DB

Parameters:
  • ignore_errors - skip any items with errors (does still report the errors)
  • log_items - callback function to log import items before committing them

define_job_table(cls)
Class Method

source code 

define_item_table(cls)
Class Method

source code 

store(self)

source code 

Store this job and all its items in the job table

get_tree(self)

source code 

Reconstruct the element tree of this job

delete(self)

source code 

Delete this job and all its items from the job table

restore_references(self)

source code 

Restore the job's reference structure after loading items from the item table


Class Variable Details

JOB_TABLE_NAME

Value:
"s3_import_job"

ITEM_TABLE_NAME

Value:
"s3_import_item"