當前位置: 首頁>>代碼示例>>Python>>正文


Python db.DataError方法代碼示例

本文整理匯總了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 '字段長度超長,請重新編輯' 
開發者ID:httprunner,項目名稱:HttpRunnerManager,代碼行數:26,代碼來源:operation.py

示例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 
開發者ID:openlegaldata,項目名稱:oldp,代碼行數:23,代碼來源:reference_processor.py

示例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 
開發者ID:openlegaldata,項目名稱:oldp,代碼行數:24,代碼來源:case_processor.py

示例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 
開發者ID:openlegaldata,項目名稱:oldp,代碼行數:23,代碼來源:court_processor.py

示例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) 
開發者ID:yunity,項目名稱:karrot-backend,代碼行數:5,代碼來源:test_model.py

示例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) 
開發者ID:yunity,項目名稱:karrot-backend,代碼行數:10,代碼來源:test_filters.py

示例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) 
開發者ID:yunity,項目名稱:karrot-backend,代碼行數:5,代碼來源:test_models.py

示例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) 
開發者ID:yunity,項目名稱:karrot-backend,代碼行數:7,代碼來源:test_model.py

示例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) 
開發者ID:yunity,項目名稱:karrot-backend,代碼行數:5,代碼來源:test_models.py

示例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 ### 
開發者ID:dissemin,項目名稱:dissemin,代碼行數:38,代碼來源:models.py

示例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' 
開發者ID:httprunner,項目名稱:HttpRunnerManager,代碼行數:39,代碼來源:operation.py

示例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' 
開發者ID:httprunner,項目名稱:HttpRunnerManager,代碼行數:39,代碼來源:operation.py

示例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' 
開發者ID:httprunner,項目名稱:HttpRunnerManager,代碼行數:34,代碼來源:operation.py

示例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 
開發者ID:BeanWei,項目名稱:Dailyfresh-B2C,代碼行數:7,代碼來源:validators.py

示例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() 
開發者ID:BeanWei,項目名稱:Dailyfresh-B2C,代碼行數:7,代碼來源:validators.py


注:本文中的django.db.DataError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。