Exemplo n.º 1
0
def validate_username(username):
    if username in Es.names():
        raise forms.ValidationError(_('Gebruikersnaam is al in gebruik'))
    if any([c not in settings.USERNAME_CHARS for c in username]):
        raise forms.ValidationError(
            _('Gebruikersnaam bevat een niet-toegestane letter'))
    if not reserved.allowed(username):
        raise forms.ValidationError(_('Gebruikersnaam is niet toegestaan'))
Exemplo n.º 2
0
def validate_username(username):
    if username in Es.names():
        raise forms.ValidationError(_('Gebruikersnaam is al in gebruik'))
    if any(map(lambda c: c not in settings.USERNAME_CHARS, username)):
        raise forms.ValidationError(
                _('Gebruikersnaam bevat een niet-toegestane letter'))
    if not reserved.allowed(username):
        raise forms.ValidationError(_('Gebruikersnaam is niet toegestaan'))
Exemplo n.º 3
0
def find_name_for_user(first_name, last_name):
    """ Given the first and the last name of a user, find a free name """
    def clean(s, last_name=False, capitalize_tussenvoegsels=False):
        """ Cleans a first or last name.  We do some extra things for last
            names and optionally capitalize letters that came
            from tussenvoegsels. """
        if last_name and ',' in s:
            bits = s.split(',', 2)
            s = bits[1] + ' ' + bits[0]
        s = unidecode.unidecode(s).lower()
        s = ''.join((x for x in s if x in settings.USERNAME_CHARS))
        if last_name:
            s = s.replace('van ', 'V ')
            s = s.replace('der ', 'D ')
            s = s.replace('de ', 'D ')
            s = s.replace('den ', 'D ')
            if not capitalize_tussenvoegsels:
                s = s.lower()
        return s.replace(' ', '')

    names = Es.names()
    fn = clean(first_name)
    ln_ctv = clean(last_name, last_name=True, capitalize_tussenvoegsels=True)
    ln = clean(last_name, last_name=True)
    # Others users with this firstname
    users_with_same_fn = [
        u for u in Es.users() if u.first_name and clean(u.first_name) == fn
    ]
    # Try first_name or first_name with a few letters of the last_name appended
    for i in range(len(ln) + 1):
        n = fn + ln[:i]
        # Don't try giedov, but directly giedovdm if the name is derived
        # from `Giedo van der Meer'.
        if i and ln_ctv[:i][-1].isupper():
            continue
        if n in names:
            continue
        # Recall `Giedo Jansen' has the username `giedo'.  Suppose there is
        # a new member called `Giedo Joosten'. In this case we want to give
        # him the username `giedojo' instead of `giedoj'.
        ok = True
        for u in users_with_same_fn:
            un = clean(u.first_name) + clean(u.last_name, last_name=True)
            if un.startswith(n):
                ok = False
                break
        if ok:
            return n
    # Last resort: try <first_name><last_name><i> for i in {2,3,...}
    i = 1
    while True:
        i += 1
        n = fn + ln + str(i)
        if n not in names:
            return n
