From b63999f3859c8c8b269b68e7e16093bc509453f9 Mon Sep 17 00:00:00 2001 From: BaiJiangjie Date: Tue, 3 Apr 2018 16:28:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9B=E5=BB=BA=E7=94=A8=E6=88=B7=E5=8F=91?= =?UTF-8?q?=E9=80=81=E9=82=AE=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/users/signals_handler.py | 30 ++++++++++++++++++++---------- apps/users/views/user.py | 1 + 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/apps/users/signals_handler.py b/apps/users/signals_handler.py index 9e1abf350..4c6afc663 100644 --- a/apps/users/signals_handler.py +++ b/apps/users/signals_handler.py @@ -2,19 +2,29 @@ # from django.dispatch import receiver -from django.db.models.signals import post_save +# from django.db.models.signals import post_save from common.utils import get_logger -from .models import User +from .signals import post_user_create +# from .models import User logger = get_logger(__file__) -@receiver(post_save, sender=User) -def on_user_created(sender, instance=None, created=False, **kwargs): - if created: - logger.debug("Receive user `{}` create signal".format(instance.name)) - from .utils import send_user_created_mail - logger.info(" - Sending welcome mail ...".format(instance.name)) - if instance.email: - send_user_created_mail(instance) \ No newline at end of file +# @receiver(post_save, sender=User) +# def on_user_created(sender, instance=None, created=False, **kwargs): +# if created: +# logger.debug("Receive user `{}` create signal".format(instance.name)) +# from .utils import send_user_created_mail +# logger.info(" - Sending welcome mail ...".format(instance.name)) +# if instance.email: +# send_user_created_mail(instance) + + +@receiver(post_user_create) +def on_user_create(sender, user=None, **kwargs): + logger.debug("Receive user `{}` create signal".format(user.name)) + from .utils import send_user_created_mail + logger.info(" - Sending welcome mail ...".format(user.name)) + if user.email: + send_user_created_mail(user) diff --git a/apps/users/views/user.py b/apps/users/views/user.py index 84c670370..1d68eb81d 100644 --- a/apps/users/views/user.py +++ b/apps/users/views/user.py @@ -79,6 +79,7 @@ class UserCreateView(AdminUserRequiredMixin, SuccessMessageMixin, CreateView): user = form.save(commit=False) user.created_by = self.request.user.username or 'System' user.save() + post_user_create.send(self.__class__, user=user) return super().form_valid(form)