Better check_config.py example
authorKarl O. Pinc <kop@karlpinc.com>
Tue, 17 Nov 2020 19:52:46 +0000 (13:52 -0600)
committerKarl O. Pinc <kop@karlpinc.com>
Tue, 17 Nov 2020 19:52:46 +0000 (13:52 -0600)
README.rst

index 167d4b32fbd04a36ac12aa5e0492b5b058a46483..4076584e13d42a6c442c53e4beccbd1e83028f71 100644 (file)
@@ -367,15 +367,27 @@ PGWUI_Common contains helpers to use when checking settings.  An
 example setting checker from PGWUI_Upload is::
 
    from pgwui_common import checkset
+   from . import exceptions as upload_ex
 
 
    PGWUI_COMPONENT = 'pgwui_upload'
    UPLOAD_SETTINGS = ['menu_label',
+                      'literal_column_headings',
                       ]
    REQUIRED_SETTINGS = []
    BOOLEAN_SETTINGS = []
 
 
+   def validate_literal_column_headings(errors, settings):
+       '''Make sure the values are those allowed
+       '''
+       value = settings.get('literal_column_headings')
+       if value is None:
+           return
+       if value not in ('on', 'off', 'ask'):
+           errors.append(upload_ex.BadLiteralColumnHeadingsError(value))
+
+
    def check_settings(component_config):
        '''Check that all pgwui_upload specific settings are good.
        This includes:
@@ -384,13 +396,17 @@ example setting checker from PGWUI_Upload is::
          checking the boolean settings
          checking that the values of other settings are valid
        '''
-       return (
-           checkset.unknown_settings(
-               PGWUI_COMPONENT, UPLOAD_SETTINGS, component_config)
-           .extend(checkset.require_settings(
-               PGWUI_COMPONENT, REQUIRED_SETTINGS, component_config)
-               .extend(checkset.boolean_settings(
-                   PGWUI_COMPONENT, BOOLEAN_SETTINGS, component_config))))
+       errors = []
+       errors.extend(checkset.unknown_settings(
+           PGWUI_COMPONENT, UPLOAD_SETTINGS, component_config))
+       errors.extend(checkset.require_settings(
+           PGWUI_COMPONENT, REQUIRED_SETTINGS, component_config))
+       errors.extend(checkset.boolean_settings(
+           PGWUI_COMPONENT, BOOLEAN_SETTINGS, component_config))
+       validate_literal_column_headings(errors, component_config)
+
+       return errors
+
 
 When establishing the entrypoint for your PGWUI componenent the name
 of the entrypoint is the name of the pgwui component.  The value