def default_status_check(sender, instance, **kwargs): if not isinstance(instance, OrderPayment): return # Send status change notification when record first created # This is to ensure any components listening for a status # on the Sender will also receive the initial status. # Get the default status for the status field on Sender default_status = StatusDefinition.CREATED from bluebottle.payments_logger.adapters import PaymentLogAdapter # adding a Log when the status changes payment_logger = PaymentLogAdapter() try: # if there is no Payment associated to the order_payment do not log # The log will be created in the adapter payment = Payment.objects.get(order_payment=instance) payment_logger.log(payment, "info", "a new payment status {0}".format(instance.status)) except Payment.DoesNotExist: pass except Payment.MultipleObjectsReturned: payment = Payment.objects.order("-created").filter(order_payment=instance).all()[0] payment_logger.log(payment, "info", "a new payment status {0}".format(instance.status)) finally: # Signal new status if current status is the default value if instance.status == default_status: signal_kwargs = {"sender": sender, "instance": instance, "target": instance.status} post_transition.send(**signal_kwargs)
def default_status_check(sender, instance, **kwargs): if not (isinstance(instance, Payment) or isinstance(instance, OrderPayment)): return # Send status change notification when record first created # This is to ensure any components listening for a status # on the Sender will also receive the initial status. # Get the default status for the status field on Sender default_status = sender._meta.get_field_by_name('status')[0].get_default() from bluebottle.payments_logger.adapters import PaymentLogAdapter # adding a Log when the status changes payment_logger = PaymentLogAdapter() try: # if there is no Payment associated to the order_payment do not log # The log will be created in the adapter payment = Payment.objects.get(order_payment=instance) payment_logger.log(payment, 'info', 'a new payment status {0}'.format(instance.status)) except Payment.DoesNotExist: pass except Payment.MultipleObjectsReturned: payment = Payment.objects.order('-created').filter(order_payment=instance).all()[0] payment_logger.log(payment, 'info', 'a new payment status {0}'.format(instance.status)) finally: # Signal new status if current status is the default value if (instance.status == default_status): signal_kwargs = { 'sender': sender, 'instance': instance, 'target': instance.status } post_transition.send(**signal_kwargs)
def default_status_check(sender, instance, **kwargs): if not isinstance(instance, OrderPayment): return # Send status change notification when record first created # This is to ensure any components listening for a status # on the Sender will also receive the initial status. # Get the default status for the status field on Sender default_status = StatusDefinition.CREATED from bluebottle.payments_logger.adapters import PaymentLogAdapter # adding a Log when the status changes payment_logger = PaymentLogAdapter() try: # if there is no Payment associated to the order_payment do not log # The log will be created in the adapter payment = Payment.objects.get(order_payment=instance) payment_logger.log(payment, 'info', 'a new payment status {0}'.format(instance.status)) except Payment.DoesNotExist: pass except Payment.MultipleObjectsReturned: payment = Payment.objects.order('-created').filter( order_payment=instance).all()[0] payment_logger.log(payment, 'info', 'a new payment status {0}'.format(instance.status)) finally: # Signal new status if current status is the default value if (instance.status == default_status): signal_kwargs = { 'sender': sender, 'instance': instance, 'target': instance.status } post_transition.send(**signal_kwargs)
def test_payment_log_adapter(self): """ Tests the adapter creating different log messages """ payment = self.order_payment.payment payment_logger = PaymentLogAdapter() payment_logger.log(payment=payment, level='ERROR', message='Test Error log') payment_logger.log(payment=payment, level='INFO', message='Test Info log') payment_logger.log(payment=payment, level='WARN', message='Test Warn log') self.assertEqual(3, PaymentLogEntry.objects.all().count())
def test_payment_log_adapter(self): """ Tests the adapter creating different log messages """ payment = self.order_payment.payment payment_logger = PaymentLogAdapter() payment_logger.log(payment=payment, level='ERROR', message='Test Error log') payment_logger.log(payment=payment, level='INFO', message='Test Info log') payment_logger.log(payment=payment, level='WARN', message='Test Warn log') self.assertEqual(3, PaymentLogEntry.objects.all().count())