Exemplo n.º 4
0
def find_name_for_user(first_name, last_name):
    """ Given the first and the last name of a user, find a free name """
    def clean(s, last_name=False, capitalize_tussenvoegsels=False):
        """ Cleans a first or last name.  We do some extra things for last
            names and optionally capitalize letters that came
            from tussenvoegsels. """
        if last_name and ',' in s:
            bits  = s.split(',', 2)
            s = bits[1] + ' ' + bits[0]
        s = unidecode.unidecode(s).lower()
        s = filter(lambda x: x in settings.USERNAME_CHARS + ' ', s)
        if last_name:
            s = s.replace('van ', 'V ')
            s = s.replace('der ', 'D ')
            s = s.replace('de ', 'D ')
            s = s.replace('den ', 'D ')
            if not capitalize_tussenvoegsels:
                s = s.lower()
        return s.replace(' ', '')

    names = Es.names()
    fn = clean(first_name)
    ln_ctv = clean(last_name, last_name=True, capitalize_tussenvoegsels=True)
    ln = clean(last_name, last_name=True)
    # Others users with this firstname
    users_with_same_fn = [u for u in Es.users() if u.first_name
                                and clean(u.first_name) == fn]
    # Try first_name or first_name with a few letters of the last_name appended
    for i in xrange(len(ln)+1):
        n = fn + ln[:i]
        # Don't try giedov, but directly giedovdm if the name is derived
        # from `Giedo van der Meer'.
        if i and ln_ctv[:i][-1].isupper():
            continue
        if n in names:
            continue
        # Recall `Giedo Jansen' has the username `giedo'.  Suppose there is
        # a new member called `Giedo Joosten'. In this case we want to give
        # him the username `giedojo' instead of `giedoj'.
        ok = True
        for u in users_with_same_fn:
            un = clean(u.first_name) + clean(u.last_name, last_name=True)
            if un.startswith(n):
                ok = False
                break
        if ok:
            return n
    # Last resort: try <first_name><last_name><i> for i in {2,3,...}
    i = 1
    while True:
        i += 1
        n = fn + ln + str(i)
        if n not in names:
            return n
Exemplo n.º 5
0
def find_name_for_user(first_name, last_name):
    """ Given the first and the last name of a user, find a free name """
    names = Es.names()

    def clean(s):
        return filter(lambda x: x in settings.USERNAME_CHARS, s.lower())

    def clean_ln(s):
        if ',' in s:
            bits = s.split(',', 2)
            s = bits[1] + ' ' + bits[0]
        s = s.lower()
        s = s.replace('van ', 'v ')
        s = s.replace('de ', 'd ')
        s = s.replace('der ', 'd ')
        s = s.replace('den ', 'd ')
        return clean(s)

    fn = clean(first_name)
    ln = clean_ln(last_name)
    users = [
        u for u in Es.users() if u.first_name and clean(u.first_name) == fn
    ]
    # First, simply try the first_name.  This is OK if the name is not taken
    # and there is noone else with that first_name.
    if fn not in names and len(users) == 0:
        return fn
    # Try first_name with a few letters of last_name.
    for i in xrange(len(ln)):
        n = fn + ln[:i + 1]
        if n in names:
            continue
        ok = True
        for u in users:
            un = clean(u.first_name) + clean_ln(u.last_name)
            if un.startswith(n):
                ok = False
                break
        if ok:
            return n
    # Try <first_name><last_name><i> for i in {2,3,...}
    i = 1
    while True:
        i += 1
        n = fn + ln + str(i)
        if n not in names:
            return n
Exemplo n.º 6
0
def find_name_for_user(first_name, last_name):
    """ Given the first and the last name of a user, find a free name """
    names = Es.names()
    def clean(s):
        return filter(lambda x: x in settings.USERNAME_CHARS, s.lower())
    def clean_ln(s):
        if ',' in s:
            bits  = s.split(',',2)
            s = bits[1] + ' ' + bits[0]
        s = s.lower()
        s = s.replace('van ', 'v ')
        s = s.replace('de ', 'd ')
        s = s.replace('der ', 'd ')
        s = s.replace('den ', 'd ')
        return clean(s)
    fn = clean(first_name)
    ln = clean_ln(last_name)
    users = [u for u in Es.users() if u.first_name
                        and clean(u.first_name) == fn]
    # First, simply try the first_name.  This is OK if the name is not taken
    # and there is noone else with that first_name.
    if fn not in names and len(users) == 0:
        return fn
    # Try first_name with a few letters of last_name.
    for i in xrange(len(ln)):
        n = fn + ln[:i+1]
        if n in names:
            continue
        ok = True
        for u in users:
            un = clean(u.first_name) + clean_ln(u.last_name)
            if un.startswith(n):
                ok = False
                break
        if ok:
            return n
    # Try <first_name><last_name><i> for i in {2,3,...}
    i = 1
    while True:
        i += 1
        n = fn + ln + str(i)
        if n not in names:
            return n