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):
|
||||
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
|
||||
perspective) of the "current instance" object. Where the data "goes"
|
||||
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()
|
||||
|
||||
if host_object is None:
|
||||
local_data = importer.normalize_local_object(local_object)
|
||||
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)
|
||||
|
||||
if local_object:
|
||||
if importer.allow_update:
|
||||
local_data = importer.normalize_local_object(local_object)
|
||||
|
|
Loading…
Reference in a new issue