当前位置: 首页>>代码示例>>Python>>正文


Python models.signals方法代码示例

本文整理汇总了Python中django.db.models.signals方法的典型用法代码示例。如果您正苦于以下问题:Python models.signals方法的具体用法?Python models.signals怎么用?Python models.signals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.db.models的用法示例。


在下文中一共展示了models.signals方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ctl_signals

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import signals [as 别名]
def ctl_signals(request,cmd):
    """utility view to control and debug signals"""
    from rdf_io.signals import setup_signals,list_pubs,sync_signals
    if cmd == 'on':
        msg = auto_on()
    elif cmd == 'off' :
        msg = auto_off()
    elif cmd == 'list' :
        msg = list_pubs()
    elif cmd == 'sync' :
        msg = sync_signals()
    elif cmd == 'help' :
        msg = "usage /rdf_io/ctl_signals/(on|off|list|sync|help)"
    else:
        msg = "Command %s not understood. Use /rdf_io/ctl_signals/help for valid commands" % cmd
    return HttpResponse(msg, status=200) 
开发者ID:rob-metalinkage,项目名称:django-rdf-io,代码行数:18,代码来源:manage.py

示例2: list_pubs

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import signals [as 别名]
def list_pubs():
#    import pdb; pdb.set_trace()
    import weakref
    msg = []
    for receiver in signals.post_save.receivers:
        (receiver_class_name,_), receiver = receiver
        # django.contrib.contenttypes.generic.GenericForeignKey.instance_pre_init is not weakref
        if isinstance(receiver, weakref.ReferenceType):
            receiver = receiver()
        receiver = getattr(receiver, '__wraps__', receiver)
        receiver_name = getattr(receiver, '__name__', str(receiver))
        text = "%s.%s" % (receiver_class_name, receiver_name)
        if receiver_name == 'publish_rdf' :
            msg.append(text)

    return str(msg) 
开发者ID:rob-metalinkage,项目名称:django-rdf-io,代码行数:18,代码来源:utils.py

示例3: register

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import signals [as 别名]
def register(self, serializer):
        """Store the serializer and model on registry to that the cache can be
        cleaned whenever an object is changed or deleted.
        After the serializer is registered we must connect the signals that
        clear the instance cache.
        """
        model = serializer.Meta.model

        if model not in self._registry:
            self._registry[model] = []

        if serializer in self._registry[model]:
            raise AlreadyRegistered("Serializer {} is already registered"
                                    .format(model.__name__))

        self._registry[model].append(serializer)
        self.connect_signals(model) 
开发者ID:Onyo,项目名称:django-rest-framework-cache,代码行数:19,代码来源:registry.py

示例4: setUp

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import signals [as 别名]
def setUp(self):
        # Inert signals before setup begins
        with mock.patch(MODULE_PATH + '.signals.trigger_all_ts_update') as trigger_all_ts_update:
            self.member = 'member_user'
            member = AuthUtils.create_member(self.member)
            Teamspeak3User.objects.create(user=member, uid=self.member, perm_key='123ABC')
            self.none_user = 'none_user'
            AuthUtils.create_user(self.none_user)
            state = member.profile.state
            ts_member_group = TSgroup.objects.create(ts_group_id=1, ts_group_name='Member')
            ts_state_group = TSgroup.objects.create(ts_group_id=2, ts_group_name='State')
            m2m_member_group = AuthTS.objects.create(auth_group=member.groups.all()[0])
            m2m_member_group.ts_group.add(ts_member_group)
            m2m_member_group.save()
            StateGroup.objects.create(state=state, ts_group=ts_state_group)
            self.service = Teamspeak3Service
            add_permissions() 
开发者ID:allianceauth,项目名称:allianceauth,代码行数:19,代码来源:tests.py

示例5: check_model_signals

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import signals [as 别名]
def check_model_signals(app_configs=None, **kwargs):
    """
    Ensure lazily referenced model signals senders are installed.
    """
    # Avoid circular import
    from django.db import models

    errors = []
    for name in dir(models.signals):
        obj = getattr(models.signals, name)
        if isinstance(obj, models.signals.ModelSignal):
            for reference, receivers in obj.unresolved_references.items():
                for receiver, _, _ in receivers:
                    # The receiver is either a function or an instance of class
                    # defining a `__call__` method.
                    if isinstance(receiver, types.FunctionType):
                        description = "The '%s' function" % receiver.__name__
                    else:
                        description = "An instance of the '%s' class" % receiver.__class__.__name__
                    errors.append(
                        Error(
                            "%s was connected to the '%s' signal "
                            "with a lazy reference to the '%s' sender, "
                            "which has not been installed." % (
                                description, name, '.'.join(reference)
                            ),
                            obj=receiver.__module__,
                            hint=None,
                            id='signals.E001'
                        )
                    )
    return errors 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:34,代码来源:model_checks.py

