本文整理汇总了Python中validator.Validator.is_valid方法的典型用法代码示例。如果您正苦于以下问题:Python Validator.is_valid方法的具体用法?Python Validator.is_valid怎么用?Python Validator.is_valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类validator.Validator
的用法示例。
在下文中一共展示了Validator.is_valid方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_data
# 需要导入模块: from validator import Validator [as 别名]
# 或者: from validator.Validator import is_valid [as 别名]
def update_data(self, section_number, id_variable, id_variable_value,
body):
if id_variable_value == "None":
data = self.insert_data(section_number, id_variable, body)
return data
if self.models:
json_dict = simplejson.JSONDecoder().decode(body)
orig_json_dict = json_dict
json_dict = self.pre_process_keys(json_dict)
for k in json_dict.keys():
if k in self.db_mapping.keys():
json_dict[self.db_mapping[k]] = json_dict[k]
json_dict.pop(k)
validator_form = self.model_form_mapping[int(section_number)](json_dict)
if validator_form.is_valid():
self.model_mapping[int(section_number)].objects.filter(pk=id_variable_value).update(**json_dict)
data = model_to_dict(self.model_mapping[int(section_number)].objects.get(id=id_variable_value))
else:
errors = {}
for field in validator_form:
errors[field.label] = field.errors.as_text()
data = orig_json_dict
data['errors'] = errors
else:
json_dict = simplejson.JSONDecoder().decode(body)
validator = Validator(self.validator, json_dict)
if validator.is_valid():
for k in json_dict.keys():
if k in self.db_mapping.keys():
json_dict[self.db_mapping[k]] = json_dict[k]
json_dict.pop(k)
queryset = QuerySet(table_name=self.get_table_name(section_number))
queryset.update(json_dict, id_variable_value)
data = queryset.data
else:
for k in json_dict.keys():
if k in self.db_mapping.keys():
json_dict[self.db_mapping[k]] = json_dict[k]
json_dict.pop(k)
data = json_dict
data['errors'] = validator.errors
return data
示例2: insert_data
# 需要导入模块: from validator import Validator [as 别名]
# 或者: from validator.Validator import is_valid [as 别名]
def insert_data(self, section_number, id_variable, body):
json_dict = simplejson.JSONDecoder().decode(body)
if self.models:
json_dict = self.pre_process_keys(json_dict)
validator = self.model_form_mapping[int(section_number)](json_dict)
if validator.is_valid():
for k in json_dict.keys():
if k in self.db_mapping.keys():
json_dict[self.db_mapping[k]] = json_dict[k]
json_dict.pop(k)
if 'id' in json_dict.keys():
json_dict.pop('id')
json_dict = self.post_process_keys(json_dict)
model = self.model_mapping[int(section_number)].objects.create(**json_dict)
data = model_to_dict(model)
else:
errors = {}
for field in validator:
errors[field.label] = field.errors
data = json_dict
data['errors'] = 'errors'
else:
if 'search' in json_dict.keys():
data = self.search(json_dict['search'], section_number)
else:
validator = Validator(self.validator, json_dict)
print json_dict, self.validator
if validator.is_valid():
for k in json_dict.keys():
if k in self.db_mapping.keys():
json_dict[self.db_mapping[k]] = json_dict[k]
json_dict.pop(k)
queryset = QuerySet(table_name=self.get_table_name(section_number))
data = queryset.create(json_dict)
else:
for k in json_dict.keys():
if k in self.db_mapping.keys():
json_dict[self.db_mapping[k]] = json_dict[k]
json_dict.pop(k)
data = json_dict
data['errors'] = validator.errors
return data
示例3: len
# 需要导入模块: from validator import Validator [as 别名]
# 或者: from validator.Validator import is_valid [as 别名]
while True:
buf = ser.readline()
arr = buf.split(",")
if len(arr) > 3:
continue
try:
temperature = float(arr[0])
humidity = float(arr[1])
luminosity = float(arr[2])
validator = Validator(temperature, humidity, luminosity)
if (validator.is_valid()):
prev = [temperature, humidity, luminosity]
else:
if len(prev) > 0:
arr = prev
else:
continue
print ", ".join(str(x) for x in arr)
db = DBWriter(arr[0], arr[1], arr[2])
db.write()
log = LogWriter(arr[0], arr[1], arr[2])
log.write()
except IndexError: