Python django.dispatch.Signal() Examples
The following are 11
code examples of django.dispatch.Signal().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.dispatch
, or try the search function
.
Example #1
Source File: signals.py From django-notifs with MIT License | 6 votes |
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()
Example #2
Source File: signals.py From django-notifs with MIT License | 5 votes |
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())
Example #3
Source File: models.py From FIR with GNU General Public License v3.0 | 5 votes |
def __unicode__(self): return self.name # # Signal receivers #
Example #4
Source File: observer.py From djangochannelsrestframework with MIT License | 5 votes |
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)
Example #5
Source File: backends.py From zulip with Apache License 2.0 | 5 votes |
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__)
Example #6
Source File: signals.py From django-db-mailer with GNU General Public License v2.0 | 5 votes |
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 )
Example #7
Source File: signals.py From django-db-mailer with GNU General Public License v2.0 | 5 votes |
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
Example #8
Source File: signals.py From django-db-mailer with GNU General Public License v2.0 | 5 votes |
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 )
Example #9
Source File: test_documentation.py From byro with Apache License 2.0 | 5 votes |
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 )
Example #10
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
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)
Example #11
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
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)