python - Referencing a model class inside of a property in Google App Engine -


how reference model class inside of property validator?

my source code below. 1 of properties model class user. problem in line 4, keyword self given. goal pass user model class validator (it use search class objects validate login has unique value), don't know how reference class. self of course doesn't work.

class user(db.model):     (...)     login = db.stringproperty(         required=true,         validator=combine_validators(             validate_uniqueness_fun(self, "login", loginnotavailable),             validate_string_fun(                 login_min_length,                 login_max_length,                 login_valid_regex,                 logininvalidlength,                 logininvalidformat             )         )     )     (...) 

and functions used in property. validate_string_fun() not important, returns validator functon takes property value it's argument.

def combine_validators(*validators):     """     accepts number of validators (validating functions) combines     1 validator. constructed function runs each given validator     value.      """       return functools.partial(         _combine_validators,         validators_list=[v v in validators]     )  def _combine_validators(value, validators_list):     validator in validators_list:         validator(value)   def validate_uniqueness_fun(model, property_name, not_unique_exception):     """     arguments:     * model: subclass of google.appengine.ext.db.model     * property_name: string     * property_not_unique: sub-clas of propertynotunique      returns function given value validates it's uniqueness. if in     property_name of model class there value equal     given one, raises property_not_unique exception.      """     return functools.partial(         _validate_uniqueness,         model=model,         property_name=property_name,         not_unique_exception=not_unique_exception     )  def _validate_uniqueness(property_value, model, property_name, not_unique_exception):     query = model.all().filter(property_name, property_value)     if (query.get()):         raise not_unique_exception(property_value) 


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -