django signal sorting on weight via Django 2.*
Project description
django weight sort signal
django_weight_sort_signal is change order of Django signals sorting by using weight. its help you weight signal handling with third-party apps also without changing signal class
Installation
#. Install django-weight-sort-signal using pip::
pip install django-weight-sort-signal
Configuration
#. settings.py::
INSTALLED_APPS = [
...
'django_weight_sort_signal',
]
'''
Configuration for third party app signal usage
#. settings.py::
INSTALLED_APPS = [
'django_weight_sort_signal', #django_weight_sort_signal put into top in the INSTALLED_APPS
'django.contrib.admin',
'django.contrib.auth',
...
]
'''
DJANGO_WEIGHT_SORT_SIGNAL ={
'DEFAULT_SIGNAL':True, #its help you weight signal handling with third-party apps without changing signal class
}
Signal
#. signal.py::
from django_weight_sort_signal.dispatcher import WeightSortSignal
order_refresh = WeightSortSignal(providing_args=["order"])
Reciever
In receiver callback we can give weight to sort
#. receiver.py::
from .signals import order_refresh
from django_weight_sort_signal.dispatcher import receiver as weight_sort_receiver
@weight_sort_receiver(order_refresh,weight=10)
def tax_order_refresh(sender,order, **kwargs):
#tax amount calculation functionality triggered on order_refresh signal dispatch
pass
@weight_sort_receiver(order_refresh,weight=20)
def discount_order_refresh(sender,order, **kwargs):
#discount amount calculation functionality triggered on order_refresh signal dispatch
pass
@weight_sort_receiver(order_refresh,weight=30)
def shipping_order_refresh(sender,order, **kwargs):
#shipping amount calculation functionality triggered on order_refresh signal dispatch
pass
Reciever for third-party apps Eg:
In receiver callback we can give weight to sort without changing the base signal
#. receiver.py::
from django.contrib.auth.signals import user_logged_in
def do_stuff(sender, user, request, **kwargs):
#ADD SOME CODE
user_logged_in.connect(do_stuff,weight=10)
def do_stuff2(sender, user, request, **kwargs):
#ADD SOME CODE
user_logged_in.connect(do_stuff2,weight=20)
We can dispatch signal anywhere as following.
Send :
#. ::
from .signals import order_refresh
order = Order.objects.get(pk=10001)
order.status="review"
order.save()
order_refresh.send(sender=None,order=order)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file django-weight-sort-signal-0.0.3.tar.gz.
File metadata
- Download URL: django-weight-sort-signal-0.0.3.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.6.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
644d9388e9a14d13be428561d0145fe853441180d6a94d79240cc7a046f7d361
|
|
| MD5 |
5f55e8e6775893ac2ba6c104ea840303
|
|
| BLAKE2b-256 |
daba3478a8b11cacb5d201e2c31e4141cb69cfe7247e43808a01b588905405b3
|