Python django.db.models.signals.post_delete.connect() Examples
The following are 19
code examples of django.db.models.signals.post_delete.connect().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.db.models.signals.post_delete
, or try the search function
.
Example #1
Source File: model_observer.py From djangochannelsrestframework with MIT License | 6 votes |
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) )
Example #2
Source File: apps.py From substra-backend with Apache License 2.0 | 6 votes |
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)
Example #3
Source File: state.py From django-river with BSD 3-Clause "New" or "Revised" License | 6 votes |
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)
Example #4
Source File: apps.py From openwisp-controller with GNU General Public License v3.0 | 6 votes |
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 )
Example #5
Source File: test_delete_page.py From wagtail with BSD 3-Clause "New" or "Revised" License | 6 votes |
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)
Example #6
Source File: generics.py From adhocracy4 with GNU Affero General Public License v3.0 | 6 votes |
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 )
Example #7
Source File: mixins.py From django-knocker with BSD 3-Clause "New" or "Revised" License | 6 votes |
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__) )
Example #8
Source File: test_indexable.py From django-elasticsearch with MIT License | 5 votes |
def setUp(self): from django.db.models.signals import post_save, post_delete try: from django.db.models.signals import post_migrate except ImportError: # django <= 1.6 from django.db.models.signals import post_syncdb as post_migrate from django_elasticsearch.models import es_save_callback from django_elasticsearch.models import es_delete_callback from django_elasticsearch.models import es_syncdb_callback try: from django.apps import apps app = apps.get_app_config('django_elasticsearch') except ImportError: # django 1.4 from django.db.models import get_app app = get_app('django_elasticsearch') post_save.connect(es_save_callback) post_delete.connect(es_delete_callback) post_migrate.connect(es_syncdb_callback) if int(get_version()[2]) >= 6: sender = app else: sender = None post_migrate.send(sender=sender, app_config=app, app=app, # django 1.4 created_models=[TestModel,], verbosity=2) self.instance = TestModel.objects.create(username=u"1", first_name=u"woot", last_name=u"foo") self.instance.es.do_index()
Example #9
Source File: apps.py From c3nav with Apache License 2.0 | 5 votes |
def ready(self): from c3nav.editor.models import ChangeSet from c3nav.editor.signals import set_changeset_author_on_login post_save.connect(ChangeSet.object_changed_handler) post_delete.connect(ChangeSet.object_changed_handler) m2m_changed.connect(ChangeSet.object_changed_handler) user_logged_in.connect(set_changeset_author_on_login)
Example #10
Source File: changes.py From c3nav with Apache License 2.0 | 5 votes |
def register_signals(): from c3nav.mapdata.models.geometry.base import GeometryMixin for model in get_submodels(GeometryMixin): post_delete.connect(geometry_deleted, sender=model) from c3nav.mapdata.models.locations import SpecificLocation for model in get_submodels(SpecificLocation): m2m_changed.connect(locationgroup_changed, sender=model.groups.through)
Example #11
Source File: signals.py From site with MIT License | 5 votes |
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)
Example #12
Source File: signal_handlers.py From wagtail with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #13
Source File: signal_handlers.py From wagtail with BSD 3-Clause "New" or "Revised" License | 5 votes |
def register_signal_handlers(): Document = get_document_model() post_delete.connect(post_delete_file_cleanup, sender=Document)
Example #14
Source File: signal_handlers.py From wagtail with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #15
Source File: signal_handlers.py From wagtail with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #16
Source File: test_delete_page.py From wagtail with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #17
Source File: middleware.py From django-aws-template with MIT License | 5 votes |
def __init__(self): post_save.connect(invalidate_cache, sender=get_user_model()) post_delete.connect(invalidate_cache, sender=get_user_model())
Example #18
Source File: managers.py From stream-django with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #19
Source File: test_delete_page.py From wagtail with BSD 3-Clause "New" or "Revised" License | 4 votes |
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)