本文整理汇总了Python中django.db.models.signals.post_delete.connect方法的典型用法代码示例。如果您正苦于以下问题:Python post_delete.connect方法的具体用法?Python post_delete.connect怎么用?Python post_delete.connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.db.models.signals.post_delete
的用法示例。
在下文中一共展示了post_delete.connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: contribute_to_class
# 需要导入模块: from django.db.models.signals import post_delete [as 别名]
# 或者: from django.db.models.signals.post_delete import connect [as 别名]
def contribute_to_class(self, cls, name, *args, **kwargs):
@classproperty
def river(_self):
return RiverObject(_self)
self.field_name = name
self._add_to_class(cls, self.field_name + "_transition_approvals",
GenericRelation('%s.%s' % (TransitionApproval._meta.app_label, TransitionApproval._meta.object_name)))
self._add_to_class(cls, self.field_name + "_transitions", GenericRelation('%s.%s' % (Transition._meta.app_label, Transition._meta.object_name)))
if id(cls) not in workflow_registry.workflows:
self._add_to_class(cls, "river", river)
super(StateField, self).contribute_to_class(cls, name, *args, **kwargs)
if id(cls) not in workflow_registry.workflows:
post_save.connect(_on_workflow_object_saved, self.model, False, dispatch_uid='%s_%s_riverstatefield_post' % (self.model, name))
post_delete.connect(_on_workflow_object_deleted, self.model, False, dispatch_uid='%s_%s_riverstatefield_post' % (self.model, name))
workflow_registry.add(self.field_name, cls)
示例2: _connect
# 需要导入模块: from django.db.models.signals import post_delete [as 别名]
# 或者: from django.db.models.signals.post_delete import connect [as 别名]
def _connect(self):
"""
Connect the signal listing.
"""
# this is used to capture the current state for the model
post_init.connect(
self.post_init_receiver, sender=self.model_cls, dispatch_uid=id(self)
)
post_save.connect(
self.post_save_receiver, sender=self.model_cls, dispatch_uid=id(self)
)
post_delete.connect(
self.post_delete_receiver, sender=self.model_cls, dispatch_uid=id(self)
)
示例3: ready
# 需要导入模块: from django.db.models.signals import post_delete [as 别名]
# 或者: from django.db.models.signals.post_delete import connect [as 别名]
def ready(self):
from .signals.datasample.pre_save import data_sample_pre_save
from .signals.algo.post_delete import algo_post_delete
from .signals.objective.post_delete import objective_post_delete
from .signals.datasample.post_delete import data_sample_post_delete
from .signals.datamanager.post_delete import datamanager_post_delete
from .signals.model.post_delete import model_post_delete
# registering signals with the model's string label
from substrapp.models import Algo, Objective, DataSample, DataManager, Model
pre_save.connect(data_sample_pre_save, sender=DataSample)
post_delete.connect(algo_post_delete, sender=Algo)
post_delete.connect(objective_post_delete, sender=Objective)
post_delete.connect(data_sample_post_delete, sender=DataSample)
post_delete.connect(datamanager_post_delete, sender=DataManager)
post_delete.connect(model_post_delete, sender=Model)
示例4: test_page_delete_post
# 需要导入模块: from django.db.models.signals import post_delete [as 别名]
# 或者: from django.db.models.signals.post_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)
示例5: _connect
# 需要导入模块: from django.db.models.signals import post_delete [as 别名]
# 或者: from django.db.models.signals.post_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__)
)
示例6: setup_delete_signals
# 需要导入模块: from django.db.models.signals import post_delete [as 别名]
# 或者: from django.db.models.signals.post_delete import connect [as 别名]
def setup_delete_signals(model_list, generic_model):
"""
Ensure that generic model instance is deleted if content object was.
"""
def delete_content_object_handler(sender, instance, **kwargs):
contenttype = ContentType.objects.get_for_model(instance)
pk = instance.pk
generic_model.objects\
.filter(content_type=contenttype, object_pk=pk)\
.delete()
for model in model_list:
post_delete.connect(
delete_content_object_handler,
'.'.join(model),
weak=False
)
示例7: connect_signals
# 需要导入模块: from django.db.models.signals import post_delete [as 别名]
# 或者: from django.db.models.signals.post_delete import connect [as 别名]
def connect_signals(self):
"""
* m2m validation before templates are added/removed to a config
* automatic vpn client management on m2m_changed
* automatic vpn client removal
"""
m2m_changed.connect(
self.config_model.clean_templates,
sender=self.config_model.templates.through,
)
m2m_changed.connect(
self.config_model.templates_changed,
sender=self.config_model.templates.through,
)
m2m_changed.connect(
self.config_model.manage_vpn_clients,
sender=self.config_model.templates.through,
)
post_delete.connect(
self.vpnclient_model.post_delete, sender=self.vpnclient_model
)
示例8: bind_model
# 需要导入模块: from django.db.models.signals import post_delete [as 别名]
# 或者: from django.db.models.signals.post_delete import connect [as 别名]
def bind_model(self, sender, **kwargs):
if issubclass(sender, (Activity, )):
post_save.connect(self.activity_created, sender=sender)
post_delete.connect(self.activity_delete, sender=sender)
示例9: __init__
# 需要导入模块: from django.db.models.signals import post_delete [as 别名]
# 或者: from django.db.models.signals.post_delete import connect [as 别名]
def __init__(self):
post_save.connect(invalidate_cache, sender=get_user_model())
post_delete.connect(invalidate_cache, sender=get_user_model())
示例10: test_page_delete_notlive_post
# 需要导入模块: from django.db.models.signals import post_delete [as 别名]
# 或者: from django.db.models.signals.post_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)
示例11: register_signal_handlers
# 需要导入模块: from django.db.models.signals import post_delete [as 别名]
# 或者: from django.db.models.signals.post_delete import connect [as 别名]
def register_signal_handlers():
Image = get_image_model()
Document = get_document_model()
for model in get_page_models():
page_published.connect(purge_page_from_cache, sender=model)
page_unpublished.connect(purge_page_from_cache, sender=model)
post_save.connect(purge_image_from_cache, sender=Image)
post_delete.connect(purge_image_from_cache, sender=Image)
post_save.connect(purge_document_from_cache, sender=Document)
post_delete.connect(purge_document_from_cache, sender=Document)
示例12: register_signal_handlers
# 需要导入模块: from django.db.models.signals import post_delete [as 别名]
# 或者: from django.db.models.signals.post_delete import connect [as 别名]
def register_signal_handlers():
Image = get_image_model()
Rendition = Image.get_rendition_model()
pre_save.connect(pre_save_image_feature_detection, sender=Image)
post_delete.connect(post_delete_file_cleanup, sender=Image)
post_delete.connect(post_delete_file_cleanup, sender=Rendition)
post_delete.connect(post_delete_purge_rendition_cache, sender=Rendition)
示例13: register_signal_handlers
# 需要导入模块: from django.db.models.signals import post_delete [as 别名]
# 或者: from django.db.models.signals.post_delete import connect [as 别名]
def register_signal_handlers():
Document = get_document_model()
post_delete.connect(post_delete_file_cleanup, sender=Document)
示例14: register_signal_handlers
# 需要导入模块: from django.db.models.signals import post_delete [as 别名]
# 或者: from django.db.models.signals.post_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)
示例15: __init__
# 需要导入模块: from django.db.models.signals import post_delete [as 别名]
# 或者: from django.db.models.signals.post_delete import connect [as 别名]
def __init__(self):
post_save.connect(self.user_model_updated, sender=DiscordUser)
post_delete.connect(self.mapping_model_deleted, sender=RoleMapping)
pre_save.connect(self.mapping_model_updated, sender=RoleMapping)
pre_social_login.connect(self.social_account_updated)
social_account_added.connect(self.social_account_updated)
social_account_updated.connect(self.social_account_updated)
social_account_removed.connect(self.social_account_removed)
user_logged_in.connect(self.user_logged_in)