Projet

Général

Profil

0001-misc-include-item-fields-with-custom-view-as-datasou.patch

Frédéric Péters, 21 janvier 2022 12:47

Télécharger (3,32 ko)

Voir les différences:

Subject: [PATCH] misc: include item fields with custom view as datasource in
 links (#60917)

 tests/backoffice_pages/test_carddata.py | 16 ++++++++++++++++
 wcs/formdata.py                         | 10 +++++++---
 2 files changed, 23 insertions(+), 3 deletions(-)
tests/backoffice_pages/test_carddata.py
288 288
    resp = resp.click('card plop')
289 289
    assert '<div class="value">plop</div>' in resp
290 290

  
291
    carddata = carddef2.data_class().get(1)
292
    linked_cards = list(carddata.iter_target_datas())
293
    assert len(linked_cards) == 1
294
    assert linked_cards[0][0].formdef.url_name == carddef.url_name
295

  
291 296
    # check with a custom view as data source
292 297
    custom_view = pub.custom_view_class()
293 298
    custom_view.title = 'shared custom test view'
......
308 313
    resp = app.get('/backoffice/data/bar/1/')
309 314
    resp = resp.click('card plop')
310 315

  
316
    carddata = carddef2.data_class().get(1)
317
    linked_cards = list(carddata.iter_target_datas())
318
    assert len(linked_cards) == 1
319
    assert linked_cards[0][0].formdef.url_name == carddef.url_name
320

  
311 321
    # link to a unknown carddef
312 322
    carddef2.fields = [
313 323
        fields.ItemField(
......
315 325
        ),
316 326
    ]
317 327
    carddef2.store()
328

  
329
    carddata = carddef2.data_class().get(1)
330
    linked_cards = list(carddata.iter_target_datas())
331
    assert len(linked_cards) == 1
332
    assert linked_cards[0][0] == 'Linked object def by id unknown'
333

  
318 334
    app = login(get_app(pub))
319 335
    resp = app.get('/backoffice/data/')
320 336
    resp = resp.click('bar')
wcs/formdata.py
1424 1424
            data_source = getattr(field, 'data_source', None)
1425 1425
            if not data_source:
1426 1426
                continue
1427
            data_source_type = data_source['type']
1428
            if data_source_type.count(':') == 2:
1429
                # custom view, only keep object type and object slug
1430
                data_source_type = ':'.join(data_source_type.split(':')[:2])
1427 1431
            origin = _('Data Source')
1428 1432
            if field.varname:
1429 1433
                origin = '%s - varname "%s"' % (origin, field.varname)
1430 1434
            if object_type:
1431 1435
                # looking for a data_source of a specific type (workflow action)
1432
                if data_source['type'] == object_type:
1433
                    data_ids.append((data_source['type'], linked_id, origin))
1436
                if data_source_type == object_type:
1437
                    data_ids.append((data_source_type, linked_id, origin))
1434 1438
            else:
1435 1439
                # looking for any data_source (inspect page)
1436
                data_ids.append((data_source['type'], linked_id, origin))
1440
                data_ids.append((data_source_type, linked_id, origin))
1437 1441

  
1438 1442
        # search in evolution
1439 1443
        for part in self.iter_evolution_parts():
1440
-