Search code examples
pythondjangomezzanine

Can Mezzanine send an email to admin when a user signs up?


Is there any way to configure Mezzanine so that the admin user gets an email when a new (regular) user signs up? I have ACCOUNTS_VERIFICATION_REQUIRED=True, so the would-be user gets an email, but I don't want to have to approve accounts myself (ACCOUNTS_APPROVAL_REQUIRED).

If this isn't possible out of the box, do I need to customize the accounts app? Or monkey-patch UserProfileAdmin.save_model? What is the best approach?


Solution

  • For the sake of closure, here is the solution I was more or less handed from Steve MacDonald himself on the mezzanine-users mailing list. The setting ACCOUNTS_PROFILE_FORM_CLASS allows one to specify a custom form class for user profile signup/update. So, in settings.py set:

    ACCOUNTS_PROFILE_FORM_CLASS = "myapp.forms.MyCustomProfileForm"
    

    And in myapp.forms.py send the email on save:

    from mezzanine.accounts.forms import ProfileForm
    
    class MyCustomProfileForm(ProfileForm):
        def save(self, *args, **kwargs):
            user = super(MyCustomProfileForm, self).save(*args, **kwargs)
            if self._signup:
                # send email here
            return user
    

    This worked very well for me.