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


Python signals.post_delete方法代碼示例

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


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

示例1: connect_receivers

# 需要導入模塊: from django.db.models import signals [as 別名]
# 或者: from django.db.models.signals import post_delete [as 別名]
def connect_receivers(self):
        OrganizationUser = load_model('openwisp_users', 'OrganizationUser')
        OrganizationOwner = load_model('openwisp_users', 'OrganizationOwner')
        signal_tuples = [(post_save, 'post_save'), (post_delete, 'post_delete')]

        for model in [OrganizationUser, OrganizationOwner]:
            for signal, name in signal_tuples:
                signal.connect(
                    self.update_organizations_dict,
                    sender=model,
                    dispatch_uid='{}_{}_update_organizations_dict'.format(
                        name, model.__name__
                    ),
                ) 
開發者ID:openwisp,項目名稱:openwisp-users,代碼行數:16,代碼來源:apps.py

示例2: post_delete

# 需要導入模塊: from django.db.models import signals [as 別名]
# 或者: from django.db.models.signals import post_delete [as 別名]
def post_delete(sender, **kwargs):
    send_notification(dict(
        type='post_delete',
        feature=kwargs['instance'].geojson_feature
    )) 
開發者ID:abarto,項目名稱:tracker_project,代碼行數:7,代碼來源:signals.py

示例3: connect

# 需要導入模塊: from django.db.models import signals [as 別名]
# 或者: from django.db.models.signals import post_delete [as 別名]
def connect(self, index):
        """Connect signals needed for dependency updates.

        Pre- and post-delete signals have to be handled separately, as:

          * in the pre-delete signal we have the information which
            objects to rebuild, but affected relations are still
            presented, so rebuild would reflect in the wrong (outdated)
            indices
          * in the post-delete signal indices can be rebuild corectly,
            but there is no information which objects to rebuild, as
            affected relations were already deleted

        To bypass this, list of objects should be stored in the
        pre-delete signal indexing should be triggered in the
        post-delete signal.
        """
        self.index = index

        signal = ElasticSignal(self, "process", pass_kwargs=True)
        signal.connect(post_save, sender=self.model)
        signal.connect(pre_delete, sender=self.model)

        pre_delete_signal = ElasticSignal(self, "process_predelete", pass_kwargs=True)
        pre_delete_signal.connect(pre_delete, sender=self.model)

        post_delete_signal = ElasticSignal(self, "process_delete", pass_kwargs=True)
        post_delete_signal.connect(post_delete, sender=self.model)

        return [signal, pre_delete_signal, post_delete_signal] 
開發者ID:genialis,項目名稱:resolwe,代碼行數:32,代碼來源:builder.py

示例4: _connect_signal

# 需要導入模塊: from django.db.models import signals [as 別名]
# 或者: from django.db.models.signals import post_delete [as 別名]
def _connect_signal(self, index):
        """Create signals for building indexes."""
        post_save_signal = ElasticSignal(index, "build")
        post_save_signal.connect(post_save, sender=index.object_type)
        self.signals.append(post_save_signal)

        post_delete_signal = ElasticSignal(index, "remove_object")
        post_delete_signal.connect(post_delete, sender=index.object_type)
        self.signals.append(post_delete_signal)

        # Connect signals for all dependencies.
        for dependency in index.get_dependencies():
            # Automatically convert m2m fields to dependencies.
            if isinstance(dependency, (models.ManyToManyField, ManyToManyDescriptor)):
                dependency = ManyToManyDependency(dependency)
            elif isinstance(dependency, ReverseManyToOneDescriptor):
                dependency = ReverseManyToOneDependency(dependency)
            elif isinstance(dependency, ForwardManyToOneDescriptor):
                dependency = ForwardManyToOneDependency(dependency)
            elif not isinstance(dependency, Dependency):
                raise TypeError(
                    "Unsupported dependency type: {}".format(repr(dependency))
                )

            signal = dependency.connect(index)
            self.signals.extend(signal) 
開發者ID:genialis,項目名稱:resolwe,代碼行數:28,代碼來源:builder.py

示例5: _manage_signals

# 需要導入模塊: from django.db.models import signals [as 別名]
# 或者: from django.db.models.signals import post_delete [as 別名]
def _manage_signals(self, method):
        if method not in ['connect', 'disconnect']:
            raise ValueError()
        getattr(post_save, method)(self._on_rr_post_save, sender=RR, dispatch_uid=self.__module__)
        getattr(post_delete, method)(self._on_rr_post_delete, sender=RR, dispatch_uid=self.__module__)
        getattr(post_save, method)(self._on_rr_set_post_save, sender=RRset, dispatch_uid=self.__module__)
        getattr(post_delete, method)(self._on_rr_set_post_delete, sender=RRset, dispatch_uid=self.__module__)
        getattr(post_save, method)(self._on_domain_post_save, sender=Domain, dispatch_uid=self.__module__)
        getattr(post_delete, method)(self._on_domain_post_delete, sender=Domain, dispatch_uid=self.__module__) 
