Projet

Général

Profil

0001-wcs-adjust-labels-in-card-ids-selection-for-card-cel.patch

Lauréline Guérin, 01 septembre 2022 16:31

Télécharger (16 ko)

Voir les différences:

Subject: [PATCH] wcs: adjust labels in card ids selection for card cell
 (#68531)

 combo/apps/wcs/forms.py  |  13 ++--
 combo/apps/wcs/models.py |   5 +-
 tests/wcs/test_card.py   | 146 ++++++++++++++++++++-------------------
 3 files changed, 85 insertions(+), 79 deletions(-)
combo/apps/wcs/forms.py
74 74
        card_models = get_wcs_options('/api/cards/@list', include_custom_views=True)
75 75
        self.fields['carddef_reference'].widget = forms.Select(choices=card_models)
76 76

  
77
        self.fields['related_card_path'].choices = []
77
        self.fields['related_card_path'].choices = [
78
            ('__all__', _('All cards')),
79
        ]
78 80
        with_sub_slug = any(p.sub_slug for p in self.instance.page.get_parents_and_self())
79 81
        if with_sub_slug:
80 82
            self.fields['related_card_path'].choices += [
81
                ('--', _('According to page URL')),
83
                ('--', _('Card whose identifier is in the URL')),
82 84
            ]
83 85
            self.fields['related_card_path'].initial = '--'
84 86
            if not self.instance.card_ids and not self.instance.related_card_path:
85 87
                self.initial['related_card_path'] = '--'
86
        self.fields['related_card_path'].choices += [
87
            ('__all__', _('All cards')),
88
            ('', _('Others:')),
89
        ] + self.instance.get_related_card_paths()
88
        self.fields['related_card_path'].choices += self.instance.get_related_card_paths() + [
89
            ('', _('Template')),
90
        ]
90 91
        self.fields['card_ids'].label = ''
91 92
        self.fields['card_ids'].help_text = _('Card identifiers, separated by commas.')
92 93

  
combo/apps/wcs/models.py
1086 1086
                    'reverse:' if relation['reverse'] else '',
1087 1087
                    relation['varname'],
1088 1088
                )
1089
                new_label = '%s/%s%s' % (
1089
                _new_label = '%s/%s%s' % (
1090 1090
                    label,
1091 1091
                    relation['varname'],
1092 1092
                    ' (reverse)' if relation['reverse'] else '',
1093 1093
                )
1094
                new_label = _('Linked card: %s') % _new_label
1094 1095
                if relation['obj'] == 'carddef:%s' % self.card_slug:
1095 1096
                    # target carddef found
1096 1097
                    yield (new_path, new_label)
......
1103 1104
                        yield from iter_relations(
1104 1105
                            relations=new_card_schema['relations'],
1105 1106
                            path=new_path,
1106
                            label=new_label,
1107
                            label=_new_label,
1107 1108
                            carddefs_already_seen=carddefs_already_seen,
1108 1109
                        )
1109 1110

  
tests/wcs/test_card.py
394 394
    resp = app.get('/manage/pages/%s/' % page.pk)
395 395
    # but only one cell on the page, no relations to follow
396 396
    assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].options == [
397
        ('--', True, 'According to page URL'),
398 397
        ('__all__', False, 'All cards'),
399
        ('', False, 'Others:'),
398
        ('--', True, 'Card whose identifier is in the URL'),
399
        ('', False, 'Template'),
400 400
    ]
401 401

  
402 402
    # all cards
......
404 404
    cell.save()
405 405
    resp = app.get('/manage/pages/%s/' % page.pk)
406 406
    assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].options == [
407
        ('--', False, 'According to page URL'),
408 407
        ('__all__', True, 'All cards'),
409
        ('', False, 'Others:'),
408
        ('--', False, 'Card whose identifier is in the URL'),
409
        ('', False, 'Template'),
410 410
    ]
411 411

  
412 412
    # add a second cell, related to the first card model
......
418 418
    resp = app.get('/manage/pages/%s/' % page.pk)
419 419
    # still no relation to follow
420 420
    assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].options == [
421
        ('--', True, 'According to page URL'),
422 421
        ('__all__', False, 'All cards'),
423
        ('', False, 'Others:'),
422
        ('--', True, 'Card whose identifier is in the URL'),
423
        ('', False, 'Template'),
424 424
    ]
425 425
    # no cell with id and slug
