Improve master view oneoff_import()
method
be more flexible about what caller must provide
This commit is contained in:
parent
f3dddf0e40
commit
7bae01f03c
|
@ -1841,21 +1841,32 @@ class MasterView(View):
|
||||||
def fetch_grid_totals(self):
|
def fetch_grid_totals(self):
|
||||||
return {'totals_display': "TODO: totals go here"}
|
return {'totals_display': "TODO: totals go here"}
|
||||||
|
|
||||||
def oneoff_import(self, importer, host_object=None):
|
def oneoff_import(self, importer, host_object=None, local_object=None):
|
||||||
"""
|
"""
|
||||||
Basic helper method, to do a one-off import (or export, depending on
|
Basic helper method, to do a one-off import (or export, depending on
|
||||||
perspective) of the "current instance" object. Where the data "goes"
|
perspective) of the "current instance" object. Where the data "goes"
|
||||||
depends on the importer you provide.
|
depends on the importer you provide.
|
||||||
"""
|
"""
|
||||||
if not host_object:
|
if host_object is None and local_object is None:
|
||||||
host_object = self.get_instance()
|
host_object = self.get_instance()
|
||||||
|
|
||||||
host_data = importer.normalize_host_object(host_object)
|
if host_object is None:
|
||||||
if not host_data:
|
local_data = importer.normalize_local_object(local_object)
|
||||||
return
|
key = importer.get_key(local_data)
|
||||||
|
host_object = importer.get_single_host_object(key)
|
||||||
|
if not host_object:
|
||||||
|
return
|
||||||
|
host_data = importer.normalize_host_object(host_object)
|
||||||
|
if not host_data:
|
||||||
|
return
|
||||||
|
|
||||||
|
else:
|
||||||
|
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)
|
||||||
|
|
||||||
key = importer.get_key(host_data)
|
|
||||||
local_object = importer.get_local_object(key)
|
|
||||||
if local_object:
|
if local_object:
|
||||||
if importer.allow_update:
|
if importer.allow_update:
|
||||||
local_data = importer.normalize_local_object(local_object)
|
local_data = importer.normalize_local_object(local_object)
|
||||||
|
|
Loading…
Reference in a new issue