Projet

Général

Profil

0001-wcs-adjust-labels-of-cards-to-display-selection-6851.patch

Frédéric Péters, 29 août 2022 15:26

Télécharger (10,8 ko)

Voir les différences:

Subject: [PATCH] wcs: adjust labels of cards to display selection (#68517)

 combo/apps/wcs/forms.py |  6 ++--
 tests/wcs/test_card.py  | 72 ++++++++++++++++++++---------------------
 2 files changed, 40 insertions(+), 38 deletions(-)
combo/apps/wcs/forms.py
78 78
        with_sub_slug = any(p.sub_slug for p in self.instance.page.get_parents_and_self())
79 79
        if with_sub_slug:
80 80
            self.fields['related_card_path'].choices += [
81
                ('--', _('Identifier from page URL')),
81
                ('--', _('According to page URL')),
82 82
            ]
83 83
            self.fields['related_card_path'].initial = '--'
84 84
            if not self.instance.card_ids and not self.instance.related_card_path:
85 85
                self.initial['related_card_path'] = '--'
86 86
        self.fields['related_card_path'].choices += [
87 87
            ('__all__', _('All cards')),
88
            ('', _('Other Card Identifiers')),
88
            ('', _('Others:')),
89 89
        ] + self.instance.get_related_card_paths()
90
        self.fields['card_ids'].label = ''
91
        self.fields['card_ids'].help_text = _('Card identifiers, separated by commas.')
90 92

  
91 93
    def save(self, *args, **kwargs):
92 94
        super().save(*args, **kwargs)
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, 'Identifier from page URL'),
397
        ('--', True, 'According to page URL'),
398 398
        ('__all__', False, 'All cards'),
399
        ('', False, 'Other Card Identifiers'),
399
        ('', False, 'Others:'),
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, 'Identifier from page URL'),
407
        ('--', False, 'According to page URL'),
408 408
        ('__all__', True, 'All cards'),
409
        ('', False, 'Other Card Identifiers'),
409
        ('', False, 'Others:'),
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, 'Identifier from page URL'),
421
        ('--', True, 'According to page URL'),
422 422
        ('__all__', False, 'All cards'),
423
        ('', False, 'Other Card Identifiers'),
423
        ('', False, 'Others:'),
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, 'Identifier from page URL'),
427
        ('--', True, 'According to page URL'),
428 428
        ('__all__', False, 'All cards'),
429
        ('', False, 'Other Card Identifiers'),
429
        ('', False, 'Others:'),
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, 'Identifier from page URL'),
438
        ('--', True, 'According to page URL'),
439 439
        ('__all__', False, 'All cards'),
440
        ('', False, 'Other Card Identifiers'),
440
        ('', False, 'Others:'),
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, 'Identifier from page URL'),
444
        ('--', True, 'According to page URL'),
445 445
        ('__all__', False, 'All cards'),
446
        ('', False, 'Other Card Identifiers'),
446
        ('', False, 'Others:'),
447 447
        ('sluga/cardb', False, 'sluga/cardb'),
448 448
        ('sluga/cardsb', False, 'sluga/cardsb'),
449 449
        ('sluga/blockb_cardb', False, 'sluga/blockb_cardb'),
......
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, 'Identifier from page URL'),
461
        ('--', False, 'According to page URL'),
462 462
        ('__all__', False, 'All cards'),
463
        ('', True, 'Other Card Identifiers'),
463
        ('', True, 'Others:'),
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, 'Identifier from page URL'),
467
        ('--', True, 'According to page URL'),
468 468
        ('__all__', False, 'All cards'),
469
        ('', False, 'Other Card Identifiers'),
469
        ('', False, 'Others:'),
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, 'Identifier from page URL'),
480
        ('--', True, 'According to page URL'),
481 481
        ('__all__', False, 'All cards'),
482
        ('', False, 'Other Card Identifiers'),
482
        ('', False, 'Others:'),
483 483
        ('slugb/reverse:cardb', False, 'slugb/cardb (reverse)'),
484 484
        ('slugb/reverse:cardsb', False, 'slugb/cardsb (reverse)'),
485 485
        ('slugb/reverse:blockb_cardb', False, 'slugb/blockb_cardb (reverse)'),
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, 'Identifier from page URL'),
489
        ('--', True, 'According to page URL'),
490 490
        ('__all__', False, 'All cards'),
491
        ('', False, 'Other Card Identifiers'),
491
        ('', False, 'Others:'),
