Example #1
0
    def run_intro(self):
        log.debug('Function Called'
                  ' - organize::Person::run_intro')

        # Attempt to get the primary email that belongs to person
        # Returning from function if failed
        try:
            primary_identifier = PersonIdentifier.objects.get(belongs_to=self, primary_identifier=True,
                                                              identifier_type=PersonIdentifier.EMAIL)
        except PersonIdentifier.DoesNotExist:
            log.debug('Function Error:'
                      ' - organize::Person::run_intro'
                      ' - PersonIdentifier.DoesNotExist')
            return

        # Attempt to get the introduction email to send
        # Returning from function if failed
        try:
            intro_email = NotificationEmail.objects.get(notification_type=NotificationEmail.INTRO)
        except NotificationEmail.DoesNotExist:
            log.debug('Function Error:'
                      ' - organize::Person::run_intro'
                      ' - NotificationEmail.DoesNotExist')
            return

        # Get map for formatting template
        intro_formatting = self.get_formatting()

        # Send email to primary email address, checking mail has been sent correctly
        # True - Run the task for sending email invite
        return send_mail_smtp(primary_identifier.identifier,
                              intro_email.address_from,
                              string.Template(intro_email.subject).safe_substitute(intro_formatting),
                              string.Template(intro_email.body).safe_substitute(intro_formatting))
Example #2
0
    def internal_run_evaluate_email(self, target_profile):
        logger.debug('Function Called'
                     ' - evaluate::EvaluateTemplate::internal_run_evaluate_email')

        target = target_profile.target
        sender = target_profile.controller.sender
        formatting_information = {
            'target_first_name': target.first_name,
            'target_last_name': target.surname,
            'target_full_name': '{} {}'.format(target.first_name,
                                               target.surname),
            'target_token': target_profile.token,
            'sender_first_name': sender.first_name,
            'sender_last_name': sender.last_name,
            'sender_full_name': '{} {}'.format(sender.first_name,
                                               sender.last_name),
        }

        # Attempt to get the primary email that belongs to target
        # Returning from function if failed
        try:
            primary_identifier = PersonIdentifier.objects.get(belongs_to=target, primary_identifier=True,
                                                              identifier_type=PersonIdentifier.EMAIL)
        except PersonIdentifier.DoesNotExist:
            logger.debug('Function Error:'
                         ' - evaluate::EvaluateTemplate::internal_run_evaluate_email'
                         ' - NotificationEmail.DoesNotExist')
            return False

        return send_mail_smtp(primary_identifier.identifier,
                              '{} {} <{}>'.format(sender.first_name, sender.last_name, sender.email_address),
                              Template(self.email_subject).safe_substitute(formatting_information),
                              Template(self.email_body).safe_substitute(formatting_information))
Example #3
0
    def run_invite(self):
        log.debug('Function Called' ' - organize::Person::run_invite')

        # Attempt to get the primary email that belongs to person
        # Returning from function if failed
        try:
            primary_identifier = PersonIdentifier.objects.get(
                belongs_to=self,
                primary_identifier=True,
                identifier_type=PersonIdentifier.EMAIL)
        except PersonIdentifier.DoesNotExist:
            log.debug('Function Error:'
                      ' - organize::Person::run_invite'
                      ' - PersonalIdentifier.DoesNotExist')
            return

        # Create a new user from the primary email address
        user = User.objects.create_user(username=primary_identifier.identifier,
                                        email=primary_identifier.identifier,
                                        password=get_random_string())

        from ava_core.my.models import People
        my_people_object, created = People.objects.update_or_create(
            owner=user, person=self)

        # Attempt to get the introduction email to send
        # Returning from function if failed
        try:
            invite_email = NotificationEmail.objects.get(
                notification_type=NotificationEmail.INVITE)
        except NotificationEmail.DoesNotExist:
            log.debug('Function Error:'
                      ' - organize::Person::run_intro'
                      ' - NotificationEmail.DoesNotExist')
            return

        # Get map for formatting template
        invite_formatting = self.get_formatting()

        # Send email to primary email address, checking mail has been sent correctly
        # True - Run the task for sending email invite
        return send_mail_smtp(
            primary_identifier.identifier, invite_email.address_from,
            string.Template(
                invite_email.subject).safe_substitute(invite_formatting),
            string.Template(
                invite_email.body).safe_substitute(invite_formatting))
