2012-08-07 18:12:50 +00:00
|
|
|
from notification import models as notification
|
2013-06-03 16:31:39 +00:00
|
|
|
|
2012-05-16 02:47:57 +00:00
|
|
|
from django.dispatch import Signal
|
|
|
|
|
|
|
|
transaction_charged = Signal(providing_args=["transaction"])
|
2012-11-06 19:22:25 +00:00
|
|
|
transaction_failed = Signal(providing_args=["transaction"])
|
|
|
|
transaction_refunded = Signal(providing_args=["transaction"])
|
|
|
|
transaction_disputed = Signal(providing_args=["transaction"])
|
|
|
|
|
2013-08-22 18:30:56 +00:00
|
|
|
pledge_created = Signal(providing_args=["transaction"]) # should really be called "authorization created
|
2012-08-07 02:52:45 +00:00
|
|
|
pledge_modified = Signal(providing_args=["transaction", "up_or_down"])
|
2012-08-07 18:12:50 +00:00
|
|
|
credit_balance_added = Signal(providing_args=["amount"])
|
2012-08-07 02:52:45 +00:00
|
|
|
|
2016-07-24 22:39:36 +00:00
|
|
|
from django.apps import apps
|
2012-08-07 02:52:45 +00:00
|
|
|
from django.db.models.signals import post_save
|
|
|
|
from django.db.utils import DatabaseError
|
|
|
|
from django.contrib.auth.models import User
|
|
|
|
|
|
|
|
# create Credit to associate with User
|
|
|
|
def create_user_objects(sender, created, instance, **kwargs):
|
|
|
|
# use get_model to avoid circular import problem with models
|
2017-07-27 14:33:13 +00:00
|
|
|
# don't create Credit if we are loading fixtures https://stackoverflow.com/a/3500009/7782
|
2012-10-31 18:08:46 +00:00
|
|
|
if not kwargs.get('raw', False):
|
|
|
|
try:
|
2016-07-24 22:39:36 +00:00
|
|
|
Credit = apps.get_model('payment', 'Credit')
|
2012-10-31 18:08:46 +00:00
|
|
|
if created:
|
|
|
|
Credit.objects.create(user=instance)
|
|
|
|
except DatabaseError:
|
|
|
|
# this can happen when creating superuser during syncdb since the
|
|
|
|
# core_wishlist table doesn't exist yet
|
|
|
|
return
|
2012-08-07 02:52:45 +00:00
|
|
|
|
|
|
|
post_save.connect(create_user_objects, sender=User)
|
2012-08-07 18:12:50 +00:00
|
|
|
|
|
|
|
def handle_credit_balance(sender, amount=0, **kwargs):
|
2013-12-13 20:15:35 +00:00
|
|
|
notification.queue([sender.user], "pledge_gift_credit", {
|
2012-08-07 18:12:50 +00:00
|
|
|
'user':sender.user,
|
|
|
|
'amount':amount,
|
|
|
|
'minus_amount':-amount
|
|
|
|
}, True)
|
|
|
|
from regluit.core.tasks import emit_notifications
|
|
|
|
emit_notifications.delay()
|
|
|
|
|
|
|
|
# successful_campaign -> send notices
|
|
|
|
credit_balance_added.connect(handle_credit_balance)
|