492 492
        ('sluga/cardb', False, 'sluga/cardb'),
493 493
        ('sluga/cardsb', False, 'sluga/cardsb'),
494 494
        ('sluga/blockb_cardb', False, 'sluga/blockb_cardb'),
......
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, 'Identifier from page URL'),
510
        ('--', True, 'According to page URL'),
511 511
        ('__all__', False, 'All cards'),
512
        ('', False, 'Other Card Identifiers'),
512
        ('', False, 'Others:'),
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, 'Identifier from page URL'),
516
        ('--', False, 'According to page URL'),
517 517
        ('__all__', False, 'All cards'),
518
        ('', False, 'Other Card Identifiers'),
518
        ('', False, 'Others:'),
519 519
        ('sluga/cardb', True, 'sluga/cardb'),
520 520
        ('sluga/cardsb', False, 'sluga/cardsb'),
521 521
        ('sluga/blockb_cardb', False, 'sluga/blockb_cardb'),
......
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, 'Identifier from page URL'),
541
        ('--', True, 'According to page URL'),
542 542
        ('__all__', False, 'All cards'),
543
        ('', False, 'Other Card Identifiers'),
543
        ('', False, 'Others:'),
544 544
        ('slugd/cardd-foo/carde-foo', False, 'slugd/cardd-foo/carde-foo'),
545 545
        ('slugd/carde-foo', False, 'slugd/carde-foo'),
546 546
    ]
547 547
    assert resp.forms[1]['c%s-related_card_path' % cell2.get_reference()].options == [
548
        ('--', True, 'Identifier from page URL'),
548
        ('--', True, 'According to page URL'),
549 549
        ('__all__', False, 'All cards'),
550
        ('', False, 'Other Card Identifiers'),
550
        ('', False, 'Others:'),
551 551
        ('sluge/cardd-bar', False, 'sluge/cardd-bar'),
552 552
        ('sluge/reverse:carde-foo', False, 'sluge/carde-foo (reverse)'),
553 553
    ]
......
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, 'Identifier from page URL'),
564
        ('--', True, 'According to page URL'),
565 565
        ('__all__', False, 'All cards'),
566
        ('', False, 'Other Card Identifiers'),
566
        ('', False, 'Others:'),
567 567
        ('slugd-bis/cardd-foo', False, 'slugd-bis/cardd-foo'),
568 568
        ('slugd-bis/reverse:cardd-foo', False, 'slugd-bis/cardd-foo (reverse)'),
569 569
        ('slugd-bis/carde-foo/cardd-bar', False, 'slugd-bis/carde-foo/cardd-bar'),
570 570
        ('slugd-bis/carde-foo/reverse:carde-foo', False, 'slugd-bis/carde-foo/carde-foo (reverse)'),
571 571
    ]
572 572
    assert resp.forms[1]['c%s-related_card_path' % cell2.get_reference()].options == [
573
        ('--', True, 'Identifier from page URL'),
573
        ('--', True, 'According to page URL'),
574 574
        ('__all__', False, 'All cards'),
575
        ('', False, 'Other Card Identifiers'),
575
        ('', False, 'Others:'),
576 576
        ('slugd/cardd-foo', False, 'slugd/cardd-foo'),
577 577
        ('slugd/reverse:cardd-foo', False, 'slugd/cardd-foo (reverse)'),
578 578
        ('slugd/carde-foo/cardd-bar', False, 'slugd/carde-foo/cardd-bar'),
......
588 588
    cell2.save()
589 589
    resp = app.get('/manage/pages/%s/' % page.pk)
590 590
    assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].options == [
591
        ('--', True, 'Identifier from page URL'),
591
        ('--', True, 'According to page URL'),
592 592
        ('__all__', False, 'All cards'),
593
        ('', False, 'Other Card Identifiers'),
593
        ('', False, 'Others:'),
594 594
        ('sluge-bis/cardd-bar/carde-foo', False, 'sluge-bis/cardd-bar/carde-foo'),
595 595
    ]
596 596
    assert resp.forms[1]['c%s-related_card_path' % cell2.get_reference()].options == [
597
        ('--', True, 'Identifier from page URL'),
597
        ('--', True, 'According to page URL'),
598 598
        ('__all__', False, 'All cards'),
599
        ('', False, 'Other Card Identifiers'),
599
        ('', False, 'Others:'),
600 600
        ('sluge/cardd-bar/carde-foo', False, 'sluge/cardd-bar/carde-foo'),
601 601
    ]
602 602

  
603
-