開發者ID:desec-io,項目名稱:desec-stack,代碼行數:11,代碼來源:pdns_change_tracker.py

示例6: __init__

# 需要導入模塊: from django.db.models import signals [as 別名]
# 或者: from django.db.models.signals import post_delete [as 別名]
def __init__(self, create=True, update=True, delete=True, custom=None):
        from actionslog.receivers import action_log_create, action_log_update, action_log_delete

        self._registry = {}
        self._signals = {}

        if create:
            self._signals[post_save] = action_log_create
        if update:
            self._signals[pre_save] = action_log_update
        if delete:
            self._signals[post_delete] = action_log_delete

        if custom is not None:
            self._signals.update(custom) 
開發者ID:shtalinberg,項目名稱:django-actions-logger,代碼行數:17,代碼來源:registry.py

示例7: count_resource_accounts

# 需要導入模塊: from django.db.models import signals [as 別名]
# 或者: from django.db.models.signals import post_delete [as 別名]
def count_resource_accounts(signal, instance, **kwargs):
    if signal is post_delete:
        instance.resource.n_accounts -= 1
        instance.resource.save()
    elif signal is post_save and kwargs['created']:
        instance.resource.n_accounts += 1
        instance.resource.save() 
開發者ID:aropan,項目名稱:clist,代碼行數:9,代碼來源:models.py

示例8: count_account_contests

# 需要導入模塊: from django.db.models import signals [as 別名]
# 或者: from django.db.models.signals import post_delete [as 別名]
def count_account_contests(signal, instance, **kwargs):
    if instance.addition.get('_no_update_n_contests'):
        return

    if signal is post_delete:
        instance.account.n_contests -= 1
        instance.account.save()
    elif signal is post_save and kwargs['created']:
        instance.account.n_contests += 1

        if not instance.account.last_activity or instance.account.last_activity < instance.contest.start_time:
            instance.account.last_activity = instance.contest.start_time

        instance.account.save() 
開發者ID:aropan,項目名稱:clist,代碼行數:16,代碼來源:models.py

示例9: get_absolute_file_path

# 需要導入模塊: from django.db.models import signals [as 別名]
# 或者: from django.db.models.signals import post_delete [as 別名]
def get_absolute_file_path(self):
        fsp = local_settings.FILE_STORE_PATH
        if not fsp:
            fsp = ''
        return os.path.join(fsp, self.file.name)


# When a TemporaryUpload record is deleted, we need to delete the
# corresponding file from the filesystem by catching the post_delete signal. 
開發者ID:ImperialCollegeLondon,項目名稱:django-drf-filepond,代碼行數:11,代碼來源:models.py

示例10: delete_temp_upload_file

# 需要導入模塊: from django.db.models import signals [as 別名]
# 或者: from django.db.models.signals import post_delete [as 別名]
def delete_temp_upload_file(sender, instance, **kwargs):
    # Check that the file parameter for the instance is not None
    # and that the file exists and is not a directory! Then we can delete it
    LOG.debug('*** post_delete signal handler called. Deleting file.')
    if instance.file:
        if (os.path.exists(instance.file.path) and
                os.path.isfile(instance.file.path)):
            os.remove(instance.file.path)

    if local_settings.DELETE_UPLOAD_TMP_DIRS:
        file_dir = os.path.join(storage.location, instance.upload_id)
        if(os.path.exists(file_dir) and os.path.isdir(file_dir)):
            os.rmdir(file_dir)
            LOG.debug('*** post_delete signal handler called. Deleting temp '
                      'dir that contained file.') 
開發者ID:ImperialCollegeLondon,項目名稱:django-drf-filepond,代碼行數:17,代碼來源:models.py

示例11: unseed_db

