def post(self, request): pre_delete.send(sender=PeriodicTask, instance=TimedTask) intervals = request.POST.getlist("interval_check", []) if intervals: for v in intervals: IntervalSchedule.objects.filter(pk=v).delete() return HttpResponseRedirect(reverse('job_interval_list'))
def update(self, instance, validated_data): user_from = validated_data.get('user_from') if validated_data.get('_status') == settings.EVENT_CH_STATUS_DELETED: pre_delete.send(sender=instance.__class__, instance=instance) instance.status = (user_from, validated_data.get('_status')) return instance
def on_model_pre_delete(self, model, instance): try: model_cls, django_instance = self.get_django_instance(model, instance) pre_delete.send(model_cls, using=self, instance=django_instance) self.pre_delete_django_instance = django_instance except Exception as e: logger.warning('[!] on_model_pre_delete signal failed: {}'.format(str(e)))
def post(self, request): pre_delete.send(sender=PeriodicTask, instance=TimedTask) crontabs = request.POST.getlist("crontab_check", []) if crontabs: for v in crontabs: CrontabSchedule.objects.filter(pk=v).delete() return HttpResponseRedirect(reverse('job_crontab_list'))
def delete(self, using=None, force=False): if force: super().delete(using) else: pre_delete.send(sender=self.__class__, instance=self) self.deleted = True self.save() post_delete.send(sender=self.__class__, instance=self)
def delete(self): pre_delete.send(sender=self.__class__, instance=self, using=self._state.db) self.deleted_at = datetime.datetime.now(pytz.UTC) self.save() post_delete.send(sender=self.__class__, instance=self, using=self._state.db)
def delete(self, using=None, force=False): if force: super(BaseModel, self).delete(using=using) else: model_class = type(self) pre_delete.send(sender=model_class, instance=self, using=self._state.db) self.deleted = now() self.save() post_delete.send(sender=model_class, instance=self, using=self._state.db)
def delete(self, **kwargs): force = kwargs.pop('force', False) if force: super(DeletableTimeStampedModel, self).delete(**kwargs) else: pre_delete.send(self.__class__, instance=self) self.deleted = True self.save() post_delete.send(self.__class__, instance=self)
def delete(self): pre_delete.send(sender=self.__class__, instance=self) super().delete() post_delete.send(sender=self.__class__, instance=self) # We also clean the DRF cache clear_for_instance(self)
def delete(self, obj): """ deletes an object :param obj: object to be deleted """ if obj.id: pre_delete.send(sender=obj.__class__, instance=obj, using='repository') self.connection.delete(obj.id) post_delete.send(sender=obj.__class__, instance=obj, using='repository')
def delete(self, force=False): if force: return super(DataQuerySet, self).delete() else: # otherwise this list will be different in the next loop :) to_be_notified = list(self) for obj in to_be_notified: pre_delete.send(sender=self.model, instance=obj, using=self._db) qs = self.update(deleted=now()) for obj in to_be_notified: post_delete.send(sender=self.model, instance=obj, using=self._db) return qs
def delete(self, **kwargs): # pylint: disable=arguments-differ """ Override delete method to allow for "soft" deleting. If `force` is True delete from the database, otherwise set model.deleted = True :param kwargs: dict - add force=True to delete from the database :return: """ force = kwargs.pop('force', False) if force: super().delete(**kwargs) else: pre_delete.send(self.__class__, instance=self) self.deleted = True self.save() post_delete.send(self.__class__, instance=self)
def delete(self, force=False): """ Add support for the queryset.delete method. Use select_for_update and set deleted to True. Manually send post_delete signals on delete. """ if force: return super().delete() else: with transaction.atomic(savepoint=False): instances = super().select_for_update() for instance in instances: pre_delete.send(sender=instance.__class__, instance=instance) delete_result = instances.delete() for instance in instances: post_delete.send(sender=instance.__class__, instance=instance) return delete_result
def test_missing_relation_object(self): test_type = { 'verbose_name': 'Test Notification Type', 'level': 'info', 'verb': 'testing', 'message': ('{notification.verb} initiated by' '[{notification.actor}]({notification.actor_link}) with' ' [{notification.action_object}]({notification.action_link}) for' ' [{notification.target}]({notification.target_link}).'), 'email_subject': ('[{site.name}] {notification.verb} reported by' ' {notification.actor} with {notification.action_object} for {notification.target}' ), } register_notification_type('test_type', test_type) self.notification_options.pop('email_subject') self.notification_options.update({'type': 'test_type'}) operator = self._get_operator() with self.subTest("Missing target object after creation"): self.notification_options.update({'target': operator}) self._create_notification() pre_delete.send(sender=self, instance=operator) n_count = notification_queryset.count() self.assertEqual(n_count, 0) with self.subTest("Missing action object after creation"): self.notification_options.pop('target') self.notification_options.update({'action_object': operator}) self._create_notification() pre_delete.send(sender=self, instance=operator) n_count = notification_queryset.count() self.assertEqual(n_count, 0) with self.subTest("Missing actor object after creation"): self.notification_options.pop('action_object') self.notification_options.pop('url') self.notification_options.update({'sender': operator}) self._create_notification() pre_delete.send(sender=self, instance=operator) n_count = notification_queryset.count() self.assertEqual(n_count, 0) unregister_notification_type('test_type')
def delete(self, *args, **kwargs): pre_delete.send(sender=Contact, instance=self, using='default') super(Contact, self).delete(*args, **kwargs) self.primary_contact.clear()
def merge_into(self, other, callback=lambda x: x, using='default'): """ Collects objects related to ``self`` and updates their foreign keys to point to ``other``. If ``callback`` is specified, it will be executed on each collected chunk before any changes are made, and should return a modified list of results that still need updated. NOTE: Duplicates (unique constraints) which exist and are bound to ``other`` are preserved, and relations on ``self`` are discarded. """ # TODO: proper support for database routing s_model = type(self) # Find all the objects than need to be deleted. collector = EverythingCollector(using=using) collector.collect([self]) for model, objects in six.iteritems(collector.data): # find all potential keys which match our type fields = set(f.name for f in model._meta.fields if isinstance(f, ForeignKey) and f.rel.to == s_model if f.rel.to) if not fields: # the collector pulls in the self reference, so if it's our model # we actually assume it's probably not related to itself, and its # perfectly ok if model == s_model: continue raise TypeError('Unable to determine related keys on %r' % model) for obj in objects: send_signals = not model._meta.auto_created # find fields which need changed update_kwargs = {} for f_name in fields: if getattr(obj, f_name) == self: update_kwargs[f_name] = other if not update_kwargs: # as before, if we're referencing ourself, this is ok if obj == self: continue raise ValueError('Mismatched row present in related results') signal_kwargs = { 'sender': model, 'instance': obj, 'using': using, 'migrated': True, } if send_signals: pre_delete.send(**signal_kwargs) post_delete.send(**signal_kwargs) for k, v in six.iteritems(update_kwargs): setattr(obj, k, v) if send_signals: pre_save.send(created=True, **signal_kwargs) try: with transaction.atomic(using=using): model.objects.using(using).filter(pk=obj.pk).update( **update_kwargs) except IntegrityError: # duplicate key exists, destroy the relations model.objects.using(using).filter(pk=obj.pk).delete() if send_signals: post_save.send(created=True, **signal_kwargs)
def archive(self, *args, **kwargs): pre_delete.send(sender=Contact, instance=self, using='default') super(Contact, self).archive(*args, **kwargs)
def deactivate_signal(self): # sends a signal to deactivate user and remove partnerstaffmember link pre_delete.send(PartnerStaffMember, instance=self)
def redirect_pre_delete(sender, signal=None, *args, **kwargs): pre_delete.send(BaseGroup, *args, **kwargs)
def merge_into(self, other, callback=lambda x: x, using='default'): """ Collects objects related to ``self`` and updates their foreign keys to point to ``other``. If ``callback`` is specified, it will be executed on each collected chunk before any changes are made, and should return a modified list of results that still need updated. NOTE: Duplicates (unique constraints) which exist and are bound to ``other`` are preserved, and relations on ``self`` are discarded. """ # TODO: proper support for database routing s_model = type(self) # Find all the objects than need to be deleted. collector = EverythingCollector(using=using) collector.collect([self]) for model, objects in collector.data.iteritems(): # find all potential keys which match our type fields = set( f.name for f in model._meta.fields if isinstance(f, ForeignKey) and f.rel.to == s_model if f.rel.to ) if not fields: # the collector pulls in the self reference, so if it's our model # we actually assume it's probably not related to itself, and its # perfectly ok if model == s_model: continue raise TypeError('Unable to determine related keys on %r' % model) for obj in objects: send_signals = not model._meta.auto_created # find fields which need changed update_kwargs = {} for f_name in fields: if getattr(obj, f_name) == self: update_kwargs[f_name] = other if not update_kwargs: # as before, if we're referencing ourself, this is ok if obj == self: continue raise ValueError('Mismatched row present in related results') signal_kwargs = { 'sender': model, 'instance': obj, 'using': using, 'migrated': True, } if send_signals: pre_delete.send(**signal_kwargs) post_delete.send(**signal_kwargs) for k, v in update_kwargs.iteritems(): setattr(obj, k, v) if send_signals: pre_save.send(created=True, **signal_kwargs) try: with transaction.atomic(): model.objects.using(using).filter(pk=obj.pk).update(**update_kwargs) except IntegrityError: # duplicate key exists, destroy the relations model.objects.using(using).filter(pk=obj.pk).delete() if send_signals: post_save.send(created=True, **signal_kwargs)
def delete(self): pre_delete.send(sender=self.__class__, instance=self) self.is_deleted = True self.save() post_delete.send(sender=self.__class__, instance=self)
def redirect_pre_delete(sender, signal=None, *args, **kwargs): pre_delete.send(BaseUser, *args, **kwargs)
def on_model_pre_delete(self, model, instance): model_cls, django_instance = self.get_django_instance(model, instance) pre_delete.send(model_cls, using=self, instance=django_instance) self.pre_delete_django_instance = django_instance
def timedtask_delete_change(instance, **kwargs): instance.no_changes = False pre_delete.send(sender=PeriodicTask, instance=instance)
def delete(self, *args, **kwargs): pre_delete.send(sender=self.__class__, instance=self) self.deleted_at = now() self.__class__.objects.filter(id=self.id).update( deleted_at=self.deleted_at, ) post_delete.send(sender=self.__class__, instance=self)
def delete(self, *args, **kwargs): pre_delete.send(sender=Contact, instance=self, using='default') self.archived_on = datetime.now() self.primary_contact.clear() self.save()