Just spent some time looking into this - there's actually a setting
ACCOUNTS_PROFILE_FORM_CLASS (
http://mezzanine.jupo.org/docs/configuration.html#accounts-profile-form-class)
which allows you to specify a custom form class for user profile
signup/update. You could override the save method of it and send an email
via that, something like (untested):
# settings.py
ACCOUNTS_PROFILE_FORM_CLASS = "myapp.forms.MyCustomProfileForm"
# myapp.forms.py
from mezzanine.account.forms import ProfileForm
class MyCustomProfileForm(ProfileForm):
def save(self, *args, **kwargs):
user = super(MyCustomProfileForm, self).save(*args, **kwargs)
if self._signup:
# send email
return user
On Thu, Feb 2, 2017 at 10:02 PM, Christian Hill <[email protected]> wrote:
> Unfortunately, I don't think this will work very reliably: the time of
> update and time of creation will be a little bit different, so I can't
> check for strict equality, but the two UserProfile save events occur close
> together, so I can't choose a reliable timedelta to ascertain whether the
> instance is begin saved the first time or the second time. For example, the
> output from
>
> def email_admins_on_new_signup(sender, instance, **kwargs):
> print('created:', instance.profile_created)
> print('updated:', instance.profile_updated)
>
> is:
>
> created: 2017-02-02 10:53:51.575074+00:00
> updated: 2017-02-02 10:53:51.575115+00:00
> created: 2017-02-02 10:53:51.575074+00:00
> updated: 2017-02-02 10:53:51.578555+00:00
>
> A workaround is:
> if not kwargs['created'] and instance.profile_updated -
> instance.profile_created < timedelta(seconds=5):
> # Only send an email if a new UserProfile was created.
> send_signup_alert_email_to_admins(instance)
>
> – i.e. only send the email if the instance save is after initial creation,
> but within 5 seconds of it, but that feels awfully hacky and I'd love a
> better solution.
>
>
> On 2 February 2017 at 03:08, Melvyn Sopacua <[email protected]> wrote:
>
>> On Wednesday 01 February 2017 07:02:30 Christian Hill wrote:
>>
>> > And I don't want
>>
>> > the email sent if the user is simply editing their profile.
>>
>> > Would I be better off customizing the accounts app?
>>
>>
>>
>> Add two fields to your profile:
>>
>> - profile_created: DateTimeField(auto_now_add=True)
>> - profile_updated: DateTimeField(auto_now=True)
>>
>> If they're equal, you send mail.
>>
>>
>>
>> >
>>
>> > On 1 February 2017 at 00:27, Stephen McDonald <[email protected]> wrote:
>>
>> > > On Wed, Feb 1, 2017 at 8:46 AM, Christian Hill <[email protected]>
>> wrote:
>>
>> > >> Presumably UserProfile is saved twice and I'm only picking up the
>>
>> > >> first time, after it's been attached to a user but before the
>>
>> > >> extra data is attached to it.
>>
>> > >
>>
>> > > If that's true, then the signal handler would run each time, which
>>
>> > > means you could then modify it to check for the expected data
>>
>> > > (affiliation) and only send the email then.
>>
>> > >
>>
>> > >
>>
>> > > --
>>
>> > > Stephen McDonald
>>
>> > > http://jupo.org
>>
>> > >
>>
>> > > --
>>
>> > > You received this message because you are subscribed to the Google
>>
>> > > Groups "Mezzanine Users" group.
>>
>> > > To unsubscribe from this group and stop receiving emails from it,
>>
>> > > send an email to [email protected].
>>
>> > > For more options, visit https://groups.google.com/d/optout.
>>
>>
>>
>> --
>>
>> Melvyn Sopacua
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Mezzanine Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> My book, Learning Scientific Programming with Python is published by CUP
> <http://www.cambridge.org/gb/academic/subjects/physics/computational-science-and-modelling/learning-scientific-programming-python?format=PB>
> scipython.com: | @scipython3 <https://twitter.com/scipython3>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Mezzanine Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>
--
Stephen McDonald
http://jupo.org
--
You received this message because you are subscribed to the Google Groups
"Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.