diff options
author | makkalot <makkalot@gmail.com> | 2008-06-19 23:09:10 +0300 |
---|---|---|
committer | makkalot <makkalot@gmail.com> | 2008-06-19 23:09:10 +0300 |
commit | 4f878c5c6c9e25e18d84f53abda1079837f333be (patch) | |
tree | ce1c29763695cec5bf301824d78cbd5443149208 /funcweb/funcweb | |
parent | 17ea6e4c8c72599ea9cf370c9d21a7e4480a23c0 (diff) | |
download | func-4f878c5c6c9e25e18d84f53abda1079837f333be.tar.gz func-4f878c5c6c9e25e18d84f53abda1079837f333be.tar.xz func-4f878c5c6c9e25e18d84f53abda1079837f333be.zip |
add a beautiful string validator here
Diffstat (limited to 'funcweb/funcweb')
-rw-r--r-- | funcweb/funcweb/widget_validation.py | 65 |
1 files changed, 53 insertions, 12 deletions
diff --git a/funcweb/funcweb/widget_validation.py b/funcweb/funcweb/widget_validation.py index 39bad1c..6a1c010 100644 --- a/funcweb/funcweb/widget_validation.py +++ b/funcweb/funcweb/widget_validation.py @@ -15,7 +15,7 @@ class WidgetSchemaFactory(object): """ self.method_argument_dict = method_argument_dict - self.validator_list = [] #the validator that will create final schema + self.validator_list = {} #the validator that will create final schema def _add_validators(self): """ @@ -23,38 +23,72 @@ class WidgetSchemaFactory(object): and according to their types it sends the process to more specialized validator adders """ - pass + + for argument_name,argument_values in self.method_argument_dict.iteritems(): + #some lazy stuff :) + #for ex : _add_int_validator(some_arg) + getattr(self,"_add_%s_validator"%(argument_values['type']))(argument_name) - def _add_int_validator(self): + def _add_int_validator(self,argument_name): """ Gets the options of the int type and adds a new validator to validator_list """ pass - - def _add_string_validator(self): + + def _add_string_validator(self,argument_name): """ Gets the options of the string type and adds a new validator to validator_list """ - pass - def _add_float_validator(self): + string_data_set={} + str_validator_list =[] + + if self.method_argument_dict[argument_name].has_key('optional'): + if self.method_argument_dict[argument_name]['optional']: + string_data_set['not_empty']=False + else: + string_data_set['not_empty']=True + + if self.method_argument_dict[argument_name].has_key('min_length'): + string_data_set['min']=self.method_argument_dict[argument_name]['min_length'] + if self.method_argument_dict[argument_name].has_key('max_length'): + string_data_set['max']=self.method_argument_dict[argument_name]['max_length'] + if self.method_argument_dict[argument_name].has_key('validator'): + str_validator_list.append(getattr(validators,'Regex')(self.method_argument_dict[argument_name]['validator'])) + + #if we have set a string_data_set + if string_data_set: + str_validator_list.append(getattr(validators,'String')(**string_data_set)) + + #if true it should be a validator.All thing + if len(str_validator_list)>1: + self.validator_list[argument_name]=getattr(validators,'All')(*str_validator_list) + elif str_validator_list: + self.validator_list[argument_name]=str_validator_list[0] + else: #if there is no option + self.validator_list[argument_name]=getattr(validators,'String')() + + + + + def _add_float_validator(self,argument_name): """ Gets the options of the float type and adds a new validator to validator_list """ pass - def _add_list_validator(self): - """ + def _add_list_validator(self,argument_name): + """ Gets the options of the list type and adds a new validator to validator_list """ pass - def _add_hash_validator(self): - """ + def _add_hash_validator(self,argument_name): + """ Gets the options of the hash type and adds a new validator to validator_list """ @@ -65,7 +99,14 @@ class WidgetSchemaFactory(object): """ Get the final validator schema """ - pass + final_schema = validators.Schema() + if not self.validator_list: + self._add_validators() + + for vd_name,vd in self.validator_list.iteritems(): + setattr(final_schema,vd_name,vd) + + return final_schema |