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


Python transaction.set_rollback方法代碼示例

本文整理匯總了Python中django.db.transaction.set_rollback方法的典型用法代碼示例。如果您正苦於以下問題:Python transaction.set_rollback方法的具體用法?Python transaction.set_rollback怎麽用?Python transaction.set_rollback使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.db.transaction的用法示例。


在下文中一共展示了transaction.set_rollback方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _rollback_atomics

# 需要導入模塊: from django.db import transaction [as 別名]
# 或者: from django.db.transaction import set_rollback [as 別名]
def _rollback_atomics(cls, atomics):
        """Rollback atomic blocks opened through the previous method"""
        for db_name in reversed(cls._databases_names()):
            transaction.set_rollback(True, using=db_name)
            atomics[db_name].__exit__(None, None, None) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:7,代碼來源:testcases.py

示例2: _rollback_atomics

# 需要導入模塊: from django.db import transaction [as 別名]
# 或者: from django.db.transaction import set_rollback [as 別名]
def _rollback_atomics(cls, atomics):
        """Rollback atomic blocks opened by the previous method."""
        for db_name in reversed(cls._databases_names()):
            transaction.set_rollback(True, using=db_name)
            atomics[db_name].__exit__(None, None, None) 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:7,代碼來源:testcases.py

示例3: test_first_access_with_rollback

# 需要導入模塊: from django.db import transaction [as 別名]
# 或者: from django.db.transaction import set_rollback [as 別名]
def test_first_access_with_rollback(self):

        def one(output):
            output.append(('one', 'begin'))
            with transaction.atomic():
                value = get_next_value()
                output.append(('one', value))
                time.sleep(0.2)
                transaction.set_rollback(True)
                output.append(('one', 'rollback'))
            connection.close()

        def two(output):
            time.sleep(0.1)
            output.append(('two', 'begin'))
            with transaction.atomic():
                value = get_next_value()
                output.append(('two', value))
                output.append(('two', 'commit'))
            connection.close()

        expected = [
            ('one', 'begin'),
            ('one', 1),
            ('two', 'begin'),
            ('one', 'rollback'),
            ('two', 1),
            ('two', 'commit'),
        ]

        self.assertSequence(one, two, expected) 
開發者ID:aaugustin,項目名稱:django-sequences,代碼行數:33,代碼來源:test_sequences.py

示例4: test_later_access_with_rollback

# 需要導入模塊: from django.db import transaction [as 別名]
# 或者: from django.db.transaction import set_rollback [as 別名]
def test_later_access_with_rollback(self):

        get_next_value()

        def one(output):
            output.append(('one', 'begin'))
            with transaction.atomic():
                value = get_next_value()
                output.append(('one', value))
                time.sleep(0.2)
                transaction.set_rollback(True)
                output.append(('one', 'rollback'))
            connection.close()

        def two(output):
            time.sleep(0.1)
            output.append(('two', 'begin'))
            with transaction.atomic():
                value = get_next_value()
                output.append(('two', value))
                output.append(('two', 'commit'))
            connection.close()

        expected = [
            ('one', 'begin'),
            ('one', 2),
            ('two', 'begin'),
            ('one', 'rollback'),
            ('two', 2),
            ('two', 'commit'),
        ]

        self.assertSequence(one, two, expected) 
開發者ID:aaugustin,項目名稱:django-sequences,代碼行數:35,代碼來源:test_sequences.py

示例5: set_rollback

# 需要導入模塊: from django.db import transaction [as 別名]
# 或者: from django.db.transaction import set_rollback [as 別名]
def set_rollback():
    atomic_requests = connection.settings_dict.get('ATOMIC_REQUESTS', False)
    if atomic_requests and connection.in_atomic_block:
        transaction.set_rollback(True) 
開發者ID:BeanWei,項目名稱:Dailyfresh-B2C,代碼行數:6,代碼來源:views.py

示例6: exception_handler

