Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

a guest Apr 6th, 2020 209 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def async_receiver(signal, task_decorator=task, **kwargs):
  2.     """
  3.    @param task_decorator : By default, uses celery's task decorator. Others, like
  4.    django-celery-transactions' (https://github.com/chrisdoble/django-celery-transactions)
  5.    can be substituted.
  6.    """
  7.     def _decorator(func):
  8.         def _with_task(created_task):
  9.             def _call_async(*args, **kwargs):
  10.                 # It's undocumented, but django sends `signal` as a kwarg to receivers.
  11.                 # Signals can't be pickled.
  12.                 try:
  13.                     del kwargs['signal']
  14.                 except KeyError:
  15.                     pass
  16.                 new_kwargs = {}
  17.                 for key, value in kwargs.items():
  18.                     if isinstance(value, models.Model):
  19.                         new_kwargs[key+'_id'] = value.id
  20.                     elif isinstance(value, (bool, str, int, float)):
  21.                         new_kwargs[key] = value
  22.                 return created_task.delay(*args, **new_kwargs)
  23.             signal.connect(_call_async, **kwargs)
  24.             return _call_async
  25.         return _with_task(task_decorator(func))
  26.     return _decorator
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top