当前位置: 首页>>代码示例>>Python>>正文


Python pre_delete.connect方法代码示例

本文整理汇总了Python中django.db.models.signals.pre_delete.connect方法的典型用法代码示例。如果您正苦于以下问题:Python pre_delete.connect方法的具体用法?Python pre_delete.connect怎么用?Python pre_delete.connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.db.models.signals.pre_delete的用法示例。


在下文中一共展示了pre_delete.connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ready

# 需要导入模块: from django.db.models.signals import pre_delete [as 别名]
# 或者: from django.db.models.signals.pre_delete import connect [as 别名]
def ready(self):
        # The app is now ready. Include any monkey patches here.

        # Monkey patch CSRF to switch to session based CSRF. Session
        # based CSRF will prevent attacks from apps under the same
        # domain. If you're planning to host your app under it's own
        # domain you can remove session_csrf and use Django's CSRF
        # library. See also
        # https://github.com/mozilla/sugardough/issues/38
        session_csrf.monkeypatch()

        # Connect signals.
        from atmo.jobs.models import SparkJob
        from atmo.jobs.signals import assign_group_perm, remove_group_perm

        post_save.connect(
            assign_group_perm,
            sender=SparkJob,
            dispatch_uid="sparkjob_post_save_assign_perm",
        )
        pre_delete.connect(
            remove_group_perm,
            sender=SparkJob,
            dispatch_uid="sparkjob_pre_delete_remove_perm",
        ) 
开发者ID:mozilla,项目名称:telemetry-analysis-service,代码行数:27,代码来源:apps.py

示例2: test_page_delete_post

# 需要导入模块: from django.db.models.signals import pre_delete [as 别名]
# 或者: from django.db.models.signals.pre_delete import connect [as 别名]
def test_page_delete_post(self):
        # Connect a mock signal handler to page_unpublished signal
        mock_handler = mock.MagicMock()
        page_unpublished.connect(mock_handler)

        # Post
        response = self.client.post(reverse('wagtailadmin_pages:delete', args=(self.child_page.id, )))

        # Should be redirected to explorer page
        self.assertRedirects(response, reverse('wagtailadmin_explore', args=(self.root_page.id, )))

        # treebeard should report no consistency problems with the tree
        self.assertFalse(any(Page.find_problems()), 'treebeard found consistency problems')

        # Check that the page is gone
        self.assertEqual(Page.objects.filter(path__startswith=self.root_page.path, slug='hello-world').count(), 0)

        # Check that the page_unpublished signal was fired
        self.assertEqual(mock_handler.call_count, 1)
        mock_call = mock_handler.mock_calls[0][2]

        self.assertEqual(mock_call['sender'], self.child_page.specific_class)
        self.assertEqual(mock_call['instance'], self.child_page)
        self.assertIsInstance(mock_call['instance'], self.child_page.specific_class) 
开发者ID:wagtail,项目名称:wagtail,代码行数:26,代码来源:test_delete_page.py

示例3: _connect

# 需要导入模块: from django.db.models.signals import pre_delete [as 别名]
# 或者: from django.db.models.signals.pre_delete import connect [as 别名]
def _connect(cls):
        """
        Connect signal to current model
        """
        pre_save.connect(
            notify_items_pre_save, sender=cls,
            dispatch_uid='knocker_pre_save_{0}'.format(cls.__name__)
        )
        post_save.connect(
            notify_items_post_save, sender=cls,
            dispatch_uid='knocker_post_save_{0}'.format(cls.__name__)
        )
        pre_delete.connect(
            notify_items_pre_delete, sender=cls,
            dispatch_uid='knocker_pre_delete_{0}'.format(cls.__name__)
        )
        post_delete.connect(
            notify_items_post_delete, sender=cls,
            dispatch_uid='knocker_post_delete_{0}'.format(cls.__name__)
        ) 
开发者ID:nephila,项目名称:django-knocker,代码行数:22,代码来源:mixins.py

示例4: register

