more validation input fixes
This commit is contained in:
parent
e911da20ef
commit
f1e1355986
@ -365,6 +365,8 @@ class InputValidationShipcall():
|
|||||||
"""
|
"""
|
||||||
if (eta is None) and (etd is None):
|
if (eta is None) and (etd is None):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
time_in_a_year = time_now.replace(time_now.year + 1)
|
||||||
|
|
||||||
if type_ is None:
|
if type_ is None:
|
||||||
raise ValidationError({"type":f"when providing 'eta' or 'etd', one must provide the type of the shipcall, so the datetimes can be verified."})
|
raise ValidationError({"type":f"when providing 'eta' or 'etd', one must provide the type of the shipcall, so the datetimes can be verified."})
|
||||||
@ -383,6 +385,8 @@ class InputValidationShipcall():
|
|||||||
raise ValidationError({"eta":f"'eta' must be in the future. Incorrect datetime provided. Current Time: {time_now}. ETA: {eta}."})
|
raise ValidationError({"eta":f"'eta' must be in the future. Incorrect datetime provided. Current Time: {time_now}. ETA: {eta}."})
|
||||||
if etd is not None:
|
if etd is not None:
|
||||||
raise ValidationError({"etd":f"'etd' should not be set when the shipcall type is 'arrival'."})
|
raise ValidationError({"etd":f"'etd' should not be set when the shipcall type is 'arrival'."})
|
||||||
|
if eta > time_in_a_year:
|
||||||
|
raise ValidationError({"eta":f"'eta' is more than a year in the future. ETA: {eta}."})
|
||||||
|
|
||||||
elif int(type_)==int(ShipcallType.departure):
|
elif int(type_)==int(ShipcallType.departure):
|
||||||
if etd is None: # null values -> no violation
|
if etd is None: # null values -> no violation
|
||||||
@ -390,9 +394,10 @@ class InputValidationShipcall():
|
|||||||
|
|
||||||
if not etd > time_now:
|
if not etd > time_now:
|
||||||
raise ValidationError({"etd":f"'etd' must be in the future. Incorrect datetime provided. Current Time: {time_now}. ETD: {etd}."})
|
raise ValidationError({"etd":f"'etd' must be in the future. Incorrect datetime provided. Current Time: {time_now}. ETD: {etd}."})
|
||||||
|
|
||||||
if eta is not None:
|
if eta is not None:
|
||||||
raise ValidationError({"eta":f"'eta' should not be set when the shipcall type is 'departure'."})
|
raise ValidationError({"eta":f"'eta' should not be set when the shipcall type is 'departure'."})
|
||||||
|
if etd > time_in_a_year:
|
||||||
|
raise ValidationError({"etd":f"'etd' is more than a year in the future. ETD: {etd}."})
|
||||||
|
|
||||||
elif int(type_)==int(ShipcallType.shifting):
|
elif int(type_)==int(ShipcallType.shifting):
|
||||||
if (eta is None) and (etd is None): # null values -> no violation
|
if (eta is None) and (etd is None): # null values -> no violation
|
||||||
@ -410,17 +415,29 @@ class InputValidationShipcall():
|
|||||||
|
|
||||||
if (eta is not None and etd is None) or (eta is None and etd is not None):
|
if (eta is not None and etd is None) or (eta is None and etd is not None):
|
||||||
raise ValidationError({"eta_or_etd":f"'eta' and 'etd' must both be provided when the shipcall type is 'shifting'."})
|
raise ValidationError({"eta_or_etd":f"'eta' and 'etd' must both be provided when the shipcall type is 'shifting'."})
|
||||||
|
if eta > time_in_a_year:
|
||||||
|
raise ValidationError({"eta":f"'eta' is more than a year in the future. ETA: {eta}."})
|
||||||
|
if etd > time_in_a_year:
|
||||||
|
raise ValidationError({"etd":f"'etd' is more than a year in the future. ETD: {etd}."})
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def check_tidal_window_in_future(type_, time_now, tidal_window_from, tidal_window_to):
|
def check_tidal_window_in_future(type_, time_now, tidal_window_from, tidal_window_to):
|
||||||
|
|
||||||
|
time_in_a_year = time_now.replace(time_now.year + 1)
|
||||||
|
|
||||||
if tidal_window_to is not None:
|
if tidal_window_to is not None:
|
||||||
if not tidal_window_to >= time_now:
|
if not tidal_window_to >= time_now:
|
||||||
raise ValidationError({"tidal_window_to":f"'tidal_window_to' must be in the future. Incorrect datetime provided."})
|
raise ValidationError({"tidal_window_to":f"'tidal_window_to' must be in the future. Incorrect datetime provided."})
|
||||||
|
if tidal_window_to > time_in_a_year:
|
||||||
|
raise ValidationError({"tidal_window_to":f"'tidal_window_to' is more than a year in the future. Found: {tidal_window_to}."})
|
||||||
|
|
||||||
if tidal_window_from is not None:
|
if tidal_window_from is not None:
|
||||||
if not tidal_window_from >= time_now:
|
if not tidal_window_from >= time_now:
|
||||||
raise ValidationError({"tidal_window_from":f"'tidal_window_from' must be in the future. Incorrect datetime provided."})
|
raise ValidationError({"tidal_window_from":f"'tidal_window_from' must be in the future. Incorrect datetime provided."})
|
||||||
|
if tidal_window_from > time_in_a_year:
|
||||||
|
raise ValidationError({"tidal_window_from":f"'tidal_window_from' is more than a year in the future. Found: {tidal_window_from}."})
|
||||||
|
|
||||||
if (tidal_window_to is not None) and (tidal_window_from is not None):
|
if (tidal_window_to is not None) and (tidal_window_from is not None):
|
||||||
if tidal_window_to < tidal_window_from:
|
if tidal_window_to < tidal_window_from:
|
||||||
|
|||||||
@ -124,7 +124,8 @@ class InputValidationTimes():
|
|||||||
InputValidationTimes.check_if_entry_is_already_deleted(times_id)
|
InputValidationTimes.check_if_entry_is_already_deleted(times_id)
|
||||||
|
|
||||||
# 2.) Only users of the same participant_id, which the times dataset refers to, can delete the entry
|
# 2.) Only users of the same participant_id, which the times dataset refers to, can delete the entry
|
||||||
InputValidationTimes.check_user_belongs_to_same_group_as_dataset_determines(user_data, loadedModel=None, times_id=times_id)
|
if not check_if_user_is_bsmd_type(user_data):
|
||||||
|
InputValidationTimes.check_user_belongs_to_same_group_as_dataset_determines(user_data, loadedModel=None, times_id=times_id)
|
||||||
return
|
return
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user