Skip to content

Commit

Permalink
Update surveyjs version and theme handling
Browse files Browse the repository at this point in the history
  • Loading branch information
cguardia committed Apr 10, 2023
1 parent 660cd92 commit cfd7303
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 31 deletions.
13 changes: 5 additions & 8 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions questions/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions questions/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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,
Expand Down
10 changes: 2 additions & 8 deletions questions/settings.py
Original file line number Diff line number Diff line change
@@ -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"

Expand Down Expand Up @@ -560,14 +560,8 @@
)

SURVEY_JS_THEMES = (
"default",
"defaultV2",
"bootstrap",
"orange",
"darkblue",
"darkrose",
"stone",
"winter",
"winterstone",
"modern",
)

Expand Down
14 changes: 7 additions & 7 deletions questions/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -77,18 +78,17 @@ 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(
form_json: str = "",
form_data: Dict[str, Any] = None,
html_id: str = "questions_form",
action: str = "",
theme: str = "default",
theme: str = "defaultV2",
platform: str = "jquery",
):
"""
Expand Down
8 changes: 4 additions & 4 deletions tests/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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():
Expand Down

0 comments on commit cfd7303

Please sign in to comment.