Skip to content

Commit

Permalink
Add panels (#3)
Browse files Browse the repository at this point in the history
Implement panels
  • Loading branch information
jakub-jedrusiak authored Oct 3, 2024
1 parent 15961f8 commit 6c9c294
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 0 deletions.
64 changes: 64 additions & 0 deletions velesresearch/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,70 @@ class QuestionNoUiSliderModel(QuestionModel):
type: str = Field(default="nouislider")


class PanelModel(BaseModel):
"""Object model for panel data
Attributes:
name (str): The label of the panel.
questions (QuestionModel | list): The questions on the panel.
description (str | None): Optional subtitle or description of the panel.
enableIf (str | None): Expression to enable the panel.
id (str | None): HTML id attribute for the panel. Usually not necessary.
innerIndent (int | None): The inner indent of the panel from the left edge. Can be integers from 0 up.
isRequired (bool): Whether the panel is required (at least one question must be answered).
maxWidth (str): Maximum width of the panel in CSS units.
minWidth (str): Minimum width of the panel in CSS units.
questionErrorLocation (str): The location of the error text for the questions. Can be 'default', 'top', 'bottom'.
questionsOrder (str): The order of the questions. Can be 'default', 'random', 'initial'.
questionStartIndex (str | None): The start index of the questions' numbers. Can include prefixes and suffixes. Default is '1.'.
questionTitleLocation (str): The location of the title for the questions. Can be 'default', 'top', 'bottom'.
questionTitleWidth (str | None): The width of the question title in CSS units. Only if `questionTitleLocation='left'`.
readOnly (bool): Whether the panel is read-only.
requiredErrorText (str | None): Error text if the required condition is not met.
requiredIf (str | None): Expression to make the panel required.
rightIndent (int | None): The right indent of the panel from the right edge. Can be integers from 0 up.
showNumber (bool): Whether to show the panel number.
showQuestionNumbers (str): Whether to show the question numbers. Can be 'default', 'onpanel', 'off'.
startWithNewLine (bool): Whether to start the panel on a new line.
title (str): The visible title of the panel.
visible (bool): Whether the panel is visible.
visibleIf (str | None): Expression to make the panel visible.
width (str): Width of the panel in CSS units.
"""

name: str
questions: QuestionModel | list
description: str | None = None
enableIf: str | None = None
id: str | None = None
innerIndent: int | None = None
isRequired: bool = False
maxWidth: str = "100%"
minWidth: str = "300px"
questionErrorLocation: str = "default"
questionsOrder: str = "default"
questionStartIndex: str | None = None
questionTitleLocation: str = "default"
questionTitleWidth: str | None = None
readOnly: bool = False
requiredErrorText: str | None = None
requiredIf: str | None = None
rightIndent: int | None = None
showNumber: bool = False
showQuestionNumbers: str = "default"
startWithNewLine: bool = True
title: str | None = None
visible: bool = True
visibleIf: str | None = None
width: str = ""

def dict(self) -> dict:
return dict_without_defaults(self) | {
"type": "panel",
"elements": [question.dict() for question in self.questions],
}


class PageModel(BaseModel):
"""Object model for page data
Expand Down
60 changes: 60 additions & 0 deletions velesresearch/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,66 @@ def page(
)


def panel(
name: str,
*questions: QuestionModel | list[QuestionModel],
description: str | None = None,
enableIf: str | None = None,
id: str | None = None,
innerIndent: int | None = None,
isRequired: bool = False,
maxWidth: str = "100%",
minWidth: str = "300px",
questionErrorLocation: str = "default",
questionsOrder: str = "default",
questionStartIndex: str | None = None,
questionTitleLocation: str = "default",
questionTitleWidth: str | None = None,
readOnly: bool = False,
requiredErrorText: str | None = None,
requiredIf: str | None = None,
rightIndent: int | None = None,
showNumber: bool = False,
showQuestionNumbers: str = "default",
startWithNewLine: bool = True,
visible: bool = True,
visibleIf: str | None = None,
width: str = "",
**kwargs,
) -> PanelModel:
args = {
"description": description,
"enableIf": enableIf,
"id": id,
"innerIndent": innerIndent,
"isRequired": isRequired,
"maxWidth": maxWidth,
"minWidth": minWidth,
"questionErrorLocation": questionErrorLocation,
"questionsOrder": questionsOrder,
"questionStartIndex": questionStartIndex,
"questionTitleLocation": questionTitleLocation,
"questionTitleWidth": questionTitleWidth,
"readOnly": readOnly,
"requiredErrorText": requiredErrorText,
"requiredIf": requiredIf,
"rightIndent": rightIndent,
"showNumber": showNumber,
"showQuestionNumbers": showQuestionNumbers,
"startWithNewLine": startWithNewLine,
"visible": visible,
"visibleIf": visibleIf,
"width": width,
}
questions = flatten(questions)
return PanelModel(
name=name,
questions=questions,
**args,
**kwargs,
)


def dropdown(
name: str,
title: str | list[str] | None,
Expand Down

0 comments on commit 6c9c294

Please sign in to comment.