From 46522711a5c196287c48d278d5eedab776202380 Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 19 Feb 2018 10:10:36 +0300 Subject: [PATCH] migrate update --- finance/signals.py | 17 +++++++++++++---- lms/settings.py | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/finance/signals.py b/finance/signals.py index 6b88d88..300001d 100644 --- a/finance/signals.py +++ b/finance/signals.py @@ -1,3 +1,4 @@ +from django.contrib.auth import get_user_model from django.core.mail import EmailMessage from django.db.models.signals import pre_save, post_save from django.dispatch import receiver @@ -29,10 +30,18 @@ def invoice_signal(instance, **kwargs): if instance.status == 'F': if instance.is_open: - Progress.objects.get_or_create( - course_token=instance.bill.course_token, - user=instance.bill.user, - ) + try: + Progress.objects.get( + course_token=instance.bill.course_token, + user=instance.bill.user, + ) + except Progress.DoesNotExist: + Progress.objects.create( + course_token=instance.bill.course_token, + user=instance.bill.user, + teacher=get_user_model().objects.get(out_key=course.get_teacher()) + ) + msg = EmailMessage( 'Ваш платёж прошёл успешно', '''Вам открыт доступ к курсу "%s", вы можете перейти по ссылке и diff --git a/lms/settings.py b/lms/settings.py index 3132323..852c54d 100644 --- a/lms/settings.py +++ b/lms/settings.py @@ -124,7 +124,7 @@ MIDDLEWARE_CLASSES = [ REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATION_CLASSES': ( - 'rest_framework.authentication.SessionAuthentication' + 'rest_framework.authentication.SessionAuthentication', ) }