# 需要导入模块: from django.db.models.signals import pre_delete [as 别名]
# 或者: from django.db.models.signals.pre_delete import connect [as 别名]
def register(self, model, index_cls=AlgoliaIndex, auto_indexing=None):
        """
        Registers the given model with Algolia engine.

        If the given model is already registered with Algolia engine, a
        RegistrationError will be raised.
        """
        # Check for existing registration.
        if self.is_registered(model):
            raise RegistrationError(
                '{} is already registered with Algolia engine'.format(model))

        # Perform the registration.
        if not issubclass(index_cls, AlgoliaIndex):
            raise RegistrationError(
                '{} should be a subclass of AlgoliaIndex'.format(index_cls))
        index_obj = index_cls(model, self.client, self.__settings)
        self.__registered_models[model] = index_obj

        if (isinstance(auto_indexing, bool) and
                auto_indexing) or self.__auto_indexing:
            # Connect to the signalling framework.
            post_save.connect(self.__post_save_receiver, model)
            pre_delete.connect(self.__pre_delete_receiver, model)
            logger.info('REGISTER %s', model) 
开发者ID:algolia,项目名称:algoliasearch-django,代码行数:27,代码来源:registration.py

示例5: ready

# 需要导入模块: from django.db.models.signals import pre_delete [as 别名]
# 或者: from django.db.models.signals.pre_delete import connect [as 别名]
def ready(self):
        from .models import clear_usersettings_cache
        from .shortcuts import get_usersettings_model

        usersettings_model = get_usersettings_model()
        pre_save.connect(clear_usersettings_cache, sender=usersettings_model)
        pre_delete.connect(clear_usersettings_cache, sender=usersettings_model) 
开发者ID:mishbahr,项目名称:django-usersettings2,代码行数:9,代码来源:apps.py

示例6: remove_xform

# 需要导入模块: from django.db.models.signals import pre_delete [as 别名]
# 或者: from django.db.models.signals.pre_delete import connect [as 别名]
def remove_xform(xform):
    # disconnect parsed instance pre delete signal
    pre_delete.disconnect(_remove_from_mongo, sender=ParsedInstance)

    # delete instances from mongo db
    query = {
        ParsedInstance.USERFORM_ID:
        "%s_%s" % (xform.user.username, xform.id_string)}
    xform_instances.remove(query, j=True)

    # delete xform, and all related models
    xform.delete()

    # reconnect parsed instance pre delete signal?
    pre_delete.connect(_remove_from_mongo, sender=ParsedInstance) 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:17,代码来源:logger_tools.py

示例7: __call__

# 需要导入模块: from django.db.models.signals import pre_delete [as 别名]
# 或者: from django.db.models.signals.pre_delete import connect [as 别名]
def __call__(self, request):
        # Prepare to collect objects that have been changed
        local_thread.changed_objects = []

        # Assign an ID to the given request in case we have to handle multiple objects
        request.id = uuid.uuid4()

        # Listen for objects being saved (created/updated) and deleted
        post_save.connect(cache_changed_object, dispatch_uid="log_object_being_changed")
        pre_delete.connect(
            cache_deleted_object, dispatch_uid="log_object_being_deleted"
        )

        # Process the request
        response = self.get_response(request)

        # Nothing to do as there are no changes to process
        if not local_thread.changed_objects:
            return response

        # Record change for each object that need to be tracked
        for changed_object, action in local_thread.changed_objects:
            if hasattr(changed_object, "log_change"):
                changed_object.log_change(request.user, request.id, action)

        # Cleanup object changes that are too old (based on changelog retention)
        if local_thread.changed_objects and settings.CHANGELOG_RETENTION:
            date_limit = timezone.now() - timedelta(days=settings.CHANGELOG_RETENTION)
            ObjectChange.objects.filter(time__lt=date_limit).delete()

        return response 
开发者ID:respawner,项目名称:peering-manager,代码行数:33,代码来源:middleware.py

示例8: test_page_delete_notlive_post

