changed validates signature

This commit is contained in:
Daniel Schick 2025-09-08 14:44:38 +02:00
parent 18ea45705c
commit 5d1b453fef

View File

@ -201,7 +201,7 @@ class Participant(Schema):
ports: List[int] = field(default_factory=list)
@validates("type")
def validate_type(self, value):
def validate_type(self, value, **kwargs):
# e.g., when an IntFlag has the values 1,2,4; the maximum valid value is 7
max_int = sum([int(val) for val in list(ParticipantType._value2member_map_.values())])
min_int = 0
@ -212,7 +212,7 @@ class Participant(Schema):
@validates("flags")
def validate_flags(self, value):
def validate_flags(self, value, **kwargs):
# e.g., when an IntFlag has the values 1,2,4; the maximum valid value is 7
max_int = sum([int(val) for val in list(ParticipantFlag._value2member_map_.values())])
min_int = 0
@ -281,7 +281,7 @@ class ShipcallSchema(Schema):
return data
@validates("type")
def validate_type(self, value):
def validate_type(self, value, **kwargs):
valid_shipcall_type = int(value) in [item.value for item in ShipcallType]
if not valid_shipcall_type:
@ -427,7 +427,7 @@ class TimesSchema(Schema):
modified = fields.DateTime(required=False, allow_none=True)
@validates("participant_type")
def validate_participant_type(self, value):
def validate_participant_type(self, value, **kwargs):
# #TODO: it may also make sense to block multi-assignments, whereas a value could be BSMD+AGENCY
# while the validation fails when one of those multi-assignments is BSMD, it passes in cases,
# such as AGENCY+PILOT
@ -440,56 +440,56 @@ class TimesSchema(Schema):
raise ValidationError({"participant_type":f"the participant_type must not be .BSMD"})
@validates("eta_berth")
def validate_eta_berth(self, value):
def validate_eta_berth(self, value, **kwargs):
# violation when time is not in the future, but also does not exceed a threshold for the 'reasonable' future
# when 'value' is 'None', a ValidationError is not issued.
valid_time = validate_time_is_in_not_too_distant_future(raise_validation_error=True, value=value, months=12)
return
@validates("etd_berth")
def validate_etd_berth(self, value):
def validate_etd_berth(self, value, **kwargs):
# violation when time is not in the future, but also does not exceed a threshold for the 'reasonable' future
# when 'value' is 'None', a ValidationError is not issued.
valid_time = validate_time_is_in_not_too_distant_future(raise_validation_error=True, value=value, months=12)
return
@validates("lock_time")
def validate_lock_time(self, value):
def validate_lock_time(self, value, **kwargs):
# violation when time is not in the future, but also does not exceed a threshold for the 'reasonable' future
# when 'value' is 'None', a ValidationError is not issued.
valid_time = validate_time_is_in_not_too_distant_future(raise_validation_error=True, value=value, months=12)
return
@validates("zone_entry")
def validate_zone_entry(self, value):
def validate_zone_entry(self, value, **kwargs):
# violation when time is not in the future, but also does not exceed a threshold for the 'reasonable' future
# when 'value' is 'None', a ValidationError is not issued.
valid_time = validate_time_is_in_not_too_distant_future(raise_validation_error=True, value=value, months=12)
return
@validates("operations_start")
def validate_operations_start(self, value):
def validate_operations_start(self, value, **kwargs):
# violation when time is not in the future, but also does not exceed a threshold for the 'reasonable' future
# when 'value' is 'None', a ValidationError is not issued.
valid_time = validate_time_is_in_not_too_distant_future(raise_validation_error=True, value=value, months=12)
return
@validates("operations_end")
def validate_operations_end(self, value):
def validate_operations_end(self, value, **kwargs):
# violation when time is not in the future, but also does not exceed a threshold for the 'reasonable' future
# when 'value' is 'None', a ValidationError is not issued.
valid_time = validate_time_is_in_not_too_distant_future(raise_validation_error=True, value=value, months=12)
return
@validates("eta_interval_end")
def validate_eta_interval_end(self, value):
def validate_eta_interval_end(self, value, **kwargs):
# violation when time is not in the future, but also does not exceed a threshold for the 'reasonable' future
# when 'value' is 'None', a ValidationError is not issued.
valid_time = validate_time_is_in_not_too_distant_future(raise_validation_error=True, value=value, months=12)
return
@validates("etd_interval_end")
def validate_etd_interval_end(self, value):
def validate_etd_interval_end(self, value, **kwargs):
# violation when time is not in the future, but also does not exceed a threshold for the 'reasonable' future
# when 'value' is 'None', a ValidationError is not issued.
valid_time = validate_time_is_in_not_too_distant_future(raise_validation_error=True, value=value, months=12)
@ -516,14 +516,14 @@ class UserSchema(Schema):
notify_on = fields.List(fields.Enum(NotificationType), required=False, allow_none=True)
@validates("user_phone")
def validate_user_phone(self, value):
def validate_user_phone(self, value, **kwargs):
if value is not None:
valid_characters = list(map(str,range(0,10)))+["+", " "]
if not all([v in valid_characters for v in value]):
raise ValidationError({"user_phone":f"one of the phone number values is not valid."})
@validates("user_email")
def validate_user_email(self, value):
def validate_user_email(self, value, **kwargs):
if value and not re.match(r"[^@]+@[^@]+\.[^@]+", value):
raise ValidationError({"user_email":f"invalid email address"})
@ -620,7 +620,7 @@ class ShipSchema(Schema):
deleted = fields.Bool(allow_none=True, required=False, load_default=False, dump_default=False)
@validates("name")
def validate_name(self, value):
def validate_name(self, value, **kwargs):
character_length = len(str(value))
if character_length<1:
raise ValidationError({"name":f"'name' argument should have at least one character"})
@ -632,7 +632,7 @@ class ShipSchema(Schema):
return
@validates("imo")
def validate_imo(self, value):
def validate_imo(self, value, **kwargs):
value = str(value).zfill(7) # 1 becomes '0000001' (7 characters). 12345678 becomes '12345678' (8 characters)
imo_length = len(value)
if imo_length != 7:
@ -640,7 +640,7 @@ class ShipSchema(Schema):
return
@validates("callsign")
def validate_callsign(self, value):
def validate_callsign(self, value, **kwargs):
if value is not None:
callsign_length = len(str(value))
if callsign_length>8: