Projet

Général

Profil

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

Lauréline Guérin, 02 septembre 2021 09:51

Télécharger (5,58 ko)

Voir les différences:

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

 tests/test_fields.py | 101 +++++++++++++++++++++++++++++++++++++++++++
 wcs/fields.py        |   4 ++
 2 files changed, 105 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
3482 3482

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