Projet

Général

Profil

0002-backoffice-computed-data-with-datasource-in-cards-gr.patch

Lauréline Guérin, 26 novembre 2021 14:39

Télécharger (7,65 ko)

Voir les différences:

Subject: [PATCH 2/2] backoffice: computed data with datasource in cards graph
 (#59048)

 tests/admin_pages/test_card.py | 36 ++++++++++++++++++++++++----------
 wcs/carddef.py                 |  1 +
 2 files changed, 27 insertions(+), 10 deletions(-)
tests/admin_pages/test_card.py
659 659
        fields.StringField(id='1', label='string', type='string', varname='block foo 1', data_source=ds1),
660 660
        fields.ItemField(id='2', label='item', type='item', varname='block foo 2', data_source=ds1),
661 661
        fields.ItemsField(id='3', label='items', type='items', varname='block foo 3', data_source=ds1),
662
        fields.ComputedField(
663
            id='4', label='computed', type='computed', varname='block foo 4', data_source=ds1
664
        ),
662 665
        fields.StringField(id='10', label='string', type='string', varname='block fooo 10', data_source=ds2),
663 666
        fields.ItemField(id='20', label='item', type='item', varname='block fooo 20', data_source=ds2),
664 667
        fields.ItemsField(id='30', label='items', type='items', varname='block fooo 30', data_source=ds2),
668
        fields.ComputedField(
669
            id='40', label='computed', type='computed', varname='block fooo 40', data_source=ds2
670
        ),
665 671
    ]
666 672
    block1.store()
667 673
    block2 = BlockDef()
......
670 676
        fields.StringField(id='1', label='string', type='string', varname='block bar 1', data_source=ds2),
671 677
        fields.ItemField(id='2', label='item', type='item', varname='block bar 2', data_source=ds2),
672 678
        fields.ItemsField(id='3', label='items', type='items', varname='block bar 3', data_source=ds2),
679
        fields.ComputedField(
680
            id='4', label='computed', type='computed', varname='block bar 4', data_source=ds2
681
        ),
673 682
    ]
674 683
    block2.store()
675 684
    block3 = BlockDef()
......
678 687
        fields.StringField(id='1', label='string', type='string', varname='block baz 1', data_source=ds3),
679 688
        fields.ItemField(id='2', label='item', type='item', varname='block baz 2', data_source=ds3),
680 689
        fields.ItemsField(id='3', label='items', type='items', varname='block baz 3', data_source=ds3),
690
        fields.ComputedField(
691
            id='4', label='computed', type='computed', varname='block baz 4', data_source=ds3
692
        ),
681 693
    ]
682 694
    block3.store()
683 695

  
......
690 702
        fields.StringField(id='1', label='string', type='string', varname='foo 1', data_source=ds1),
691 703
        fields.ItemField(id='2', label='item', type='item', varname='foo 2', data_source=ds1),
692 704
        fields.ItemsField(id='3', label='items', type='items', varname='foo 3', data_source=ds1),
693
        fields.BlockField(id='4', label='block', type='block:%s' % block1.slug),
705
        fields.ComputedField(id='4', label='computed', type='computed', varname='foo 4', data_source=ds1),
706
        fields.BlockField(id='5', label='block', type='block:%s' % block1.slug),
694 707
        fields.StringField(id='10', label='string', type='string', varname='fooo 10', data_source=ds2),
695 708
        fields.ItemField(id='20', label='item', type='item', varname='fooo 20', data_source=ds2),
696 709
        fields.ItemsField(id='30', label='items', type='items', varname='fooo 30', data_source=ds2),
697
        fields.BlockField(id='40', label='block', type='block:%s' % block2.slug),
710
        fields.ComputedField(id='40', label='computed', type='computed', varname='fooo 40', data_source=ds2),
711
        fields.BlockField(id='50', label='block', type='block:%s' % block2.slug),
698 712
    ]
699 713
    carddef11.store()
700 714
    carddef12 = CardDef()
......
715 729
        fields.StringField(id='1', label='string', type='string', varname='bar 1', data_source=ds2),
