当前位置: 首页>>代码示例>>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;未经允许,请勿转载。