Skip to content

Commit

Permalink
added message to validate_not_zero method
Browse files Browse the repository at this point in the history
  • Loading branch information
DJ Howard committed Sep 5, 2024
1 parent 4a15dce commit 3386452
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion nautobot_floor_plan/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class FloorPlan(PrimaryModel):
validators=[MinValueValidator(0)], default=1, help_text="User defined starting value for grid labeling"
)
x_axis_step = models.IntegerField(
validators=[validate_not_zero], default=1,help_text="Positive or negative integer that will be used to step labeling.",
validators=[validate_not_zero], default=1, help_text="Positive or negative integer that will be used to step labeling.",
)
y_axis_step = models.IntegerField(
validators=[validate_not_zero], default=1, help_text="Positive or negative integer that will be used to step labeling."
Expand Down
7 changes: 6 additions & 1 deletion nautobot_floor_plan/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Utilities module."""

from django.core.exceptions import ValidationError
from django.utils.translation import gettext_lazy as _


def grid_number_to_letter(number):
Expand All @@ -27,4 +28,8 @@ def grid_letter_to_number(letter):
def validate_not_zero(value):
"""Prevent the usage of 0 as a value in the step form field or model attribute."""
if value == 0:
raise ValidationError(("Value must be a positive or negative Integer not equal to zero"))
raise ValidationError(
_("%(value)s is not a positive or negative Integer not equal to zero"),
params={"value": value},
)
validate_not_zero.message = "Must be a positive or negative Integer not equal to zero."

0 comments on commit 3386452

Please sign in to comment.