當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。