Skip to main content

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)

Release files for django-weight-sort-signal 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-weight-sort-signal 0.0.3
File Size Uploaded
django-weight-sort-signal-0.0.3.tar.gz 3.6 kB Details

Release files / django-weight-sort-signal-0.0.3.tar.gz

Download URL django-weight-sort-signal-0.0.3.tar.gz
Size 3.6 kB
Tags Source
SHA-256 checksum
How to use checksums
644d9388e9a14d13be428561d0145fe853441180d6a94d79240cc7a046f7d361
BLAKE2b-256 checksum
How to use checksums
daba3478a8b11cacb5d201e2c31e4141cb69cfe7247e43808a01b588905405b3
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

0.0.3 This release

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page