426 426
    assert resp.forms[1]['c%s-related_card_path' % cell2.get_reference()].options == [
427
        ('--', True, 'According to page URL'),
428 427
        ('__all__', False, 'All cards'),
429
        ('', False, 'Others:'),
428
        ('--', True, 'Card whose identifier is in the URL'),
429
        ('', False, 'Template'),
430 430
    ]
431 431

  
432 432
    # set a slug on first cell
......
435 435
    resp = app.get('/manage/pages/%s/' % page.pk)
436 436
    # still no relation to follow
437 437
    assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].options == [
438
        ('--', True, 'According to page URL'),
439 438
        ('__all__', False, 'All cards'),
440
        ('', False, 'Others:'),
439
        ('--', True, 'Card whose identifier is in the URL'),
440
        ('', False, 'Template'),
441 441
    ]
442 442
    # multiple relations to follow
443 443
    assert resp.forms[1]['c%s-related_card_path' % cell2.get_reference()].options == [
444
        ('--', True, 'According to page URL'),
445 444
        ('__all__', False, 'All cards'),
446
        ('', False, 'Others:'),
447
        ('sluga/cardb', False, 'sluga/cardb'),
448
        ('sluga/cardsb', False, 'sluga/cardsb'),
449
        ('sluga/blockb_cardb', False, 'sluga/blockb_cardb'),
450
        ('sluga/cardc/cardb', False, 'sluga/cardc/cardb'),
451
        ('sluga/cardc/cardsb', False, 'sluga/cardc/cardsb'),
452
        ('sluga/cardc/blockb_cardb', False, 'sluga/cardc/blockb_cardb'),
445
        ('--', True, 'Card whose identifier is in the URL'),
446
        ('sluga/cardb', False, 'Linked card: sluga/cardb'),
447
        ('sluga/cardsb', False, 'Linked card: sluga/cardsb'),
448
        ('sluga/blockb_cardb', False, 'Linked card: sluga/blockb_cardb'),
449
        ('sluga/cardc/cardb', False, 'Linked card: sluga/cardc/cardb'),
450
        ('sluga/cardc/cardsb', False, 'Linked card: sluga/cardc/cardsb'),
451
        ('sluga/cardc/blockb_cardb', False, 'Linked card: sluga/cardc/blockb_cardb'),
452
        ('', False, 'Template'),
453 453
    ]
454 454

  
455 455
    # set a list of ids on first cell
......
458 458
    resp = app.get('/manage/pages/%s/' % page.pk)
459 459
    # still no relation to follow
460 460
    assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].options == [
461
        ('--', False, 'According to page URL'),
462 461
        ('__all__', False, 'All cards'),
463
        ('', True, 'Others:'),
462
        ('--', False, 'Card whose identifier is in the URL'),
463
        ('', True, 'Template'),
464 464
    ]
465 465
    # can not user cell with multiple ids as reference
466 466
    assert resp.forms[1]['c%s-related_card_path' % cell2.get_reference()].options == [
467
        ('--', True, 'According to page URL'),
468 467
        ('__all__', False, 'All cards'),
469
        ('', False, 'Others:'),
468
        ('--', True, 'Card whose identifier is in the URL'),
469
        ('', False, 'Template'),
470 470
    ]
471 471

  
472 472
    # define a slug on second cell
......
477 477
    resp = app.get('/manage/pages/%s/' % page.pk)
478 478
    # multiple relations to follow
479 479
    assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].options == [
480
        ('--', True, 'According to page URL'),
481 480
        ('__all__', False, 'All cards'),
482
        ('', False, 'Others:'),
483
        ('slugb/reverse:cardb', False, 'slugb/cardb (reverse)'),
484
        ('slugb/reverse:cardsb', False, 'slugb/cardsb (reverse)'),
485
        ('slugb/reverse:blockb_cardb', False, 'slugb/blockb_cardb (reverse)'),
481
        ('--', True, 'Card whose identifier is in the URL'),
482
        ('slugb/reverse:cardb', False, 'Linked card: slugb/cardb (reverse)'),
483
        ('slugb/reverse:cardsb', False, 'Linked card: slugb/cardsb (reverse)'),
484
        ('slugb/reverse:blockb_cardb', False, 'Linked card: slugb/blockb_cardb (reverse)'),
485
        ('', False, 'Template'),
486 486
    ]
487 487
    # still multiple relations to follow
