Skip to content

Commit

Permalink
feat(float): add step configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
velrest committed Jan 20, 2025
1 parent 361df5f commit f885a38
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions caluma/caluma_form/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,14 @@ def color(self):
def color(self, value):
self.configuration["color"] = value

@property
def step(self):
return self.configuration.get("step") or 0.001

@step.setter
def step(self, value):
self.configuration["step"] = value

@property
def validate_on_enter(self):
return self.configuration.get("validate_on_enter")
Expand Down
1 change: 1 addition & 0 deletions caluma/caluma_form/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ class Meta:
class FloatQuestion(QuestionQuerysetMixin, FormDjangoObjectType):
min_value = graphene.Float()
max_value = graphene.Float()
step = graphene.Float()
placeholder = graphene.String()
hint_text = graphene.String()
default_answer = graphene.Field("caluma.caluma_form.schema.FloatAnswer")
Expand Down
9 changes: 9 additions & 0 deletions caluma/caluma_form/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ class Meta(SaveQuestionSerializer.Meta):
class SaveFloatQuestionSerializer(SaveQuestionSerializer):
min_value = FloatField(required=False, allow_null=True)
max_value = FloatField(required=False, allow_null=True)
step = FloatField(required=False, allow_null=True)

def validate(self, data):
min_value = (
Expand All @@ -351,13 +352,21 @@ def validate(self, data):
f"max_value {max_value} is smaller than {min_value}"
)

step = data.get("step")
step = (
step
if step is not None
else 0.001
)

data["type"] = models.Question.TYPE_FLOAT
return super().validate(data)

class Meta(SaveQuestionSerializer.Meta):
fields = SaveQuestionSerializer.Meta.fields + [
"min_value",
"max_value",
"step",
"placeholder",
"hint_text",
]
Expand Down
1 change: 1 addition & 0 deletions caluma/caluma_form/tests/test_question.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def test_query_all_questions(
... on FloatQuestion {
floatMinValue: minValue
floatMaxValue: maxValue
floatStep: step
placeholder
hintText
}
Expand Down

0 comments on commit f885a38

Please sign in to comment.