# 需要导入模块: from django.db.models.signals import pre_delete [as 别名]
# 或者: from django.db.models.signals.pre_delete import connect [as 别名]
def test_page_delete_notlive_post(self):
        # Same as above, but this makes sure the page_unpublished signal is not fired
        # when if the page is not live when it is deleted

        # Unpublish the page
        self.child_page.live = False
        self.child_page.save()

        # Connect a mock signal handler to page_unpublished signal
        mock_handler = mock.MagicMock()
        page_unpublished.connect(mock_handler)

        # Post
        response = self.client.post(reverse('wagtailadmin_pages:delete', args=(self.child_page.id, )))

        # Should be redirected to explorer page
        self.assertRedirects(response, reverse('wagtailadmin_explore', args=(self.root_page.id, )))

        # treebeard should report no consistency problems with the tree
        self.assertFalse(any(Page.find_problems()), 'treebeard found consistency problems')

        # Check that the page is gone
        self.assertEqual(Page.objects.filter(path__startswith=self.root_page.path, slug='hello-world').count(), 0)

        # Check that the page_unpublished signal was not fired
        self.assertEqual(mock_handler.call_count, 0) 
开发者ID:wagtail,项目名称:wagtail,代码行数:28,代码来源:test_delete_page.py

示例9: register_signal_handlers

# 需要导入模块: from django.db.models.signals import pre_delete [as 别名]
# 或者: from django.db.models.signals.pre_delete import connect [as 别名]
def register_signal_handlers():
    post_save.connect(post_save_site_signal_handler, sender=Site)
    post_delete.connect(post_delete_site_signal_handler, sender=Site)

    pre_delete.connect(pre_delete_page_unpublish, sender=Page)
    post_delete.connect(post_delete_page_log_deletion, sender=Page) 
开发者ID:wagtail,项目名称:wagtail,代码行数:8,代码来源:signal_handlers.py

示例10: __exit__

# 需要导入模块: from django.db.models.signals import pre_delete [as 别名]
# 或者: from django.db.models.signals.pre_delete import connect [as 别名]
def __exit__(self, exc_type, exc_value, traceback):
        for model in self.models:
            post_save.connect(
                algolia_engine._AlgoliaEngine__post_save_receiver,
                sender=model
            )
            pre_delete.connect(
                algolia_engine._AlgoliaEngine__pre_delete_receiver,
                sender=model
            ) 
开发者ID:algolia,项目名称:algoliasearch-django,代码行数:12,代码来源:decorators.py

示例11: setUp

# 需要导入模块: from django.db.models.signals import pre_delete [as 别名]
# 或者: from django.db.models.signals.pre_delete import connect [as 别名]
def setUp(self):
        self.user = User.objects.create_superuser(username="test_user", email="test_user@test.com",
                                                  password="test_password")
        self.group = Group.objects.create(name="test_group")
        self.collection_set = CollectionSet.objects.create(group=self.group, name="test_collection_set")
        self.credential_token = {"key": "test_key"}
        self.credential = Credential.objects.create(user=self.user, platform="test_platform",
                                                    token=json.dumps(self.credential_token))

        # Register receivers. This would normally be done in config.py but is disabled for unit tests.
        post_save.connect(schedule_harvest_receiver, sender=Collection)
        pre_delete.connect(unschedule_harvest_receiver, sender=Collection) 
开发者ID:gwu-libraries,项目名称:sfm-ui,代码行数:14,代码来源:test_sched.py

示例12: ready

# 需要导入模块: from django.db.models.signals import pre_delete [as 别名]
# 或者: from django.db.models.signals.pre_delete import connect [as 别名]
def ready(self):
        from django.db.models.signals import post_save, pre_save, pre_delete
        from .models import TestExecution, TestRun
        from tcms import signals

        post_save.connect(signals.handle_emails_post_run_save, sender=TestRun)
        pre_save.connect(signals.pre_save_clean, sender=TestRun)
        pre_delete.connect(signals.handle_comments_pre_delete, TestExecution) 
开发者ID:kiwitcms,项目名称:Kiwi,代码行数:10,代码来源:apps.py

