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 15:32

Télécharger (3,04 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        | 15 +++++++++++++++
 2 files changed, 16 insertions(+)
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'):
......
234 245
                pass
235 246
            else:
236 247
                if existing_object:
248
                    self.increment_count()
237 249
                    continue
238 250
            new_object = element_klass()
239 251
            new_object.slug = slug
240 252
            new_object.name = '[pre-import] %s' % xml_node_text(tree.find('name'))
241 253
            new_object.store(comment=_('Application (%s)') % self.app_name)
254
            self.increment_count()
242 255

  
243 256
    def install(self, elements):
244 257
        for element in elements:
......
253 266
                    raise KeyError()
254 267
            except KeyError:
255 268
                new_object.store(comment=_('Application (%s)') % self.app_name)
269
                self.increment_count()
256 270
                continue
257 271
            # replace
258 272
            new_object.id = existing_object.id
......
270 284
                ):
271 285
                    setattr(new_object, attr, getattr(existing_object, attr))
272 286
            new_object.store(comment=_('Application (%s) update') % self.app_name)
287
            self.increment_count()
273 288

  
274 289

  
275 290
@signature_required
276
-