Skip to content

Commit

Permalink
add translation wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
erikvw committed Apr 17, 2024
1 parent dfa5a67 commit 25af2d9
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions edc_model/validators/duration.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
from django.core.validators import RegexValidator
from django.utils.translation import gettext as _

from ..utils import dh_pattern, ymd_pattern

# expect 1h20m, 11h5m, etc
dh_validator = RegexValidator(
dh_pattern,
message=(
message=_(
"Invalid format. Expected combinations of days and hours (dh): "
"Something like 3d2h, 7d, 12h, etc. No spaces allowed."
),
)

hm_validator = RegexValidator(
r"^([0-9]{1,3}h([0-5]?[0-9]m)?)$",
message="Invalid format. Expected something like 1h20m, 11h5m, etc",
message=_("Invalid format. Expected something like 1h20m, 11h5m, etc. No spaces allowed."),
)

ymd_validator = RegexValidator(
ymd_pattern,
message=(
message=_(
"Invalid format. Expected combinations of years and months (ym): "
"4y, 3y5m, 1y0m, 6m or days (d): 7d, 0d. No spaces allowed."
),
)

hm_validator2 = RegexValidator(
r"^([0-9]{1,3}:[0-5][0-9])$", message="Enter a valid time in hour:minutes format"
r"^([0-9]{1,3}:[0-5][0-9])$",
message=_("Enter a valid time in hour:minutes format. No spaces allowed."),
)

0 comments on commit 25af2d9

Please sign in to comment.