示例13: ready

# 需要导入模块: from django.db.models.signals import pre_delete [as 别名]
# 或者: from django.db.models.signals.pre_delete import connect [as 别名]
def ready(self):
        from django.db.models.signals import post_save, pre_delete, pre_save
        from .models import TestCase
        from tcms import signals

        pre_save.connect(signals.pre_save_clean, TestCase)
        post_save.connect(signals.handle_emails_post_case_save, TestCase)
        pre_delete.connect(signals.handle_emails_pre_case_delete, TestCase)
        pre_delete.connect(signals.handle_comments_pre_delete, TestCase) 
开发者ID:kiwitcms,项目名称:Kiwi,代码行数:11,代码来源:apps.py

示例14: connect_signals

# 需要导入模块: from django.db.models.signals import pre_delete [as 别名]
# 或者: from django.db.models.signals.pre_delete import connect [as 别名]
def connect_signals():
    post_save.connect(receiver=reassess_on_profile_save, sender=UserProfile)
    pre_save.connect(receiver=signals.pre_save_config, sender=AutogroupsConfig)
    pre_delete.connect(receiver=signals.pre_delete_config, sender=AutogroupsConfig)
    post_save.connect(receiver=signals.check_groups_on_profile_update, sender=UserProfile)
    m2m_changed.connect(receiver=signals.autogroups_states_changed, sender=AutogroupsConfig.states.through) 
开发者ID:allianceauth,项目名称:allianceauth,代码行数:8,代码来源:__init__.py

示例15: test_subpage_deletion

# 需要导入模块: from django.db.models.signals import pre_delete [as 别名]
# 或者: from django.db.models.signals.pre_delete import connect [as 别名]
def test_subpage_deletion(self):
        # Connect mock signal handlers to page_unpublished, pre_delete and post_delete signals
        unpublish_signals_received = []
        pre_delete_signals_received = []
        post_delete_signals_received = []

        def page_unpublished_handler(sender, instance, **kwargs):
            unpublish_signals_received.append((sender, instance.id))

        def pre_delete_handler(sender, instance, **kwargs):
            pre_delete_signals_received.append((sender, instance.id))

        def post_delete_handler(sender, instance, **kwargs):
            post_delete_signals_received.append((sender, instance.id))

        page_unpublished.connect(page_unpublished_handler)
        pre_delete.connect(pre_delete_handler)
        post_delete.connect(post_delete_handler)

        # Post
        response = self.client.post(reverse('wagtailadmin_pages:delete', args=(self.child_index.id, )))

        # Should be redirected to explorer page
        self.assertRedirects(response, reverse('wagtailadmin_explore', args=(self.root_page.id, )))

        # treebeard should report no consistency problems with the tree
        self.assertFalse(any(Page.find_problems()), 'treebeard found consistency problems')

        # Check that the page is gone
        self.assertFalse(StandardIndex.objects.filter(id=self.child_index.id).exists())
        self.assertFalse(Page.objects.filter(id=self.child_index.id).exists())

        # Check that the subpage is also gone
        self.assertFalse(StandardChild.objects.filter(id=self.grandchild_page.id).exists())
        self.assertFalse(Page.objects.filter(id=self.grandchild_page.id).exists())

        # Check that the signals were fired for both pages
        self.assertIn((StandardIndex, self.child_index.id), unpublish_signals_received)
        self.assertIn((StandardChild, self.grandchild_page.id), unpublish_signals_received)

        self.assertIn((StandardIndex, self.child_index.id), pre_delete_signals_received)
        self.assertIn((StandardChild, self.grandchild_page.id), pre_delete_signals_received)

        self.assertIn((StandardIndex, self.child_index.id), post_delete_signals_received)
        self.assertIn((StandardChild, self.grandchild_page.id), post_delete_signals_received) 
开发者ID:wagtail,项目名称:wagtail,代码行数:47,代码来源:test_delete_page.py


注:本文中的django.db.models.signals.pre_delete.connect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。