488 488
    assert resp.forms[1]['c%s-related_card_path' % cell2.get_reference()].options == [
489
        ('--', True, 'According to page URL'),
490 489
        ('__all__', False, 'All cards'),
491
        ('', False, 'Others:'),
492
        ('sluga/cardb', False, 'sluga/cardb'),
493
        ('sluga/cardsb', False, 'sluga/cardsb'),
494
        ('sluga/blockb_cardb', False, 'sluga/blockb_cardb'),
495
        ('sluga/cardc/cardb', False, 'sluga/cardc/cardb'),
496
        ('sluga/cardc/cardsb', False, 'sluga/cardc/cardsb'),
497
        ('sluga/cardc/blockb_cardb', False, 'sluga/cardc/blockb_cardb'),
490
        ('--', True, 'Card whose identifier is in the URL'),
491
        ('sluga/cardb', False, 'Linked card: sluga/cardb'),
492
        ('sluga/cardsb', False, 'Linked card: sluga/cardsb'),
493
        ('sluga/blockb_cardb', False, 'Linked card: sluga/blockb_cardb'),
494
        ('sluga/cardc/cardb', False, 'Linked card: sluga/cardc/cardb'),
495
        ('sluga/cardc/cardsb', False, 'Linked card: sluga/cardc/cardsb'),
496
        ('sluga/cardc/blockb_cardb', False, 'Linked card: sluga/cardc/blockb_cardb'),
497
        ('', False, 'Template'),
498 498
    ]
499 499

  
500 500
    # set a related_path on cell2
......
507 507
    resp = app.get('/manage/pages/%s/' % page.pk)
508 508
    # no more relation to follow
509 509
    assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].options == [
510
        ('--', True, 'According to page URL'),
511 510
        ('__all__', False, 'All cards'),
512
        ('', False, 'Others:'),
511
        ('--', True, 'Card whose identifier is in the URL'),
512
        ('', False, 'Template'),
513 513
    ]
514 514
    # still multiple relations to follow
515 515
    assert resp.forms[1]['c%s-related_card_path' % cell2.get_reference()].options == [
516
        ('--', False, 'According to page URL'),
517 516
        ('__all__', False, 'All cards'),
518
        ('', False, 'Others:'),
519
        ('sluga/cardb', True, 'sluga/cardb'),
520
        ('sluga/cardsb', False, 'sluga/cardsb'),
521
        ('sluga/blockb_cardb', False, 'sluga/blockb_cardb'),
522
        ('sluga/cardc/cardb', False, 'sluga/cardc/cardb'),
523
        ('sluga/cardc/cardsb', False, 'sluga/cardc/cardsb'),
524
        ('sluga/cardc/blockb_cardb', False, 'sluga/cardc/blockb_cardb'),
517
        ('--', False, 'Card whose identifier is in the URL'),
518
        ('sluga/cardb', True, 'Linked card: sluga/cardb'),
519
        ('sluga/cardsb', False, 'Linked card: sluga/cardsb'),
520
        ('sluga/blockb_cardb', False, 'Linked card: sluga/blockb_cardb'),
521
        ('sluga/cardc/cardb', False, 'Linked card: sluga/cardc/cardb'),
522
        ('sluga/cardc/cardsb', False, 'Linked card: sluga/cardc/cardsb'),
523
        ('sluga/cardc/blockb_cardb', False, 'Linked card: sluga/cardc/blockb_cardb'),
524
        ('', False, 'Template'),
525 525
    ]
526 526
    resp.forms[1].submit()
527 527
    cell2.refresh_from_db()
......
538 538
    cell2.save()
539 539
    resp = app.get('/manage/pages/%s/' % page.pk)
540 540
    assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].options == [
541
        ('--', True, 'According to page URL'),
542 541
        ('__all__', False, 'All cards'),
543
        ('', False, 'Others:'),
544
        ('slugd/cardd-foo/carde-foo', False, 'slugd/cardd-foo/carde-foo'),
545
        ('slugd/carde-foo', False, 'slugd/carde-foo'),
542
        ('--', True, 'Card whose identifier is in the URL'),
543
        ('slugd/cardd-foo/carde-foo', False, 'Linked card: slugd/cardd-foo/carde-foo'),
544
        ('slugd/carde-foo', False, 'Linked card: slugd/carde-foo'),
545
        ('', False, 'Template'),
546 546
    ]
547 547
    assert resp.forms[1]['c%s-related_card_path' % cell2.get_reference()].options == [
548
        ('--', True, 'According to page URL'),
549 548
        ('__all__', False, 'All cards'),
550
        ('', False, 'Others:'),
551
        ('sluge/cardd-bar', False, 'sluge/cardd-bar'),
552
        ('sluge/reverse:carde-foo', False, 'sluge/carde-foo (reverse)'),
549
        ('--', True, 'Card whose identifier is in the URL'),
550
        ('sluge/cardd-bar', False, 'Linked card: sluge/cardd-bar'),
551
        ('sluge/reverse:carde-foo', False, 'Linked card: sluge/carde-foo (reverse)'),
552
        ('', False, 'Template'),
553 553
    ]
