Пример #1
0
    def populate(self, data):
        if not isinstance(data, dict):
            raise SchemaTypeError()

        for k, t in self.structure.iteritems():
            # from form which all val are unicode
            if k in data and type(data[k]) is unicode and data[k]:
                if t is unicode:
                    self[k] = force_unicode(data[k])
                    if k in self.sanitized_fields:
                        self[k] = sanitize(self[k])
                elif t is list:
                    self[k] = listify(data[k], ',')
                elif t is datetime.datetime:
                    self[k] = datetime.datetime.strptime(data[k], '%d/%m/%Y')
                elif t is bool:
                    if data[k] == 'False':
                        self[k] = False
                    else:
                        self[k] = bool(int(data[k]))
                elif t is int:
                    self[k] = int(re.sub('[.,]*', '', data[k]))
                else:
                    self[k] = data[k]
            elif k in data:
                self[k] = data[k]
            elif t is bool:
                self[k] = False
                
        self.update_html(data)
Пример #2
0
    def populate(self, data):
        if not isinstance(data, dict):
            raise SchemaTypeError()

        for k, t in self.structure.iteritems():
            # from form which all val are unicode
            if k in data and type(data[k]) is unicode and data[k]:
                if t is unicode:
                    self[k] = force_unicode(data[k])
                    if k in self.sanitized_fields:
                        self[k] = sanitize(self[k])
                elif t is list:
                    self[k] = listify(data[k], ',')
                elif t is datetime.datetime:
                    self[k] = datetime.datetime.strptime(data[k], '%d/%m/%Y')
                elif t is bool:
                    if data[k] == 'False':
                        self[k] = False
                    else:
                        self[k] = bool(int(data[k]))
                elif t is int:
                    self[k] = int(re.sub('[.,]*', '', data[k]))
                else:
                    self[k] = data[k]
            elif k in data:
                self[k] = data[k]
            elif t is bool:
                self[k] = False

        self.update_html(data)
Пример #3
0
 def valid(self, value):
     if not value: return True
     chunks = listify(value, self.sep)
     return bool(len(chunks))