From aadf79dfdb02088f7bd644bebf07a27b80c1e7e8 Mon Sep 17 00:00:00 2001 From: "Karl O. Pinc" Date: Tue, 17 Nov 2020 13:52:46 -0600 Subject: [PATCH] Better check_config.py example --- README.rst | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/README.rst b/README.rst index 167d4b3..4076584 100644 --- a/README.rst +++ b/README.rst @@ -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 -- 2.34.1