554 554

  
555 555
    cell.slug = 'slugd'
......
561 561
    cell2.save()
562 562
    resp = app.get('/manage/pages/%s/' % page.pk)
563 563
    assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].options == [
564
        ('--', True, 'According to page URL'),
565 564
        ('__all__', False, 'All cards'),
566
        ('', False, 'Others:'),
567
        ('slugd-bis/cardd-foo', False, 'slugd-bis/cardd-foo'),
568
        ('slugd-bis/reverse:cardd-foo', False, 'slugd-bis/cardd-foo (reverse)'),
569
        ('slugd-bis/carde-foo/cardd-bar', False, 'slugd-bis/carde-foo/cardd-bar'),
570
        ('slugd-bis/carde-foo/reverse:carde-foo', False, 'slugd-bis/carde-foo/carde-foo (reverse)'),
565
        ('--', True, 'Card whose identifier is in the URL'),
566
        ('slugd-bis/cardd-foo', False, 'Linked card: slugd-bis/cardd-foo'),
567
        ('slugd-bis/reverse:cardd-foo', False, 'Linked card: slugd-bis/cardd-foo (reverse)'),
568
        ('slugd-bis/carde-foo/cardd-bar', False, 'Linked card: slugd-bis/carde-foo/cardd-bar'),
569
        (
570
            'slugd-bis/carde-foo/reverse:carde-foo',
571
            False,
572
            'Linked card: slugd-bis/carde-foo/carde-foo (reverse)',
573
        ),
574
        ('', False, 'Template'),
571 575
    ]
572 576
    assert resp.forms[1]['c%s-related_card_path' % cell2.get_reference()].options == [
573
        ('--', True, 'According to page URL'),
574 577
        ('__all__', False, 'All cards'),
575
        ('', False, 'Others:'),
576
        ('slugd/cardd-foo', False, 'slugd/cardd-foo'),
577
        ('slugd/reverse:cardd-foo', False, 'slugd/cardd-foo (reverse)'),
578
        ('slugd/carde-foo/cardd-bar', False, 'slugd/carde-foo/cardd-bar'),
579
        ('slugd/carde-foo/reverse:carde-foo', False, 'slugd/carde-foo/carde-foo (reverse)'),
578
        ('--', True, 'Card whose identifier is in the URL'),
579
        ('slugd/cardd-foo', False, 'Linked card: slugd/cardd-foo'),
580
        ('slugd/reverse:cardd-foo', False, 'Linked card: slugd/cardd-foo (reverse)'),
581
        ('slugd/carde-foo/cardd-bar', False, 'Linked card: slugd/carde-foo/cardd-bar'),
582
        ('slugd/carde-foo/reverse:carde-foo', False, 'Linked card: slugd/carde-foo/carde-foo (reverse)'),
583
        ('', False, 'Template'),
580 584
    ]
581 585

  
582 586
    cell.slug = 'sluge'
......
588 592
    cell2.save()
589 593
    resp = app.get('/manage/pages/%s/' % page.pk)
590 594
    assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].options == [
591
        ('--', True, 'According to page URL'),
592 595
        ('__all__', False, 'All cards'),
593
        ('', False, 'Others:'),
594
        ('sluge-bis/cardd-bar/carde-foo', False, 'sluge-bis/cardd-bar/carde-foo'),
596
        ('--', True, 'Card whose identifier is in the URL'),
597
        ('sluge-bis/cardd-bar/carde-foo', False, 'Linked card: sluge-bis/cardd-bar/carde-foo'),
598
        ('', False, 'Template'),
595 599
    ]
596 600
    assert resp.forms[1]['c%s-related_card_path' % cell2.get_reference()].options == [
597
        ('--', True, 'According to page URL'),
598 601
        ('__all__', False, 'All cards'),
599
        ('', False, 'Others:'),
600
        ('sluge/cardd-bar/carde-foo', False, 'sluge/cardd-bar/carde-foo'),
602
        ('--', True, 'Card whose identifier is in the URL'),
603
        ('sluge/cardd-bar/carde-foo', False, 'Linked card: sluge/cardd-bar/carde-foo'),
604
        ('', False, 'Template'),
601 605
    ]
602 606

  
603 607

  
604
-