From cfd730371a368b76aa720cfa540e9535a3675cda Mon Sep 17 00:00:00 2001 From: Carlos de la Guardia Date: Mon, 10 Apr 2023 17:02:55 -0600 Subject: [PATCH] Update surveyjs version and theme handling --- docs/installation.rst | 13 +++++-------- questions/cli.py | 4 ++-- questions/form.py | 4 ++-- questions/settings.py | 10 ++-------- questions/templates.py | 14 +++++++------- tests/test_templates.py | 8 ++++---- 6 files changed, 22 insertions(+), 31 deletions(-) diff --git a/docs/installation.rst b/docs/installation.rst index 53d567f..014b194 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -113,16 +113,13 @@ The platforms are: The themes are: - - default - - bootstrap - - darkblue - - darkrose + - default (legacy) + - defaultV2 + - bootstrap (legacy) - modern - - orange - - stone - - winter - - winterstone +The default theme is named ``defaultV2``. There is an older default theme that is +now considered legacy. The old bootstrap theme is also legacy and deprecated. This command will download all the required resources to the directory specified. This is by far the simplest way to get running if you don't plan to do any javascript development as part of your application. diff --git a/questions/cli.py b/questions/cli.py index ecb1b84..6018111 100644 --- a/questions/cli.py +++ b/questions/cli.py @@ -32,7 +32,7 @@ def download_surveyjs(path, platform, theme): Platforms are: angular, jquery, knockout, react, vue. - Themes are: default, bootstrap, darkblue, darkrose, modern, orange, stone + Themes are: default, defaultV2, bootstrap, darkblue, darkrose, modern, orange, stone winter, winterstone. """ click.echo() @@ -66,7 +66,7 @@ def list_resources(platform, theme, include_widgets): Platforms are: angular, jquery, knockout, react, vue. - Themes are: default, bootstrap, darkblue, darkrose, modern, orange, stone + Themes are: default, defaultV2, bootstrap, darkblue, darkrose, modern, orange, stone winter, winterstone. """ click.echo() diff --git a/questions/form.py b/questions/form.py index e6a98b8..e48e805 100644 --- a/questions/form.py +++ b/questions/form.py @@ -60,7 +60,7 @@ class Form(object): :param html_id: The id for the div element that will be used to render the form. :param theme: - The name of the base theme for the form. Default value is 'default'. + The name of the base theme for the form. Default value is 'defaultV2'. :param platform: The JS platform to use for generating the form. Default value is 'jquery'. :param resource_url: @@ -84,7 +84,7 @@ def __init__( name: str = "", action: str = "", html_id: str = "questions_form", - theme: Literal[SURVEY_JS_THEMES] = "default", + theme: Literal[SURVEY_JS_THEMES] = "defaultV2", platform: Literal[SURVEY_JS_PLATFORMS] = "jquery", resource_url: str = None, **params, diff --git a/questions/settings.py b/questions/settings.py index 899c991..04f0a84 100644 --- a/questions/settings.py +++ b/questions/settings.py @@ -1,6 +1,6 @@ """Defines constants to be used throughout the code.""" -SURVEY_JS_VERSION = "1.8.2" +SURVEY_JS_VERSION = "1.9.81" SURVEY_JS_CDN = "https://unpkg.com" @@ -560,14 +560,8 @@ ) SURVEY_JS_THEMES = ( - "default", + "defaultV2", "bootstrap", - "orange", - "darkblue", - "darkrose", - "stone", - "winter", - "winterstone", "modern", ) diff --git a/questions/templates.py b/questions/templates.py index 3e9197e..27bd650 100644 --- a/questions/templates.py +++ b/questions/templates.py @@ -10,6 +10,7 @@ from .settings import BOOTSTRAP_URL from .settings import SUGGESTED_JS_BY_PLATFORM from .settings import SURVEY_JS_CDN +from .settings import SURVEY_JS_THEMES # Initialize Jinja environment @@ -58,12 +59,12 @@ def get_platform_js_resources( def get_theme_css_resources( - theme: str = "default", + theme: str = "defaultV2", resource_url: str = SURVEY_JS_CDN, ): """ Get the list of suggested CSS resources for a theme. if not using the - CDN, only the main SurveyJS CSS file is returned. + CDN, or using an unsupported theme, only the main SurveyJS CSS file is returned. :param theme: The name of the CSS theme. @@ -77,10 +78,9 @@ def get_theme_css_resources( return [BOOTSTRAP_URL] elif theme == "bootstrap": return [f"{resource_url}/bootstrap.min.css"] - name = "survey" - if theme == "modern": - name = "modern" - return [f"{resource_url}/survey-core/{name}.min.css"] + if theme not in SURVEY_JS_THEMES: + theme = "survey" + return [f"{resource_url}/survey-core/{theme}.min.css"] def get_survey_js( @@ -88,7 +88,7 @@ def get_survey_js( form_data: Dict[str, Any] = None, html_id: str = "questions_form", action: str = "", - theme: str = "default", + theme: str = "defaultV2", platform: str = "jquery", ): """ diff --git a/tests/test_templates.py b/tests/test_templates.py index 9fcd08f..469ae9e 100644 --- a/tests/test_templates.py +++ b/tests/test_templates.py @@ -33,13 +33,13 @@ def test_get_survey_js(): form_data="FORM_DATA", html_id="id", action="http://testing", - theme="default", + theme="defaultV2", platform="jquery", ) assert "FORM_JSON" in survey_js assert "FORM_DATA" in survey_js assert "http://testing" in survey_js - assert "default" in survey_js + assert "defaultV2" in survey_js def test_get_survey_js_form_data_is_none(): @@ -48,12 +48,12 @@ def test_get_survey_js_form_data_is_none(): form_data=None, html_id="id", action="http://testing", - theme="default", + theme="defaultV2", platform="jquery", ) assert "FORM_JSON" in survey_js assert "http://testing" in survey_js - assert "default" in survey_js + assert "defaultV2" in survey_js def test_get_form_page():