api: add progress details to bundle import afterjob (#68019)

This commit is contained in:
Frédéric Péters 2022-08-08 13:38:48 +02:00
parent 187d998b08
commit 4e7296026f
2 changed files with 16 additions and 0 deletions

View File

@ -276,6 +276,7 @@ def test_export_import_bundle_import(pub):
afterjob_url = resp.json['url']
resp = get_app(pub).put(sign_uri(afterjob_url))
assert resp.json['data']['status'] == 'completed'
assert resp.json['data']['completion_status'] == '11/11 (100%)'
assert Category.count() == 1
assert FormDef.count() == 1

View File

@ -196,6 +196,17 @@ class BundleImportJob(AfterJob):
manifest = json.loads(self.tar.extractfile('manifest.json').read().decode())
self.app_name = manifest.get('application')
# count number of actions
self.total_count = 0
self.total_count += len(
[
x
for x in manifest.get('elements')
if x.get('type') in ('forms', 'cards', 'blocks', 'workflows')
]
)
self.total_count += len(manifest.get('elements'))
# first pass on formdef/carddef/blockdef/workflows to create them empty
# (name and slug); so they can be found for sure in import pass
for type in ('forms', 'cards', 'blocks', 'workflows'):
@ -234,11 +245,13 @@ class BundleImportJob(AfterJob):
pass
else:
if existing_object:
self.increment_count()
continue
new_object = element_klass()
new_object.slug = slug
new_object.name = '[pre-import] %s' % xml_node_text(tree.find('name'))
new_object.store(comment=_('Application (%s)') % self.app_name)
self.increment_count()
def install(self, elements):
for element in elements:
@ -253,6 +266,7 @@ class BundleImportJob(AfterJob):
raise KeyError()
except KeyError:
new_object.store(comment=_('Application (%s)') % self.app_name)
self.increment_count()
continue
# replace
new_object.id = existing_object.id
@ -270,6 +284,7 @@ class BundleImportJob(AfterJob):
):
setattr(new_object, attr, getattr(existing_object, attr))
new_object.store(comment=_('Application (%s) update') % self.app_name)
self.increment_count()
@signature_required