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


Python dispatch.Signal方法代碼示例

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


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

示例1: read_notification

# 需要導入模塊: from django import dispatch [as 別名]
# 或者: from django.dispatch import Signal [as 別名]
def read_notification(**kwargs):
    """
    Mark notification as read.

    Raises NotificationError if the user doesn't have access
    to read the notification
    """
    warnings.warn(
        'The \'read\' Signal will be removed in 2.6.5 '
        'Please use the helper functions in notifications.utils',
        PendingDeprecationWarning
    )

    notify_id = kwargs['notify_id']
    recipient = kwargs['recipient']
    notification = Notification.objects.get(id=notify_id)

    if recipient != notification.recipient:
        raise NotificationError('You cannot read this notification')

    notification.read() 
開發者ID:danidee10,項目名稱:django-notifs,代碼行數:23,代碼來源:signals.py

示例2: create_notification

# 需要導入模塊: from django import dispatch [as 別名]
# 或者: from django.dispatch import Signal [as 別名]
def create_notification(**kwargs):
    """Notify signal receiver."""
    warnings.warn(
        'The \'notify\' Signal will be removed in 2.6.5 '
        'Please use the helper functions in notifications.utils',
        PendingDeprecationWarning
    )

    # make fresh copy and retain kwargs
    params = kwargs.copy()
    del params['signal']
    del params['sender']

    try:
        del params['silent']
    except KeyError:
        pass

    notification = Notification(**params)

    # If it's a not a silent notification, save the notification
    if not kwargs.get('silent', False):
        notification.save()

    # Send the notification asynchronously with celery
    send_notification.delay(notification.to_json()) 
開發者ID:danidee10,項目名稱:django-notifs,代碼行數:28,代碼來源:signals.py

示例3: __unicode__

# 需要導入模塊: from django import dispatch [as 別名]
# 或者: from django.dispatch import Signal [as 別名]
def __unicode__(self):
        return self.name


#
# Signal receivers
# 
開發者ID:certsocietegenerale,項目名稱:FIR,代碼行數:9,代碼來源:models.py

示例4: __init__

# 需要導入模塊: from django import dispatch [as 別名]
# 或者: from django.dispatch import Signal [as 別名]
def __init__(self, func, signal: Signal = None, kwargs=None):
        super().__init__(func)
        if kwargs is None:
            kwargs = {}
        self.signal = signal
        self.signal_kwargs = kwargs
        self._serializer = None
        self.signal.connect(self.handle, **self.signal_kwargs) 
開發者ID:hishnash,項目名稱:djangochannelsrestframework,代碼行數:10,代碼來源:observer.py

示例5: catch_ldap_error

# 需要導入模塊: from django import dispatch [as 別名]
# 或者: from django.dispatch import Signal [as 別名]
def catch_ldap_error(signal: Signal, **kwargs: Any) -> None:
    """
    Inside django_auth_ldap populate_user(), if LDAPError is raised,
    e.g. due to invalid connection credentials, the function catches it
    and emits a signal (ldap_error) to communicate this error to others.
    We normally don't use signals, but here there's no choice, so in this function
    we essentially convert the signal to a normal exception that will properly
    propagate out of django_auth_ldap internals.
    """
    if kwargs['context'] == 'populate_user':
        # The exception message can contain the password (if it was invalid),
        # so it seems better not to log that, and only use the original exception's name here.
        raise PopulateUserLDAPError(kwargs['exception'].__class__.__name__) 
開發者ID:zulip,項目名稱:zulip,代碼行數:15,代碼來源:backends.py

示例6: get_signal_list

# 需要導入模塊: from django import dispatch [as 別名]
# 或者: from django.dispatch import Signal [as 別名]
def get_signal_list(self):
        if not hasattr(self.sender._meta, 'module_name'):
            return Signal.objects.filter(
                model__model=self.sender._meta.model_name,
                is_active=True
            )
        return Signal.objects.filter(
            model__model=self.sender._meta.module_name,
            is_active=True
        ) 
開發者ID:LPgenerator,項目名稱:django-db-mailer,代碼行數:12,代碼來源:signals.py

示例7: run_deferred

# 需要導入模塊: from django import dispatch [as 別名]
# 或者: from django.dispatch import Signal [as 別名]
def run_deferred(self):
        try:
            self.signal = Signal.objects.get(pk=self.signal_pk, is_active=True)
            self.get_current_instance()
            self.send_mail()
        except ObjectDoesNotExist:
            pass 
開發者ID:LPgenerator,項目名稱:django-db-mailer,代碼行數:9,代碼來源:signals.py

示例8: initial_signals

# 需要導入模塊: from django import dispatch [as 別名]
# 或者: from django.dispatch import Signal [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

示例9: test_documentation_includes_signals

# 需要導入模塊: from django import dispatch [as 別名]
# 或者: from django.dispatch import Signal [as 別名]
def test_documentation_includes_signals(app):
    app = "byro." + app.split(".")[1]
    with suppress(ImportError):
        module = importlib.import_module(app + ".signals")
        for key in dir(module):
            attrib = getattr(module, key)
            if isinstance(attrib, Signal):
                assert (
                    key in plugin_docs
                ), "Signal {app}.signals.{key} is not documented!".format(
                    app=app, key=key
                ) 
開發者ID:byro,項目名稱:byro,代碼行數:14,代碼來源:test_documentation.py

示例10: test_cannot_connect_no_kwargs

# 需要導入模塊: from django import dispatch [as 別名]
# 或者: from django.dispatch import Signal [as 別名]
def test_cannot_connect_no_kwargs(self):
        def receiver_no_kwargs(sender):
            pass

        msg = 'Signal receivers must accept keyword arguments (**kwargs).'
        with self.assertRaisesMessage(ValueError, msg):
            a_signal.connect(receiver_no_kwargs)
        self.assertTestIsClean(a_signal) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:10,代碼來源:tests.py

示例11: test_cannot_connect_non_callable

# 需要導入模塊: from django import dispatch [as 別名]
# 或者: from django.dispatch import Signal [as 別名]
def test_cannot_connect_non_callable(self):
        msg = 'Signal receivers must be callable.'
        with self.assertRaisesMessage(AssertionError, msg):
            a_signal.connect(object())
        self.assertTestIsClean(a_signal) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:7,代碼來源:tests.py


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