diff --git a/tailbone/views/master.py b/tailbone/views/master.py index 58b283ce..74a18f05 100644 --- a/tailbone/views/master.py +++ b/tailbone/views/master.py @@ -1622,6 +1622,30 @@ class MasterView(View): progress.session['success_url'] = self.get_index_url() 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): """ Execute an object.