示例6: send_signal

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import signals [as 别名]
def send_signal(self, model, instances, signal_type):
        '''
        Handle pre/post delete/save signal callings
        '''
        if not model._meta.auto_created:
            for obj in instances:
                if signal_type.__contains__('save'):
                    getattr(signals, signal_type).send(
                            sender=model, instance=obj,
                            created=False, using=self.using
                    )
                else:
                    getattr(signals, signal_type).send(
                            sender=model, instance=obj, using=self.using
                    ) 
开发者ID:exploreshaifali,项目名称:django-softdelete-it,代码行数:17,代码来源:models.py

示例7: initial_signals

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import signals [as 别名]
def initial_signals():
    for signal in Signal.objects.filter(is_active=True):
        def_signal = getattr(signals, signal.signal)
        def_signal.connect(
            signal_receiver, sender=signal.model.model_class(),
            dispatch_uid=signal.model.name
        ) 
开发者ID:LPgenerator,项目名称:django-db-mailer,代码行数:9,代码来源:signals.py

示例8: auto_on

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import signals [as 别名]
def auto_on():
    """turn Auto push signals on"""
    from rdf_io.signals import setup_signals,list_pubs
    signals.post_save.connect(setup_signals, sender=ObjectMapping)
    return list_pubs() 
开发者ID:rob-metalinkage,项目名称:django-rdf-io,代码行数:7,代码来源:manage.py

示例9: auto_off

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import signals [as 别名]
def auto_off():
    """turn off all Auto push signals on"""
    from rdf_io.signals import clear_signals
    return clear_signals() 
开发者ID:rob-metalinkage,项目名称:django-rdf-io,代码行数:6,代码来源:manage.py

示例10: sync_signals

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import signals [as 别名]
def sync_signals():
    """For each ObjectMapping force signal to be added or removed"""
    mappedObj = ObjectMapping.objects.all()
    for objmapping in mappedObj:
        _setup(objmapping)
    return "synced RDf publishing signals" 
开发者ID:rob-metalinkage,项目名称:django-rdf-io,代码行数:8,代码来源:utils.py

示例11: _setup

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import signals [as 别名]
def _setup(objmapping) :
    try:
        if objmapping.auto_push :
            ct = ContentType.objects.get(id = objmapping.content_type_id).model_class()
            signals.post_save.connect(publish_rdf, sender=ct, dispatch_uid=str(ct.__name__))
            print("RDF publishing configured for model {}".format((ct)))
            logger.info(
                "RDF publishing configured for model {}".format((ct)))
    except Exception as e:
        print("Error trying to set up auto-publish for object mapping.. %s " % e)
        pass 
开发者ID:rob-metalinkage,项目名称:django-rdf-io,代码行数:13,代码来源:utils.py

示例12: _clear

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import signals [as 别名]
def _clear(objmapping) :
    try:
        if objmapping.auto_push :
            ct = ContentType.objects.get(id = objmapping.content_type_id).model_class()
            signals.post_save.disconnect(publish_rdf, sender=ct, dispatch_uid=str(ct.__name__))
            print("RDF publishing un-configured for model {}".format((ct)))
            logger.info(
                "RDF publishing un-configured for model {}".format((ct)))
    except Exception as e:
        print("Error trying to clear auto-publish for object mapping.. %s " % e)
        pass 
开发者ID:rob-metalinkage,项目名称:django-rdf-io,代码行数:13,代码来源:utils.py

示例13: connect_signals

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import signals [as 别名]
def connect_signals(self, model):
        from .signals import clear_instance # NOQA - Prevent circular import

        signals.post_save.connect(clear_instance, sender=model)
        signals.pre_delete.connect(clear_instance, sender=model) 
开发者ID:Onyo,项目名称:django-rest-framework-cache,代码行数:7,代码来源:registry.py

示例14: ready

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import signals [as 别名]
def ready(self) -> None:
        """Validate config and connect signals."""
        super(ElasticAppConfig, self).ready()
        _validate_config(bool(settings.get_setting("strict_validation")))
        _connect_signals() 
开发者ID:yunojuno,项目名称:elasticsearch-django,代码行数:7,代码来源:apps.py

示例15: _connect_signals

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import signals [as 别名]
def _connect_signals() -> None:
    """Connect up post_save, post_delete signals for models."""
    for index in settings.get_index_names():
        for model in settings.get_index_models(index):
            _connect_model_signals(model) 
开发者ID:yunojuno,项目名称:elasticsearch-django,代码行数:7,代码来源:apps.py


注:本文中的django.db.models.signals方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。