def send_authorization_emails(sender, instance, **kwargs): """ When access code objects are updated, check if they should trigger an email to a user. """ # The AccessCode should already exist, don't trigger on code creation. if instance.id: orig_code = AccessCode.objects.get(pk=instance.id) # If this code is having an authorization added where it didn't # have one before, we've probably just finalised an application # and therefore want to send an email. if not orig_code.authorization and instance.authorization: mail_instance = MagicMailBuilder() email = mail_instance.access_code_email( instance.authorization.user.email, { "editor_wp_username": instance.authorization.user.editor.wp_username, "lang": instance.authorization.user.userprofile.lang, "partner": instance.partner, "access_code": instance.code, "user_instructions": instance.partner.user_instructions, }, ) email.send()
def send_authorization_emails(sender, instance, **kwargs): """ When access code objects are updated, check if they should trigger an email to a user. """ # The AccessCode should already exist, don't trigger on code creation. if instance.id: orig_code = AccessCode.objects.get(pk=instance.id) # If this code is having an authorization added where it didn't # have one before, we've probably just finalised an application # and therefore want to send an email. if not orig_code.authorization and instance.authorization: base_url = get_current_site(None).domain user_instructions = instance.partner.user_instructions mail_instance = MagicMailBuilder() email = mail_instance.access_code_email( instance.authorization.authorized_user.email, { 'editor_wp_username': instance.authorization.authorized_user.editor.wp_username, 'partner': instance.partner, 'access_code': instance.code, 'user_instructions': user_instructions }) email.send()