接收数据url和触发信号django

时间:2013-11-17 04:29:14

标签: python django python-2.7

我通过帖子在网址中获取代码,然后从网络服务器接收数据。 通过获取收到的金额,我更新了与模型状态相关的字段。我正在使用信号 无法触发更新字段模型的on_paid()方法。不显示打印件。 URL正确,因为POST和数据即将到来。只有信号没有被解雇 不知道它可能是错的。

signal.py -

from django.dispatch import Signal
from .codes import codes

notification_received = Signal(providing_args=['notification'])
transaction_received = Signal(providing_args=['transaction'])

transaction_waiting = Signal()
transaction_analysis = Signal()
transaction_paid = Signal()
transaction_available = Signal()
transaction_dispute = Signal()
transaction_returned = Signal()
transaction_canceled = Signal()
transaction_unknown = Signal()


def dispatch_transaction(sender, **kwargs):
    transaction = kwargs.pop('transaction')
    status = int(transaction['status'])

signals = {
    codes.waiting: transaction_waiting,
    codes.analysis: transaction_analysis,
    codes.paid: transaction_paid,
    codes.available: transaction_available,
    codes.dispute: transaction_dispute,
    codes.returned: transaction_returned,
    codes.canceled: transaction_canceled
}

signals \
    .get(status, transaction_unknown) \
    .send(sender=None, transaction=transaction)

transaction_received.connect(dispatch_transaction)

model.py

class Pedido(models.Model):
    # .....
    statuspagamento = models.CharField(max_length=35, null=True, blank=True, verbose_name=u"Status do PagSeguro")    


from djpg.signals import transaction_paid

def on_paid(sender, **kwargs):
    transaction = kwargs.pop('transaction')
    p = Pedido.objects.get(reference=transaction['reference'])
    ref = transaction['reference']
    status = transaction['status']
    print "HELLO WORD"
    print "imprimindo p ", p
    # .....

transaction_paid.connect(on_paid)

0 个答案:

没有答案