Projet

Général

Profil

0001-misc-add-option-to-disable-some-fields-56118.patch

Lauréline Guérin, 20 août 2021 14:31

Télécharger (5,51 ko)

Voir les différences:

Subject: [PATCH] misc: add option to disable some fields (#56118)

 tests/test_fields.py | 101 +++++++++++++++++++++++++++++++++++++++++++
 wcs/fields.py        |   3 ++
 2 files changed, 104 insertions(+)
tests/test_fields.py
1
import os
1 2
import re
2 3
import shutil
3 4

  
......
626 627
    )
627 628
    assert value.base_filename == 'test.txt'
628 629
    assert value.get_file_pointer().read() == b'hello'
630

  
631

  
632
def test_new_field_type_options():
633
    pub.load_site_options()
634
    if not pub.site_options.has_section('options'):
635
        pub.site_options.add_section('options')
636
    pub.site_options.set('options', 'disabled-fields', '[]')
637
    with open(os.path.join(pub.app_dir, 'site-options.cfg'), 'w') as fd:
638
        pub.site_options.write(fd)
639

  
640
    assert fields.get_field_options(blacklisted_types=[]) == [
641
        ('string', 'Text (line)', 'string'),
642
        ('text', 'Long Text', 'text'),
643
        ('email', 'Email', 'email'),
644
        ('bool', 'Check Box (single choice)', 'bool'),
645
        ('file', 'File Upload', 'file'),
646
        ('date', 'Date', 'date'),
647
        ('item', 'List', 'item'),
648
        ('items', 'Multiple choice list', 'items'),
649
        ('table', 'Table', 'table'),
650
        ('table-select', 'Table of Lists', 'table-select'),
651
        ('tablerows', 'Table with rows', 'tablerows'),
652
        ('map', 'Map', 'map'),
653
        ('ranked-items', 'Ranked Items', 'ranked-items'),
654
        ('password', 'Password', 'password'),
655
        ('', '—', ''),
656
        ('title', 'Title', 'title'),
657
        ('subtitle', 'Subtitle', 'subtitle'),
658
        ('comment', 'Comment', 'comment'),
659
        ('page', 'Page', 'page'),
660
        ('', '—', ''),
661
        ('computed', 'Computed Data', 'computed'),
662
    ]
663
    assert fields.get_field_options(blacklisted_types=['password', 'page']) == [
664
        ('string', 'Text (line)', 'string'),
665
        ('text', 'Long Text', 'text'),
666
        ('email', 'Email', 'email'),
667
        ('bool', 'Check Box (single choice)', 'bool'),
668
        ('file', 'File Upload', 'file'),
669
        ('date', 'Date', 'date'),
670
        ('item', 'List', 'item'),
671
        ('items', 'Multiple choice list', 'items'),
672
        ('table', 'Table', 'table'),
673
        ('table-select', 'Table of Lists', 'table-select'),
674
        ('tablerows', 'Table with rows', 'tablerows'),
675
        ('map', 'Map', 'map'),
676
        ('ranked-items', 'Ranked Items', 'ranked-items'),
677
        ('', '—', ''),
678
        ('title', 'Title', 'title'),
679
        ('subtitle', 'Subtitle', 'subtitle'),
680
        ('comment', 'Comment', 'comment'),
681
        ('', '—', ''),
682
        ('computed', 'Computed Data', 'computed'),
683
    ]
684

  
685
    pub.site_options.set('options', 'disabled-fields', '["table", "password"]')
686
    with open(os.path.join(pub.app_dir, 'site-options.cfg'), 'w') as fd:
687
        pub.site_options.write(fd)
688

  
689
    assert fields.get_field_options(blacklisted_types=[]) == [
690
        ('string', 'Text (line)', 'string'),
691
        ('text', 'Long Text', 'text'),
692
        ('email', 'Email', 'email'),
693
        ('bool', 'Check Box (single choice)', 'bool'),
694
        ('file', 'File Upload', 'file'),
695
        ('date', 'Date', 'date'),
696
        ('item', 'List', 'item'),
697
        ('items', 'Multiple choice list', 'items'),
698
        ('table-select', 'Table of Lists', 'table-select'),
699
        ('tablerows', 'Table with rows', 'tablerows'),
700
        ('map', 'Map', 'map'),
701
        ('ranked-items', 'Ranked Items', 'ranked-items'),
702
        ('', '—', ''),
703
        ('title', 'Title', 'title'),
704
        ('subtitle', 'Subtitle', 'subtitle'),
705
        ('comment', 'Comment', 'comment'),
706
        ('page', 'Page', 'page'),
707
        ('', '—', ''),
708
        ('computed', 'Computed Data', 'computed'),
709
    ]
710
    assert fields.get_field_options(blacklisted_types=['password', 'page']) == [
711
        ('string', 'Text (line)', 'string'),
712
        ('text', 'Long Text', 'text'),
713
        ('email', 'Email', 'email'),
714
        ('bool', 'Check Box (single choice)', 'bool'),
715
        ('file', 'File Upload', 'file'),
716
        ('date', 'Date', 'date'),
717
        ('item', 'List', 'item'),
718
        ('items', 'Multiple choice list', 'items'),
719
        ('table-select', 'Table of Lists', 'table-select'),
720
        ('tablerows', 'Table with rows', 'tablerows'),
721
        ('map', 'Map', 'map'),
722
        ('ranked-items', 'Ranked Items', 'ranked-items'),
723
        ('', '—', ''),
724
        ('title', 'Title', 'title'),
725
        ('subtitle', 'Subtitle', 'subtitle'),
726
        ('comment', 'Comment', 'comment'),
727
        ('', '—', ''),
728
        ('computed', 'Computed Data', 'computed'),
729
    ]
wcs/fields.py
3479 3479

  
3480 3480
def get_field_options(blacklisted_types):
3481 3481
    widgets, non_widgets = [], []
3482
    disabled_fields = get_publisher().get_site_option('disabled-fields') or []
3482 3483
    for klass in field_classes:
3483 3484
        if klass is ComputedField:
3484 3485
            continue
3485 3486
        if klass.key in blacklisted_types:
3486 3487
            continue
3488
        if klass.key in disabled_fields:
3489
            continue
3487 3490
        if issubclass(klass, WidgetField):
3488 3491
            widgets.append((klass.key, klass.description, klass.key))
3489 3492
        else:
3490
-