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


Python pre_save.disconnect方法代碼示例

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


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

示例1: _disconnect

# 需要導入模塊: from django.db.models.signals import pre_save [as 別名]
# 或者: from django.db.models.signals.pre_save import disconnect [as 別名]
def _disconnect(cls):
        """
        Disconnect signal from current model
        """
        pre_save.disconnect(
            notify_items_pre_save, sender=cls,
            dispatch_uid='knocker_pre_save_{0}'.format(cls.__name__)
        )
        post_save.disconnect(
            notify_items_post_save, sender=cls,
            dispatch_uid='knocker_post_save_{0}'.format(cls.__name__)
        )
        pre_delete.disconnect(
            notify_items_pre_delete, sender=cls,
            dispatch_uid='knocker_pre_delete_{0}'.format(cls.__name__)
        )
        post_delete.disconnect(
            notify_items_post_delete, sender=cls,
            dispatch_uid='knocker_post_delete_{0}'.format(cls.__name__)
        ) 
開發者ID:nephila,項目名稱:django-knocker,代碼行數:22,代碼來源:mixins.py

示例2: test_update_fields_signals

# 需要導入模塊: from django.db.models.signals import pre_save [as 別名]
# 或者: from django.db.models.signals.pre_save import disconnect [as 別名]
def test_update_fields_signals(self):
        p = Person.objects.create(name='Sara', gender='F')
        pre_save_data = []

        def pre_save_receiver(**kwargs):
            pre_save_data.append(kwargs['update_fields'])
        pre_save.connect(pre_save_receiver)
        post_save_data = []

        def post_save_receiver(**kwargs):
            post_save_data.append(kwargs['update_fields'])
        post_save.connect(post_save_receiver)
        p.save(update_fields=['name'])
        self.assertEqual(len(pre_save_data), 1)
        self.assertEqual(len(pre_save_data[0]), 1)
        self.assertIn('name', pre_save_data[0])
        self.assertEqual(len(post_save_data), 1)
        self.assertEqual(len(post_save_data[0]), 1)
        self.assertIn('name', post_save_data[0])

        pre_save.disconnect(pre_save_receiver)
        post_save.disconnect(post_save_receiver) 
開發者ID:denisenkom,項目名稱:django-sqlserver,代碼行數:24,代碼來源:tests.py

示例3: test_empty_update_fields

# 需要導入模塊: from django.db.models.signals import pre_save [as 別名]
# 或者: from django.db.models.signals.pre_save import disconnect [as 別名]
def test_empty_update_fields(self):
        s = Person.objects.create(name='Sara', gender='F')
        pre_save_data = []

        def pre_save_receiver(**kwargs):
            pre_save_data.append(kwargs['update_fields'])
        pre_save.connect(pre_save_receiver)
        post_save_data = []

        def post_save_receiver(**kwargs):
            post_save_data.append(kwargs['update_fields'])
        post_save.connect(post_save_receiver)
        # Save is skipped.
        with self.assertNumQueries(0):
            s.save(update_fields=[])
        # Signals were skipped, too...
        self.assertEqual(len(pre_save_data), 0)
        self.assertEqual(len(post_save_data), 0)

        pre_save.disconnect(pre_save_receiver)
        post_save.disconnect(post_save_receiver) 
開發者ID:denisenkom,項目名稱:django-sqlserver,代碼行數:23,代碼來源:tests.py

示例4: process_response

# 需要導入模塊: from django.db.models.signals import pre_save [as 別名]
# 或者: from django.db.models.signals.pre_save import disconnect [as 別名]
def process_response(self, request, response):
        """
        Disconnects the signal receiver to prevent it from staying active.
        """
        if hasattr(threadlocal, 'actionslog'):
            pre_save.disconnect(sender=LogAction, dispatch_uid=threadlocal.actionslog['signal_duid'])

        return response 
開發者ID:shtalinberg,項目名稱:django-actions-logger,代碼行數:10,代碼來源:middleware.py

示例5: process_exception

# 需要導入模塊: from django.db.models.signals import pre_save [as 別名]
# 或者: from django.db.models.signals.pre_save import disconnect [as 別名]
def process_exception(self, request, exception):
        """
        Disconnects the signal receiver to prevent it from staying active in case of an exception.
        """
        if hasattr(threadlocal, 'actionslog'):
            pre_save.disconnect(sender=LogAction, dispatch_uid=threadlocal.actionslog['signal_duid'])

        return None 
開發者ID:shtalinberg,項目名稱:django-actions-logger,代碼行數:10,代碼來源:middleware.py

示例6: register_pre_save_on_AUTH_USER_MODER_change