# 需要導入模塊: from django.db import transaction [as 別名]
# 或者: from django.db.transaction import set_rollback [as 別名]
def exception_handler(exc, context):
    """
    Returns the response that should be used for any given exception.
    By default we handle the REST framework `APIException`, and also
    Django's built-in `Http404` and `PermissionDenied` exceptions.
    Any unhandled exceptions may return `None`, which will cause a 500 error
    to be raised.
    """
    if isinstance(exc, Http404):
        exc = exceptions.NotFound()
    elif isinstance(exc, PermissionDenied):
        exc = exceptions.PermissionDenied()

    if isinstance(exc, exceptions.APIException):
        headers = {}
        if getattr(exc, 'auth_header', None):
            headers['WWW-Authenticate'] = exc.auth_header
        if getattr(exc, 'wait', None):
            headers['Retry-After'] = '%d' % exc.wait

        if isinstance(exc.detail, (list, dict)):
            data = exc.detail
        else:
            data = {'detail': exc.detail}

        set_rollback()
        return Response(data, status=exc.status_code, headers=headers)

    return None 
開發者ID:BeanWei,項目名稱:Dailyfresh-B2C,代碼行數:31,代碼來源:views.py

示例7: test_ticket_11101

# 需要導入模塊: from django.db import transaction [as 別名]
# 或者: from django.db.transaction import set_rollback [as 別名]
def test_ticket_11101(self):
        """Fixtures can be rolled back (ticket #11101)."""
        with transaction.atomic():
            management.call_command(
                'loaddata',
                'thingy.json',
                verbosity=0,
            )
            self.assertEqual(Thingy.objects.count(), 1)
            transaction.set_rollback(True)
        self.assertEqual(Thingy.objects.count(), 0) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:13,代碼來源:tests.py

示例8: set_rollback

# 需要導入模塊: from django.db import transaction [as 別名]
# 或者: from django.db.transaction import set_rollback [as 別名]
def set_rollback():
    if hasattr(transaction, 'set_rollback'):
        if connection.settings_dict.get('ATOMIC_REQUESTS', False):
            # If running in >=1.6 then mark a rollback as required,
            # and allow it to be handled by Django.
            if connection.in_atomic_block:
                transaction.set_rollback(True)
    elif transaction.is_managed():
        # Otherwise handle it explicitly if in managed mode.
        if transaction.is_dirty():
            transaction.rollback()
        transaction.leave_transaction_management()
    else:
        # transaction not managed
        pass 
開發者ID:erigones,項目名稱:esdc-ce,代碼行數:17,代碼來源:compat.py

示例9: process_view

# 需要導入模塊: from django.db import transaction [as 別名]
# 或者: from django.db.transaction import set_rollback [as 別名]
def process_view(self, request, view_func, view_args, view_kwargs):
        user = None
        if request.user.is_authenticated:
            user = request.user

        if request.method == "GET":
            logger.debug("Start query request on the view %s." % view_func.__name__)
            # NOTE: We do not need create a changeset when we just SELECT somw records.
            response = view_func(request, *view_args, **view_kwargs)
        else:
            # trap the request and give response when the method is not defined in HTTP/1.1
            if request.method not in ["HEAD", "POST", "PUT", "DELETE", "TRACE", "CONNECT", "PATCH", "OPTIONS"]:
                logger.error('Wrong method %s specified when calling %s', request.method.decode("utf-8"), request.path)
                response_data = json.dumps({"detail": 'Method "{method}" not allowed.'.format(method=request.method)},
                                           ensure_ascii=False)
                response = HttpResponse(response_data, content_type='application/json')
                response.status_code = status.HTTP_405_METHOD_NOT_ALLOWED
                return response

            logger.debug("Start write request on the view %s." % view_func.__name__)
            try:
                with transaction.atomic():
                    comment = request.META.get("HTTP_PDC_CHANGE_COMMENT", None)
                    request.changeset = models.Changeset(author=user, comment=comment)
                    request.changeset.requested_on = timezone.now()
                    response = view_func(request, *view_args, **view_kwargs)
                    # response.exception=True means there is an error occurs.
                    if getattr(response, 'exception', 0) or (
                        hasattr(response, 'status_code') and response.status_code >= 400
                    ):
                        # avoid recording changeset on server error, also
                        # abort the transaction so that no modifications are
                        # done to database
                        request.changeset.reset()
                        transaction.set_rollback(True)
                    else:
                        request.changeset.commit()
                        self._may_announce_big_change(request.changeset, request)
            except Exception:
                # NOTE: catch all errors that were raised by view.
                # And log the trace back to the file.
                logger.error('View Function Error: %s', request.path,
                             exc_info=sys.exc_info())
                # we do not want to break the default exception processing chains,
                # so re-raise the exception to the upper level.
                raise

        return response 
開發者ID:product-definition-center,項目名稱:product-definition-center,代碼行數:50,代碼來源:middleware.py


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