Example #4
0
    def internal_run_evaluate_email(self, target_profile):
        logger.debug(
            'Function Called'
            ' - evaluate::EvaluateTemplate::internal_run_evaluate_email')

        target = target_profile.target
        sender = target_profile.controller.sender
        formatting_information = {
            'target_first_name':
            target.first_name,
            'target_last_name':
            target.surname,
            'target_full_name':
            '{} {}'.format(target.first_name, target.surname),
            'target_token':
            target_profile.token,
            'sender_first_name':
            sender.first_name,
            'sender_last_name':
            sender.last_name,
            'sender_full_name':
            '{} {}'.format(sender.first_name, sender.last_name),
        }

        # Attempt to get the primary email that belongs to target
        # Returning from function if failed
        try:
            primary_identifier = PersonIdentifier.objects.get(
                belongs_to=target,
                primary_identifier=True,
                identifier_type=PersonIdentifier.EMAIL)
        except PersonIdentifier.DoesNotExist:
            logger.debug(
                'Function Error:'
                ' - evaluate::EvaluateTemplate::internal_run_evaluate_email'
                ' - NotificationEmail.DoesNotExist')
            return False

        return send_mail_smtp(
            primary_identifier.identifier,
            '{} {} <{}>'.format(sender.first_name, sender.last_name,
                                sender.email_address),
            Template(
                self.email_subject).safe_substitute(formatting_information),
            Template(self.email_body).safe_substitute(formatting_information))
Example #5
0
    def run_invite(self):
        log.debug('Function Called'
                  ' - organize::Person::run_invite')

        # Attempt to get the primary email that belongs to person
        # Returning from function if failed
        try:
            primary_identifier = PersonIdentifier.objects.get(belongs_to=self, primary_identifier=True,
                                                              identifier_type=PersonIdentifier.EMAIL)
        except PersonIdentifier.DoesNotExist:
            log.debug('Function Error:'
                      ' - organize::Person::run_invite'
                      ' - PersonalIdentifier.DoesNotExist')
            return

        # Create a new user from the primary email address
        user = User.objects.create_user(username=primary_identifier.identifier,
                                        email=primary_identifier.identifier,
                                        password=get_random_string())

        from ava_core.my.models import People
        my_people_object, created = People.objects.update_or_create(owner=user, person=self)

        # Attempt to get the introduction email to send
        # Returning from function if failed
        try:
            invite_email = NotificationEmail.objects.get(notification_type=NotificationEmail.INVITE)
        except NotificationEmail.DoesNotExist:
            log.debug('Function Error:'
                      ' - organize::Person::run_intro'
                      ' - NotificationEmail.DoesNotExist')
            return

        # Get map for formatting template
        invite_formatting = self.get_formatting()

        # Send email to primary email address, checking mail has been sent correctly
        # True - Run the task for sending email invite
        return send_mail_smtp(primary_identifier.identifier,
                              invite_email.address_from,
                              string.Template(invite_email.subject).safe_substitute(invite_formatting),
                              string.Template(invite_email.body).safe_substitute(invite_formatting))
Example #6
0
    def run_intro(self):
        log.debug('Function Called' ' - organize::Person::run_intro')

        # Attempt to get the primary email that belongs to person
        # Returning from function if failed
        try:
            primary_identifier = PersonIdentifier.objects.get(
                belongs_to=self,
                primary_identifier=True,
                identifier_type=PersonIdentifier.EMAIL)
        except PersonIdentifier.DoesNotExist:
            log.debug('Function Error:'
                      ' - organize::Person::run_intro'
                      ' - PersonIdentifier.DoesNotExist')
            return

        # Attempt to get the introduction email to send
        # Returning from function if failed
        try:
            intro_email = NotificationEmail.objects.get(
                notification_type=NotificationEmail.INTRO)
        except NotificationEmail.DoesNotExist:
            log.debug('Function Error:'
                      ' - organize::Person::run_intro'
                      ' - NotificationEmail.DoesNotExist')
            return

        # Get map for formatting template
        intro_formatting = self.get_formatting()

        # Send email to primary email address, checking mail has been sent correctly
        # True - Run the task for sending email invite
        return send_mail_smtp(
            primary_identifier.identifier, intro_email.address_from,
            string.Template(
                intro_email.subject).safe_substitute(intro_formatting),
            string.Template(
                intro_email.body).safe_substitute(intro_formatting))