Skip to content

Commit d041bc9

Browse files
committed
param validation update
1 parent a413f03 commit d041bc9

1 file changed

Lines changed: 30 additions & 3 deletions

File tree

server/workers/api/src/apis/request_validators.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ class Meta:
3737
custom_title = fields.Str()
3838
exclude_date_filters = fields.Boolean()
3939
custom_clustering = fields.Str()
40-
academic_age_offset = fields.Int()
41-
enable_h_index = fields.Bool()
42-
enable_teaching_mentorship = fields.Bool()
40+
academic_age_offset = fields.Int(allow_none=True)
41+
enable_h_index = fields.Boolean(allow_none=True)
42+
enable_teaching_mentorship = fields.Boolean(allow_none=True)
4343

4444

4545
@pre_load
@@ -81,6 +81,33 @@ def lang_id_empty_fallback(self, in_data, **kwargs):
8181

8282
return in_data
8383

84+
@pre_load
85+
def fix_academic_age_offset(self, in_data, **kwargs):
86+
try:
87+
if "academic_age_offset" in in_data:
88+
in_data["academic_age_offset"] = int(in_data["academic_age_offset"])
89+
except (ValueError, TypeError):
90+
in_data["academic_age_offset"] = 0
91+
return in_data
92+
93+
@pre_load
94+
def fix_enable_h_index(self, in_data, **kwargs):
95+
try:
96+
if "enable_h_index" in in_data:
97+
in_data["enable_h_index"] = in_data["enable_h_index"].lower().capitalize() == "True"
98+
except Exception:
99+
pass
100+
return in_data
101+
102+
@pre_load
103+
def fix_enable_teaching_mentorship(self, in_data, **kwargs):
104+
try:
105+
if "enable_teaching_mentorship" in in_data:
106+
in_data["enable_teaching_mentorship"] = in_data["enable_teaching_mentorship"].lower().capitalize() == "True"
107+
except Exception:
108+
pass
109+
return in_data
110+
84111
@validates('from_')
85112
def is_not_in_future(self, date):
86113
if date > datetime.today().date():

0 commit comments

Comments
 (0)