Created
September 13, 2011 17:56
-
-
Save alecmunro/1214513 to your computer and use it in GitHub Desktop.
Strategy Pattern example
This file contains 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
def not_empty_string(value): | |
assert(len(value) > 0) | |
def valid_email(value): | |
assert("@" in value) | |
def greater_than_zero(value): | |
assert(int(value) > 0) | |
FIELD_VALIDATORS = { | |
"name": not_empty_string, | |
"email": valid_email, | |
"age": greater_than_zero | |
} | |
def validate_form(form): | |
for field in form.fields: | |
FIELD_VALIDATORS[field.name](field.value) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment