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