I am trying to validate my data which i am posting through post request and i want to check if the data i proper or not and with that i want to do type casting and manipulate the data.
I have tried to manipulate the data but its not working and i cant understand what is wrong as i am new in flask so i would like to learn.
def check_name(self, obj):
if not obj.first_name:
return False
else:
return True
@pre_load
def process_email_address(self, in_data):
in_data['email_address'] = in_data['email_address'].upper().strip()
return in_data
class InfoSchema(Schema):
# first_name = fields.Function(lambda obj:
obj.first_name.lower().strip() if obj.first_name else False)
# first_name = fields.Method(check_name)
first_name = fields.Str(required=True)
username = fields.String(required=True)
last_name = fields.String(required=True)
email_address = fields.String(required=True)
phone_number = fields.String(required=True)
password = fields.String(required=True)
pincode = fields.String(required=True)
city_id = fields.String(required=True)
class DataSchema(Schema):
info = fields.Nested(InfoSchema)
auth_token = fields.Nested(AuthTokenSchema)
class UserAuthSchema(Schema):
meta = fields.Nested(MetaSchema)
data = fields.Nested(DataSchema)
# @validates('age')
# def validate_age(self, data):
# if data < 14:
# raise ValidationError('Too young!')
i want to check if the data is present and its not empty and also remove the spaces from it and and the most important i want to check if the data is in integer and if it is not then convert the string to integer like for the field "pincode" if possible