Add oneoff_import()
helper method to MasterView class
This commit is contained in:
parent
b4d1666bdf
commit
d369693f9f
|
@ -1622,6 +1622,30 @@ class MasterView(View):
|
||||||
progress.session['success_url'] = self.get_index_url()
|
progress.session['success_url'] = self.get_index_url()
|
||||||
progress.session.save()
|
progress.session.save()
|
||||||
|
|
||||||
|
def oneoff_import(self, importer, host_object=None):
|
||||||
|
"""
|
||||||
|
Basic helper method, to do a one-off import (or export, depending on
|
||||||
|
perspective) of the "current instance" object. Where the data "goes"
|
||||||
|
depends on the importer you provide.
|
||||||
|
"""
|
||||||
|
if not host_object:
|
||||||
|
host_object = self.get_instance()
|
||||||
|
|
||||||
|
host_data = importer.normalize_host_object(host_object)
|
||||||
|
if not host_data:
|
||||||
|
return
|
||||||
|
|
||||||
|
key = importer.get_key(host_data)
|
||||||
|
local_object = importer.get_local_object(key)
|
||||||
|
if local_object:
|
||||||
|
if importer.allow_update:
|
||||||
|
local_data = importer.normalize_local_object(local_object)
|
||||||
|
if importer.data_diffs(local_data, host_data) and importer.allow_update:
|
||||||
|
local_object = importer.update_object(local_object, host_data, local_data)
|
||||||
|
return local_object
|
||||||
|
elif importer.allow_create:
|
||||||
|
return importer.create_object(key, host_data)
|
||||||
|
|
||||||
def execute(self):
|
def execute(self):
|
||||||
"""
|
"""
|
||||||
Execute an object.
|
Execute an object.
|
||||||
|
|
Loading…
Reference in a new issue