# 需要導入模塊: from django.db.models import signals [as 別名]
# 或者: from django.db.models.signals import post_delete [as 別名]
def unseed_db():
    """
    Deletes all seed data from the database
    """
    fake_program_ids = (
        Program.objects
        .filter(description__startswith=FAKE_PROGRAM_DESC_PREFIX)
        .values_list('id', flat=True)
    )
    fake_user_ids = (
        User.objects
        .filter(username__startswith=FAKE_USER_USERNAME_PREFIX)
        .values_list('id', flat=True)
    )
    fake_tier_ids = (
        TierProgram.objects
        .filter(program__id__in=fake_program_ids)
        .values_list('tier__id', flat=True)
    )
    fake_final_grade_ids = (
        FinalGrade.objects
        .filter(course_run__course__program__id__in=fake_program_ids)
        .values_list('id', flat=True)
    )
    financial_aid_ids = (
        FinancialAid.objects
        .filter(Q(user_id__in=fake_user_ids) | Q(tier_program__program__id__in=fake_program_ids))
        .values_list('id', flat=True)
    )
    fin_aid_audit_models = [FinancialAidAudit, FinancialAidEmailAudit]
    with mute_signals(post_delete):
        with remove_delete_protection(*fin_aid_audit_models):
            for audit_model in fin_aid_audit_models:
                audit_model.objects.filter(financial_aid__id__in=financial_aid_ids).delete()
        for model_cls in [CachedEnrollment, CachedCertificate, CachedCurrentGrade]:
            model_cls.objects.filter(course_run__course__program__id__in=fake_program_ids).delete()
        Tier.objects.filter(id__in=fake_tier_ids).delete()
        FinalGrade.objects.filter(id__in=fake_final_grade_ids).delete()
        Program.objects.filter(id__in=fake_program_ids).delete()
        User.objects.filter(id__in=fake_user_ids).delete() 
開發者ID:mitodl,項目名稱:micromasters,代碼行數:42,代碼來源:unseed_db.py

示例12: delete_large_object

# 需要導入模塊: from django.db.models import signals [as 別名]
# 或者: from django.db.models.signals import post_delete [as 別名]
def delete_large_object(sender, instance, **kwargs):
    """Delete the large object when the `LargeFile` is deleted.

    This is done using the `post_delete` signal instead of overriding delete
    on `LargeFile`, so it works correctly for both the model and `QuerySet`.
    """
    if instance.content is not None:
        post_commit_do(delete_large_object_content_later, instance.content) 
開發者ID:maas,項目名稱:maas,代碼行數:10,代碼來源:largefiles.py

示例13: delete_large_file

# 需要導入模塊: from django.db.models import signals [as 別名]
# 或者: from django.db.models.signals import post_delete [as 別名]
def delete_large_file(sender, instance, **kwargs):
    """Call delete on the LargeFile, now that the relation has been removed.
    If this was the only resource file referencing this LargeFile then it will
    be delete.

    This is done using the `post_delete` signal because only then has the
    relation been removed.
    """
    try:
        largefile = instance.largefile
    except LargeFile.DoesNotExist:
        pass  # Nothing to do.
    else:
        if largefile is not None:
            largefile.delete() 
開發者ID:maas,項目名稱:maas,代碼行數:17,代碼來源:bootresourcefiles.py

示例14: pre_delete_bmc_clean_orphaned_ip

# 需要導入模塊: from django.db.models import signals [as 別名]
# 或者: from django.db.models.signals import post_delete [as 別名]
def pre_delete_bmc_clean_orphaned_ip(sender, instance, **kwargs):
    """Stash the soon-to-be-deleted BMC's ip_address for use in post_delete."""
    instance.__previous_ip_address = instance.ip_address 
開發者ID:maas,項目名稱:maas,代碼行數:5,代碼來源:bmc.py

示例15: make_visibility_receivers

# 需要導入模塊: from django.db.models import signals [as 別名]
# 或者: from django.db.models.signals import post_delete [as 別名]
def make_visibility_receivers(for_sender, field_name, visibility_model):
    """
    Creates signal receivers for watched models. Must be defered because models
    do not become available until after the app is readied.
    - for_sender: the watched model.
    - field_name: the visibility field within the model.
    - visibility_model: the specific model according to the type of data.
    """
    uid = '{}--{}'.format(for_sender, field_name)
    foreign_key = '{}_id'.format(field_name)

    @receiver(signals.pre_save, sender=for_sender, weak=False, dispatch_uid=uid)
    def hosting_model_pre_save(sender, **kwargs):
        """
        Creates a new specific visibility object directly in database,
        if one does not yet exist.
        """
        if kwargs['raw'] or getattr(kwargs['instance'], foreign_key) is not None:
            return
        setattr(kwargs['instance'], field_name, visibility_model.prep())

    @receiver(signals.post_save, sender=for_sender, weak=False, dispatch_uid=uid)
    def hosting_model_post_save(sender, **kwargs):
        """
        Links the specific visibility object to the newly created model
        instance. If the instance already has linkage, nothing happens.
        """
        if kwargs['raw']:
            return
        instance = kwargs['instance']
        visibility_model.objects.filter(
            id=getattr(instance, foreign_key), model_id__isnull=True,
        ).update(model_id=instance.pk)

    @receiver(signals.post_delete, sender=for_sender, weak=False, dispatch_uid=uid)
    def hosting_model_post_delete(sender, **kwargs):
        """
        Deletes the visibility object linked to the watched model instance.
        """
        visibility_model.objects.filter(
            id=getattr(kwargs['instance'], foreign_key),
        ).delete() 
開發者ID:tejoesperanto,項目名稱:pasportaservo,代碼行數:44,代碼來源:apps.py


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