Exemplo n.º 1
0
 def test__get_unique_username_not_unique(self):
     self.assertNotEqual(_get_unique_username('customerA'), 'customerA')
Exemplo n.º 2
0
    def get_user(self, email, **kwargs):
        ## normalise the email this is really irritatign django
        email = User.objects.normalize_email(email)

        try:
            user = User.objects.get(email=email, **kwargs)
            is_new = False

        except User.DoesNotExist:
            username = _get_unique_username(username=email.split('@')[0])
            user = User.objects.create(username=username,
                                       email=email,
                                       **kwargs)
            is_new = True

        profile = user.profile

        #
        # Set new users to validated email automaticaly
        #
        if is_new is True:
            profile.validated_email = True
            profile.save(update_fields=['data'])


        #
        # Set the users profile to customer by default to customer
        # unless its overridden
        #
        if is_new is True or 'user_class' not in profile.data:
            logger.info('Is a new User')
            profile.data['user_class'] = 'customer'
            profile.save(update_fields=['data'])

        # setup the name of the user
        update_fields = []

        # and set it if they exist but have no name
        if self.full_name is not None:
            logger.info('Full Name was provided')
            # extract the first and last name
            names = self.full_name.split(' ')

            if user.first_name in [None, '']:
                user.first_name = names[0]
                update_fields.append('first_name')
                logger.info('Updating first_name')

            if user.last_name in [None, '']:
                #
                # Try to account for multi barreled names like Crawford d'Heureuse
                #
                user.last_name = ' '.join(names[1:])
                update_fields.append('last_name')
                logger.info('Updating last_name')

            # save the user model if we have updates
            if update_fields:
                user.save(update_fields=update_fields)

        return is_new, user, profile
Exemplo n.º 3
0
 def test__get_unique_username(self):
     self.assertEqual(_get_unique_username('unique-monkey-nuts'), 'unique-monkey-nuts')