utils.py 1.3 KB

1234567891011121314151617181920212223242526272829303132
  1. from django.urls import reverse
  2. from django.conf import settings
  3. from djadhere.utils import send_notification
  4. from .models import PaymentUpdate
  5. def notify_payment_update(request, update, old_update=None):
  6. benevole = '%s <%s>' % (request.user.username, request.user.email)
  7. message = 'Bénévole : ' + benevole
  8. message += '\n\nPaiement :\n\n'
  9. try:
  10. last_validated_update = PaymentUpdate.objects.latest('start')
  11. except PaymentUpdate.DoesNotExist:
  12. last_validated_update = None
  13. if old_update:
  14. message += '\t- %s\n' % old_update
  15. message += '\t+ %s\n' % update
  16. subject = 'Mise à jour d’une demande de saisie bancaire'
  17. else:
  18. message += '\t%s\n' % update
  19. subject = 'Nouvelle demande de saisie bancaire'
  20. subject += ' %s %d' % (update.payment.payment_type(), update.payment.payment_object().pk)
  21. base_url = 'https' if request.is_secure() else 'http'
  22. base_url += '://' + request.get_host()
  23. message += '\nVoir : ' + base_url + reverse('admin:banking_recurringpayment_change', args=(update.payment.pk,))
  24. message += '\nDébiteur : ' + base_url + reverse('admin:banking_recurringpayment_debtor', args=(update.payment.pk,))
  25. send_notification(subject, message, settings.PAYMENTS_EMAILS, cc=[benevole])