def __init__(self, alias=None, required=False, default=None): def validate(x): try: return socket.inet_aton( x ) except socket.error: return False Parameter.__init__(self, alias=alias, required=required, default=default, validate=validate)
def __init__(self, alias=None, required=False, default=None): def validate(x): try: return EmailField().clean(x) except: return False Parameter.__init__(self, alias=alias, required=required, default=default, validate=validate)
def __init__(self, alias=None, required=False, default=None, min_value=None, max_value=None): if max_value!=None and min_value!=None: validate = lambda x: x>=min_value and x<= max_value elif max_value!=None: validate = lambda x: x<=max_value elif min_value!=None: validate = lambda x: x>=min_value else: validate = None Parameter.__init__(self, alias=alias, required=required, default=default, validate=validate)
def __init__(self, alias=None, required=False, default=None, default_date=None, validate=None, formats=['%Y-%m-%d %H:%M:%S', '%Y-%m-%d %H:%M', '%Y-%m-%d'], time_formats=['%H:%M:%S', '%H:%M'] ): iter_ = lambda x: x if is_iter(x) else [x,] self.formats = {'datetime': iter_( formats )} if default_date!=None: self.default_date = default_date self.formats['time'] = iter_( time_formats ) if default == None: default = self.__default_date_only else: default = self.__default_with_default_date( default ) Parameter.__init__(self, alias=alias, required=required, default=default, validate=validate)
def __init__(self, regex, alias=None, required=False, default=None): validate = lambda x: re.findall(r'^%s$'%regex, x) Parameter.__init__(self, alias=alias, required=required, default=default, validate=validate)
def __init__(self, alias=None, required=False, default=None, max_length=None): validate = None if not max_length else (lambda x: len(x) <= max_length) Parameter.__init__(self, alias=alias, required=required, default=default, validate=validate)
def __init__(self, alias=None, required=False, default=None, validate=None): Parameter.__init__(self, alias=alias, required=required, default=default, validate=validate)
def __init__(self, model, model_attribute='pk', alias=None, required=False, default=None): self.model = model.objects self.model_attribute = model_attribute Parameter.__init__(self, alias=alias, required=required, default=default)#, validate=validate)
def __init__(self, alias=None, required=False, default=None, validate=None, latitude_first=False): self.latitude_first = latitude_first Parameter.__init__(self, alias=alias, required=required, default=default, validate=validate)
def __init__(self, choices, alias=None, required=False, default=None, sep=','): self.sep = sep validate = lambda x: all([i in choices for i in x]) Parameter.__init__(self, alias=alias, required=required, default=default, validate=validate)
def __init__(self, choices, alias=None, required=False, default=None): validate = lambda x: x in choices Parameter.__init__(self, alias=alias, required=required, default=default, validate=validate)