# 需要導入模塊: from django.db.models.signals import pre_save [as 別名]
# 或者: from django.db.models.signals.pre_save import disconnect [as 別名]
def register_pre_save_on_AUTH_USER_MODER_change(sender, setting, value, enter, **kwargs):
    if setting == "AUTH_USER_MODEL" and value != USER_MODEL:
        if enter:
            pre_save.connect(useraudit.password_expiry.user_pre_save, sender=value)
        else:
            pre_save.disconnect(useraudit.password_expiry.user_pre_save, sender=value) 
開發者ID:muccg,項目名稱:django-useraudit,代碼行數:8,代碼來源:tests.py

示例7: test_signal

# 需要導入模塊: from django.db.models.signals import pre_save [as 別名]
# 或者: from django.db.models.signals.pre_save import disconnect [as 別名]
def test_signal(self):
        def handler(sender, user=None, **kwargs):
            self.handler_called = True
            self.assertEquals(sender, type(self.user))
            self.assertEquals(user, self.user)
        login_failure_limit_reached.connect(handler)

        self.handler_called = False

        _ = authenticate(username=self.username, password="INCORRECT")
        _ = authenticate(username=self.username, password="INCORRECT")

        login_failure_limit_reached.disconnect(handler)

        self.assertTrue(self.handler_called) 
開發者ID:muccg,項目名稱:django-useraudit,代碼行數:17,代碼來源:tests.py

示例8: pre_post_save_wrapper

# 需要導入模塊: from django.db.models.signals import pre_save [as 別名]
# 或者: from django.db.models.signals.pre_save import disconnect [as 別名]
def pre_post_save_wrapper(self):
        self.pre_save_called = False
        self.post_save_called = False

        self.bar

        def pre_save_handler(sender, instance, **kwargs):
            # Assert that a pre_save handler gets the proper information on which fields have changed
            # (hence the translations have not yet been saved to the db).

            self.pre_save_called = True

            field_fr = instance._linguist_translations["title"].get("fr", None)
            field_en = instance._linguist_translations["title"].get("en", None)

            assert field_fr.has_changed
            assert not field_en.has_changed

        pre_save.connect(pre_save_handler, sender=BarModel)

        def post_save_handler(sender, instance, **kwargs):
            # Assert that a post_save handler that refreshes the model gets the saved translations
            # (hence the translations have been saved to the db).

            self.post_save_called = True

            title_fr = instance.title_fr
            title_en = instance.title_en

            instance = BarModel.objects.get(pk=instance.pk)

            assert instance.title_fr == title_fr
            assert instance.title_en == title_en

        post_save.connect(post_save_handler, sender=BarModel)

        yield

        pre_save.disconnect(pre_save_handler, sender=BarModel)
        post_save.disconnect(post_save_handler, sender=BarModel) 
開發者ID:ulule,項目名稱:django-linguist,代碼行數:42,代碼來源:test_signals.py

示例9: disconnect_signals

# 需要導入模塊: from django.db.models.signals import pre_save [as 別名]
# 或者: from django.db.models.signals.pre_save import disconnect [as 別名]
def disconnect_signals():
    post_save.disconnect(receiver=reassess_on_profile_save, sender=UserProfile)
    pre_save.disconnect(receiver=signals.pre_save_config, sender=AutogroupsConfig)
    pre_delete.disconnect(receiver=signals.pre_delete_config, sender=AutogroupsConfig)
    post_save.disconnect(receiver=signals.check_groups_on_profile_update, sender=UserProfile)
    m2m_changed.disconnect(receiver=signals.autogroups_states_changed, sender=AutogroupsConfig.states.through) 
開發者ID:allianceauth,項目名稱:allianceauth,代碼行數:8,代碼來源:__init__.py

示例10: disconnect_signals

# 需要導入模塊: from django.db.models.signals import pre_save [as 別名]
# 或者: from django.db.models.signals.pre_save import disconnect [as 別名]
def disconnect_signals(cls):
        m2m_changed.disconnect(m2m_changed_user_groups, sender=User.groups.through)
        m2m_changed.disconnect(m2m_changed_group_permissions, sender=Group.permissions.through)
        m2m_changed.disconnect(m2m_changed_user_permissions, sender=User.user_permissions.through)
        m2m_changed.disconnect(m2m_changed_state_permissions, sender=State.permissions.through)
        pre_save.disconnect(disable_services_on_inactive, sender=User)
        m2m_changed.disconnect(state_member_corporations_changed, sender=State.member_corporations.through)
        m2m_changed.disconnect(state_member_characters_changed, sender=State.member_characters.through)
        m2m_changed.disconnect(state_member_alliances_changed, sender=State.member_alliances.through)
        post_save.disconnect(state_saved, sender=State) 
開發者ID:allianceauth,項目名稱:allianceauth,代碼行數:12,代碼來源:auth_utils.py


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