本文整理汇总了Python中django.db.DataError方法的典型用法代码示例。如果您正苦于以下问题:Python db.DataError方法的具体用法?Python db.DataError怎么用?Python db.DataError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.db
的用法示例。
在下文中一共展示了db.DataError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_register_data
# 需要导入模块: from django import db [as 别名]
# 或者: from django.db import DataError [as 别名]
def add_register_data(**kwargs):
"""
用户注册信息逻辑判断及落地
:param kwargs: dict
:return: ok or tips
"""
user_info = UserInfo.objects
try:
username = kwargs.pop('account')
password = kwargs.pop('password')
email = kwargs.pop('email')
if user_info.filter(username__exact=username).filter(status=1).count() > 0:
logger.debug('{username} 已被其他用户注册'.format(username=username))
return '该用户名已被注册,请更换用户名'
if user_info.filter(email__exact=email).filter(status=1).count() > 0:
logger.debug('{email} 昵称已被其他用户注册'.format(email=email))
return '邮箱已被其他用户注册,请更换邮箱'
user_info.create(username=username, password=password, email=email)
logger.info('新增用户:{user_info}'.format(user_info=user_info))
return 'ok'
except DataError:
logger.error('信息输入有误:{user_info}'.format(user_info=user_info))
return '字段长度超长,请重新编辑'
示例2: process_content
# 需要导入模块: from django import db [as 别名]
# 或者: from django.db import DataError [as 别名]
def process_content(self):
for content in self.pre_processed_content: # type: Reference
try:
# First save (some processing steps require ids)
content.full_clean() # Validate model
content.save()
self.call_processing_steps(content)
# Save again
content.save()
logger.debug('Completed: %s' % content)
self.doc_counter += 1
self.processed_content.append(content)
except (ValidationError, DataError, OperationalError, IntegrityError, ProcessingError) as e:
logger.error('Cannot process: %s; %s' % (content, e))
self.processing_errors.append(e)
self.doc_failed_counter += 1
示例3: process_content_item
# 需要导入模块: from django import db [as 别名]
# 或者: from django.db import DataError [as 别名]
def process_content_item(self, content: Case) -> Case:
try:
# First save (some processing steps require ids)
# content.full_clean() # Validate model
content.save()
self.call_processing_steps(content)
# Save again
content.save()
logger.debug('Completed: %s' % content)
self.doc_counter += 1
self.processed_content.append(content)
except (ValidationError, DataError, OperationalError, IntegrityError, ProcessingError) as e:
logger.error('Cannot process case: %s; %s' % (content, e))
self.processing_errors.append(e)
self.doc_failed_counter += 1
return content
示例4: process_content
# 需要导入模块: from django import db [as 别名]
# 或者: from django.db import DataError [as 别名]
def process_content(self):
for content in self.pre_processed_content: # type: Court
try:
# First save (some processing steps require ids)
content.full_clean() # Validate model
content.save()
self.call_processing_steps(content)
# Save again
content.save()
logger.debug('Completed: %s' % content)
self.doc_counter += 1
self.processed_content.append(content)
except (ValidationError, DataError, OperationalError, IntegrityError, ProcessingError) as e:
logger.error('Cannot process court: %s; %s' % (content, e))
self.processing_errors.append(e)
self.doc_failed_counter += 1
示例5: test_create_fails_if_name_too_long
# 需要导入模块: from django import db [as 别名]
# 或者: from django.db import DataError [as 别名]
def test_create_fails_if_name_too_long(self):
with self.assertRaises(DataError):
Group.objects.create(name='a' * 81)
示例6: test_fails_if_date_max_less_than_date_min
# 需要导入模块: from django import db [as 别名]
# 或者: from django.db import DataError [as 别名]
def test_fails_if_date_max_less_than_date_min(self):
now = timezone.now()
qs = Activity.objects.filter(place=self.place)
with self.assertRaises(DataError):
list(ActivitiesFilter(data={
'date_min': now,
'date_max': now - timedelta(hours=1),
}, queryset=qs).qs)
示例7: test_create_fails_if_comment_too_long
# 需要导入模块: from django import db [as 别名]
# 或者: from django.db import DataError [as 别名]
def test_create_fails_if_comment_too_long(self):
with self.assertRaises(DataError):
Feedback.objects.create(comment='a' * 100001, about=self.activity, given_by=self.user, weight=1)
示例8: test_create_fails_if_name_too_long
# 需要导入模块: from django import db [as 别名]
# 或者: from django.db import DataError [as 别名]
def test_create_fails_if_name_too_long(self):
with self.assertRaises(DataError):
too_long = self.exampleuser
too_long['display_name'] = 'a' * 81
get_user_model().objects.create_user(**too_long)
示例9: test_create_fails_if_name_too_long
# 需要导入模块: from django import db [as 别名]
# 或者: from django.db import DataError [as 别名]
def test_create_fails_if_name_too_long(self):
with self.assertRaises(DataError):
Place.objects.create(name='a' * 81, group=self.group)
示例10: from_bare
# 需要导入模块: from django import db [as 别名]
# 或者: from django.db import DataError [as 别名]
def from_bare(cls, bare_obj):
"""
Saves a paper to the database if it is not already present.
The clustering algorithm is run to decide what authors should be
attributed to the paper.
:returns: the :class:`Paper` instance created from the bare paper supplied.
"""
paper = bare_obj
try:
# Look up the fingerprint
fp = paper.fingerprint
matches = Paper.find_by_fingerprint(fp)
p = None
if matches: # We have found a paper matching the fingerprint
p = matches[0]
if paper.visible and not p.visible:
p.visible = True
p.update_authors(
paper.authors,
save_now=False)
for record in paper.oairecords:
p.add_oairecord(record)
p.update_availability() # in Paper, this saves to the db
else: # Otherwise we create a new paper
# this already saves the paper in the db
p = super(Paper, cls).from_bare(paper)
return p
except DataError as e:
raise ValueError(
'Invalid paper, does not fit in the database schema:\n'+str(e))
### Other methods, specific to this non-bare subclass ###
示例11: add_project_data
# 需要导入模块: from django import db [as 别名]
# 或者: from django.db import DataError [as 别名]
def add_project_data(type, **kwargs):
"""
项目信息落地 新建时必须默认添加debugtalk.py
:param type: true: 新增, false: 更新
:param kwargs: dict
:return: ok or tips
"""
project_opt = ProjectInfo.objects
project_name = kwargs.get('project_name')
if type:
if project_opt.get_pro_name(project_name) < 1:
try:
project_opt.insert_project(**kwargs)
belong_project = project_opt.get(project_name=project_name)
DebugTalk.objects.create(belong_project=belong_project, debugtalk='# debugtalk.py')
except DataError:
return '项目信息过长'
except Exception:
logging.error('项目添加异常:{kwargs}'.format(kwargs=kwargs))
return '添加失败,请重试'
logger.info('项目添加成功:{kwargs}'.format(kwargs=kwargs))
else:
return '该项目已存在,请重新编辑'
else:
if project_name != project_opt.get_pro_name('', type=False, id=kwargs.get(
'index')) and project_opt.get_pro_name(project_name) > 0:
return '该项目已存在, 请重新命名'
try:
project_opt.update_project(kwargs.pop('index'), **kwargs) # testcaseinfo的belong_project也得更新,这个字段设计的有点坑了
except DataError:
return '项目信息过长'
except Exception:
logging.error('更新失败:{kwargs}'.format(kwargs=kwargs))
return '更新失败,请重试'
logger.info('项目更新成功:{kwargs}'.format(kwargs=kwargs))
return 'ok'
示例12: add_case_data
# 需要导入模块: from django import db [as 别名]
# 或者: from django.db import DataError [as 别名]
def add_case_data(type, **kwargs):
"""
用例信息落地
:param type: boolean: true: 添加新用例, false: 更新用例
:param kwargs: dict
:return: ok or tips
"""
case_info = kwargs.get('test').get('case_info')
case_opt = TestCaseInfo.objects
name = kwargs.get('test').get('name')
module = case_info.get('module')
project = case_info.get('project')
belong_module = ModuleInfo.objects.get_module_name(module, type=False)
config = case_info.get('config', '')
if config != '':
case_info.get('include')[0] = eval(config)
try:
if type:
if case_opt.get_case_name(name, module, project) < 1:
case_opt.insert_case(belong_module, **kwargs)
logger.info('{name}用例添加成功: {kwargs}'.format(name=name, kwargs=kwargs))
else:
return '用例或配置已存在,请重新编辑'
else:
index = case_info.get('test_index')
if name != case_opt.get_case_by_id(index, type=False) \
and case_opt.get_case_name(name, module, project) > 0:
return '用例或配置已在该模块中存在,请重新命名'
case_opt.update_case(belong_module, **kwargs)
logger.info('{name}用例更新成功: {kwargs}'.format(name=name, kwargs=kwargs))
except DataError:
logger.error('用例信息:{kwargs}过长!!'.format(kwargs=kwargs))
return '字段长度超长,请重新编辑'
return 'ok'
示例13: add_config_data
# 需要导入模块: from django import db [as 别名]
# 或者: from django.db import DataError [as 别名]
def add_config_data(type, **kwargs):
"""
配置信息落地
:param type: boolean: true: 添加新配置, fasle: 更新配置
:param kwargs: dict
:return: ok or tips
"""
case_opt = TestCaseInfo.objects
config_info = kwargs.get('config').get('config_info')
name = kwargs.get('config').get('name')
module = config_info.get('module')
project = config_info.get('project')
belong_module = ModuleInfo.objects.get_module_name(module, type=False)
try:
if type:
if case_opt.get_case_name(name, module, project) < 1:
case_opt.insert_config(belong_module, **kwargs)
logger.info('{name}配置添加成功: {kwargs}'.format(name=name, kwargs=kwargs))
else:
return '用例或配置已存在,请重新编辑'
else:
index = config_info.get('test_index')
if name != case_opt.get_case_by_id(index, type=False) \
and case_opt.get_case_name(name, module, project) > 0:
return '用例或配置已在该模块中存在,请重新命名'
case_opt.update_config(belong_module, **kwargs)
logger.info('{name}配置更新成功: {kwargs}'.format(name=name, kwargs=kwargs))
except DataError:
logger.error('{name}配置信息过长:{kwargs}'.format(name=name, kwargs=kwargs))
return '字段长度超长,请重新编辑'
return 'ok'
示例14: qs_exists
# 需要导入模块: from django import db [as 别名]
# 或者: from django.db import DataError [as 别名]
def qs_exists(queryset):
try:
return queryset.exists()
except (TypeError, ValueError, DataError):
return False
示例15: qs_filter
# 需要导入模块: from django import db [as 别名]
# 或者: from django.db import DataError [as 别名]
def qs_filter(queryset, **kwargs):
try:
return queryset.filter(**kwargs)
except (TypeError, ValueError, DataError):
return queryset.none()