Last active
May 12, 2018 18:52
-
-
Save Marlysson/e1bfc8d19dfa1f4ec56c03ed9df2e3d5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Validação field a field | |
def is_valid(self,field): | |
if field is None | |
raise Exception | |
return field | |
def validate_name(self,name): | |
return is_valid(name) | |
def validate_release_date(self,release_date): | |
return is_valid(release_date) | |
.... Para os outros fields | |
# Validação a nível objeto | |
# Usando vários ifs | |
def validate(self,data): | |
if data.get('name') is None: | |
raise Exception | |
else if data.get('release_date') is None: | |
raise Exception | |
...... | |
return data | |
# Não usando vários ifs.. | |
def validate(self,data): | |
if all(data.values()): | |
raise Exception | |
return data | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment