dddp/accounts/ddp.py
def get_username(self, user):
        """Retrieve username from user selector."""
        if isinstance(user, basestring):
            return user
        elif isinstance(user, dict) and len(user) == 1:
            [(key, val)] = user.items()
            if key == 'username' or (key == self.user_model.USERNAME_FIELD):
                # username provided directly
                return val
            elif key in ('email', 'emails.address'):
                email_field = getattr(self.user_model, 'EMAIL_FIELD', 'email')
                if self.user_model.USERNAME_FIELD == email_field:
                    return val  # email is username
                # find username by email
                return self.user_model.objects.values_list(
                    self.user_model.USERNAME_FIELD, flat=True,
                ).get(**{email_field: val})
            elif key in ('id', 'pk'):
                # find username by primary key (ID)
                return self.user_model.objects.values_list(
                    self.user_model.USERNAME_FIELD, flat=True,
                ).get(
                    pk=val,
                )
            else:
                raise MeteorError(400, 'Invalid user lookup: %r' % key)
        else:
            raise MeteorError(400, 'Invalid user expression: %r' % user)
def get_username(self, user):
        """Retrieve username from user selector."""
        if isinstance(user, basestring):
            return user
        elif isinstance(user, dict) and len(user) == 1:
            [(key, val)] = user.items()
            if key == 'username' or (key == self.user_model.USERNAME_FIELD):
                # username provided directly
                return val
            elif key in ('email', 'emails.address'):
                email_field = getattr(self.user_model, 'EMAIL_FIELD', 'email')
                if self.user_model.USERNAME_FIELD == email_field:
                    return val  # email is username
                # find username by email
                return self.user_model.objects.values_list(
                    self.user_model.USERNAME_FIELD, flat=True,
                ).get(**{email_field: val})
            elif key in ('id', 'pk'):
                # find username by primary key (ID)
                return self.user_model.objects.values_list(
                    self.user_model.USERNAME_FIELD, flat=True,
                ).get(
                    pk=val,
                )
            else:
                raise MeteorError(400, 'Invalid user lookup: %r' % key)
        else:
            raise MeteorError(400, 'Invalid user expression: %r' % user)
def get_username ( self , user ) : if isinstance ( user , basestring ) : return user elif isinstance ( user , dict ) and len ( user ) == 1 : [ ( key , val ) ] = user . items ( ) if key == 'username' or ( key == self . user_model . USERNAME_FIELD ) : # username provided directly return val elif key in ( 'email' , 'emails.address' ) : email_field = getattr ( self . user_model , 'EMAIL_FIELD' , 'email' ) if self . user_model . USERNAME_FIELD == email_field : return val # email is username # find username by email return self . user_model . objects . values_list ( self . user_model . USERNAME_FIELD , flat = True , ) . get ( * * { email_field : val } ) elif key in ( 'id' , 'pk' ) : # find username by primary key (ID) return self . user_model . objects . values_list ( self . user_model . USERNAME_FIELD , flat = True , ) . get ( pk = val , ) else : raise MeteorError ( 400 , 'Invalid user lookup: %r' % key ) else : raise MeteorError ( 400 , 'Invalid user expression: %r' % user )
Retrieve username from user selector.
Retrieve username from user selector .