716 730
        fields.ItemField(id='2', label='item', type='item', varname='bar 2', data_source=ds2),
717 731
        fields.ItemsField(id='3', label='items', type='items', varname='bar 3', data_source=ds2),
718
        fields.BlockField(id='4', label='block', type='block:%s' % block2.slug),
732
        fields.ComputedField(id='4', label='computed', type='computed', varname='bar 4', data_source=ds2),
733
        fields.BlockField(id='5', label='block', type='block:%s' % block2.slug),
719 734
    ]
720 735
    carddef21.store()
721 736
    carddef22 = CardDef()
......
730 745
        fields.StringField(id='1', label='string', type='string', varname='baz 1', data_source=ds3),
731 746
        fields.ItemField(id='2', label='item', type='item', varname='baz 2', data_source=ds3),
732 747
        fields.ItemsField(id='3', label='items', type='items', varname='baz 3', data_source=ds3),
733
        fields.BlockField(id='4', label='block', type='block:%s' % block3.slug),
748
        fields.ComputedField(id='4', label='computed', type='computed', varname='baz 4', data_source=ds3),
749
        fields.BlockField(id='5', label='block', type='block:%s' % block3.slug),
734 750
    ]
735 751
    carddef31.store()
736 752
    carddef32 = CardDef()
......
755 771
    assert '<title>card_card_3_1</title' in resp
756 772
    assert '<title>card_card_3_2</title' in resp
757 773
    # and relations
758
    assert resp.text.count('<title>card_card_1_1&#45;&gt;card_card_1_2</title>') == 6
759
    assert resp.text.count('<title>card_card_1_1&#45;&gt;card_card_2_2</title>') == 9
760
    assert resp.text.count('<title>card_card_2_1&#45;&gt;card_card_2_2</title>') == 6
761
    assert resp.text.count('<title>card_card_3_1&#45;&gt;card_card_3_2</title>') == 6
774
    assert resp.text.count('<title>card_card_1_1&#45;&gt;card_card_1_2</title>') == 8
775
    assert resp.text.count('<title>card_card_1_1&#45;&gt;card_card_2_2</title>') == 12
776
    assert resp.text.count('<title>card_card_2_1&#45;&gt;card_card_2_2</title>') == 8
777
    assert resp.text.count('<title>card_card_3_1&#45;&gt;card_card_3_2</title>') == 8
762 778

  
763 779
    resp = app.get('/backoffice/cards/svg?show-orphans=on')
764 780
    assert '<title>card_card_1_3</title' in resp
......
778 794
    assert '<title>card_card_3_1</title' not in resp
779 795
    assert '<title>card_card_3_2</title' not in resp
780 796
    # and relations
781
    assert resp.text.count('<title>card_card_1_1&#45;&gt;card_card_1_2</title>') == 6
797
    assert resp.text.count('<title>card_card_1_1&#45;&gt;card_card_1_2</title>') == 8
782 798
    assert resp.text.count('<title>card_card_1_1&#45;&gt;card_card_2_2</title>') == 0
783 799
    assert resp.text.count('<title>card_card_2_1&#45;&gt;card_card_2_2</title>') == 0
784 800
    assert resp.text.count('<title>card_card_3_1&#45;&gt;card_card_3_2</title>') == 0
......
797 813
    # and relations
798 814
    assert resp.text.count('<title>card_card_1_1&#45;&gt;card_card_1_2</title>') == 0
799 815
    assert resp.text.count('<title>card_card_1_1&#45;&gt;card_card_2_2</title>') == 0
800
    assert resp.text.count('<title>card_card_2_1&#45;&gt;card_card_2_2</title>') == 6
816
    assert resp.text.count('<title>card_card_2_1&#45;&gt;card_card_2_2</title>') == 8
801 817
    assert resp.text.count('<title>card_card_3_1&#45;&gt;card_card_3_2</title>') == 0
wcs/carddef.py
304 304
            'string': '1..n',
305 305
            'item': '1..n',
306 306
            'items': 'n..n',
307
            'computed': '1..n',
307 308
        }
308 309
        for field in fields:
309 310
            data_source = getattr(field, 'data_source', None)
310
-