Projet

Général

Profil

0001-api-add-progress-details-to-bundle-import-afterjob-6.patch

Frédéric Péters, 08 août 2022 14:26

Télécharger (3,31 ko)

Voir les différences:

Subject: [PATCH] api: add progress details to bundle import afterjob (#68019)

 tests/api/test_export_import.py |  1 +
 wcs/api_export_import.py        | 19 +++++++++++++++++--
 wcs/qommon/afterjobs.py         |  4 ++--
 3 files changed, 20 insertions(+), 4 deletions(-)
tests/api/test_export_import.py
276 276
    afterjob_url = resp.json['url']
277 277
    resp = get_app(pub).put(sign_uri(afterjob_url))
278 278
    assert resp.json['data']['status'] == 'completed'
279
    assert resp.json['data']['completion_status'] == '11/11 (100%)'
279 280

  
280 281
    assert Category.count() == 1
281 282
    assert FormDef.count() == 1
wcs/api_export_import.py
196 196
            manifest = json.loads(self.tar.extractfile('manifest.json').read().decode())
197 197
            self.app_name = manifest.get('application')
198 198

  
199
            # count number of actions
200
            self.total_count = 0
201
            self.total_count += len(
202
                [
203
                    x
204
                    for x in manifest.get('elements')
205
                    if x.get('type') in ('forms', 'cards', 'blocks', 'workflows')
206
                ]
207
            )
208
            self.total_count += len(manifest.get('elements'))
209

  
199 210
            # first pass on formdef/carddef/blockdef/workflows to create them empty
200 211
            # (name and slug); so they can be found for sure in import pass
201 212
            for type in ('forms', 'cards', 'blocks', 'workflows'):
202
                self.pre_install([x for x in manifest.get('elements') if x.get('type') == type])
213
                elements = [x for x in manifest.get('elements') if x.get('type') == type]
214
                self.pre_install(elements)
215
                self.increment_count(amount=len(elements))
203 216

  
204 217
            # real installation pass
205 218
            for type in (
......
217 230
                'blocks',
218 231
                'workflows',
219 232
            ):
220
                self.install([x for x in manifest.get('elements') if x.get('type') == type])
233
                elements = [x for x in manifest.get('elements') if x.get('type') == type]
234
                self.install(elements)
235
                self.increment_count(amount=len(elements))
221 236

  
222 237
    def pre_install(self, elements):
223 238
        for element in elements:
wcs/qommon/afterjobs.py
75 75
    def done_action_attributes(self):
76 76
        return self.done_button_attributes_arg
77 77

  
78
    def increment_count(self):
79
        self.current_count = (self.current_count or 0) + 1
78
    def increment_count(self, amount=1):
79
        self.current_count = (self.current_count or 0) + amount
80 80
        self.store()
81 81

  
82 82
    def get_completion_status(self):
83
-