当前位置: 首页>>代码示例>>Python>>正文


Python UserSocialAuth.username_max_length方法代码示例

本文整理汇总了Python中social_auth.models.UserSocialAuth.username_max_length方法的典型用法代码示例。如果您正苦于以下问题:Python UserSocialAuth.username_max_length方法的具体用法?Python UserSocialAuth.username_max_length怎么用?Python UserSocialAuth.username_max_length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在social_auth.models.UserSocialAuth的用法示例。


在下文中一共展示了UserSocialAuth.username_max_length方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_username

# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import username_max_length [as 别名]
def get_username(details, user=None,
                 user_exists=UserSocialAuth.simple_user_exists,
                 *args, **kwargs):
    """Return an username for new user. Return current user username
    if user was given.
    """
    if user:
        return {'username': user.username}

    if details.get(USERNAME):
        username = unicode(details[USERNAME])
    else:
        username = uuid4().get_hex()

    uuid_length = setting('SOCIAL_AUTH_UUID_LENGTH', 16)
    max_length = UserSocialAuth.username_max_length()
    short_username = username[:max_length - uuid_length]
    final_username = UserSocialAuth.clean_username(username[:max_length])

    # Generate a unique username for current user using username
    # as base but adding a unique hash at the end. Original
    # username is cut to avoid any field max_length.
    while user_exists(username=final_username):
        username = short_username + uuid4().get_hex()[:uuid_length]
        final_username = UserSocialAuth.clean_username(slugify(username[:max_length]))

    return {'username': final_username}
开发者ID:appel268576,项目名称:django-social-auth,代码行数:29,代码来源:user.py

示例2: get_username

# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import username_max_length [as 别名]
def get_username(details, user=None, user_exists=UserSocialAuth.simple_user_exists, *args, **kwargs):
    """Return an username for new user. Return current user username
    if user was given.
    """
    if user:
        return {"username": user.username}

    if details.get(USERNAME):
        username = unicode(details[USERNAME])
    else:
        username = uuid4().get_hex()

    uuid_length = 16
    max_length = UserSocialAuth.username_max_length()
    short_username = username[: max_length - uuid_length]
    final_username = username[:max_length]

    # Generate a unique username for current user using username
    # as base but adding a unique hash at the end. Original
    # username is cut to avoid any field max_length.
    while user_exists(username=final_username):
        username = short_username + uuid4().get_hex()[:uuid_length]
        final_username = username[:max_length]

    return {"username": final_username}
开发者ID:kjoconnor,项目名称:django-social-auth,代码行数:27,代码来源:user.py

示例3: get_username

# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import username_max_length [as 别名]
def get_username(
                 user_exists=UserSocialAuth.simple_user_exists,
                 ):
    """Return an username for new user. Return current user username
    if user was given.
    """

    uuid_length = setting('SOCIAL_AUTH_UUID_LENGTH', 16)
    do_slugify = setting('SOCIAL_AUTH_SLUGIFY_USERNAMES', False)

    username = uuid4().get_hex()

    max_length = UserSocialAuth.username_max_length()
    short_username = username[:max_length - uuid_length]
    final_username = UserSocialAuth.clean_username(username[:max_length])
    if do_slugify:
        final_username = slugify(final_username)

    # Generate a unique username for current user using username
    # as base but adding a unique hash at the end. Original
    # username is cut to avoid any field max_length.
    while user_exists(username=final_username):
        username = short_username + uuid4().get_hex()[:uuid_length]
        username = username[:max_length]
        final_username = UserSocialAuth.clean_username(username)
        if do_slugify:
            final_username = slugify(final_username)
    print final_username
    return final_username
开发者ID:wikilife-org,项目名称:datadonor,代码行数:31,代码来源:services.py

示例4: get_username

# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import username_max_length [as 别名]
def get_username(user=None, user_exists=UserSocialAuth.simple_user_exists,
                 *args, **kwargs):
    if user:
        return {'username': UserSocialAuth.user_username(user)}

    prefix = setting('ACCOUNT_USERNAME_PREFIX', 'user')
    max_length = UserSocialAuth.username_max_length()
    uuid_length = setting('SOCIAL_AUTH_UUID_LENGTH', 16)

    username = None
    while username is None or user_exists(username=username):
        username = prefix + uuid4().get_hex()[:uuid_length]
        username = username[:max_length]

    return {'username': username}
开发者ID:petrabarus,项目名称:angkot,代码行数:17,代码来源:user.py

示例5: get_username

# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import username_max_length [as 别名]
def get_username(details, user=None, user_exists=username_rejected, *args, **kwargs):
    if user:  # Existing user?
        return {"username": user.username}

    # New user: create plausible user name suitable for URLs.

    max_length = UserSocialAuth.username_max_length()
    username = details.get("username", "user")[:max_length]
    username = slugify_harder(username)

    short_username = username[: max_length - RANDOM_LENGTH]
    while user_exists(username):
        username = short_username + uuid4().hex[:RANDOM_LENGTH]

    return {"username": username}
开发者ID:pdc,项目名称:kanbo,代码行数:17,代码来源:pipeline.py

示例6: get_username

# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import username_max_length [as 别名]
def get_username(details, user=None,
                 user_exists=UserSocialAuth.simple_user_exists,
                 *args, **kwargs):
    """Return an username for new user. Return current user username
    if user was given.
    """
    if user:
        return {'username': UserSocialAuth.user_username(user)}

    email_as_username = setting('SOCIAL_AUTH_USERNAME_IS_FULL_EMAIL', False)
    uuid_length = setting('SOCIAL_AUTH_UUID_LENGTH', 16)
    do_slugify = setting('SOCIAL_AUTH_SLUGIFY_USERNAMES', False)

    old_user = User.objects.filter(email=details.get('email')).first()
    if old_user:
        final_username = old_user.username
        return {'username': final_username,
                'user': old_user}
    if email_as_username and details.get('email'):
        username = details['email']
    elif details.get('username'):
        username = unicode(details['username'])
    else:
        username = uuid4().get_hex()

    max_length = UserSocialAuth.username_max_length()
    short_username = username[:max_length - uuid_length]
    final_username = UserSocialAuth.clean_username(username[:max_length])
    if do_slugify:
        final_username = slugify(final_username)

    # Generate a unique username for current user using username
    # as base but adding a unique hash at the end. Original
    # username is cut to avoid any field max_length.
    while user_exists(username=final_username):
        username = short_username + uuid4().get_hex()[:uuid_length]
        username = username[:max_length]
        final_username = UserSocialAuth.clean_username(username)
        if do_slugify:
            final_username = slugify(final_username)
    return {'username': final_username}
开发者ID:nabockh,项目名称:code,代码行数:43,代码来源:pipeline.py

示例7: get_username

# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import username_max_length [as 别名]
def get_username(details, user=None,
                 user_exists=UserSocialAuth.simple_user_exists,
                 *args, **kwargs):
    """Return an username for new user. Return current user username
    if user was given.
    """
    if user:
        return {'username': user.username}

    warn_setting('SOCIAL_AUTH_FORCE_RANDOM_USERNAME', 'get_username')
    warn_setting('SOCIAL_AUTH_DEFAULT_USERNAME', 'get_username')
    warn_setting('SOCIAL_AUTH_UUID_LENGTH', 'get_username')
    warn_setting('SOCIAL_AUTH_USERNAME_FIXER', 'get_username')

    if setting('SOCIAL_AUTH_FORCE_RANDOM_USERNAME'):
        username = uuid4().get_hex()
    elif details.get(USERNAME):
        username = unicode(details[USERNAME])
    elif setting('SOCIAL_AUTH_DEFAULT_USERNAME'):
        username = setting('SOCIAL_AUTH_DEFAULT_USERNAME')
        if callable(username):
            username = username()
    else:
        username = uuid4().get_hex()

    uuid_length = setting('SOCIAL_AUTH_UUID_LENGTH', 16)
    username_fixer = setting('SOCIAL_AUTH_USERNAME_FIXER', lambda u: u)

    max_length = UserSocialAuth.username_max_length()
    short_username = username[:max_length - uuid_length]
    final_username = username_fixer(username)[:max_length]

    # Generate a unique username for current user using username
    # as base but adding a unique hash at the end. Original
    # username is cut to avoid any field max_length.
    while user_exists(username=final_username):
        username = short_username + uuid4().get_hex()[:uuid_length]
        final_username = username_fixer(username)[:max_length]

    return {'username': final_username}
开发者ID:arnaudbreton,项目名称:django-social-auth,代码行数:42,代码来源:user.py

示例8: CreateUserFromSocial

# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import username_max_length [as 别名]
# -*- coding: utf-8 -*-
"""
User related class and functions.
"""

from uuid import uuid4
from django.conf import settings
from django.contrib.auth.models import User
from userena.models import UserenaSignup
from social_auth.models import UserSocialAuth
from social_auth.backends import USERNAME

USERNAME_MAX_LENGTH = UserSocialAuth.username_max_length()


class CreateUserFromSocial(object):
    """Create local users from a social auth mechanism.

    Perform every step to create new users to the system. This is a
    wrapper around userena.
    """

    def __call__(self, *args, **kwargs):
        """Create a new user to Transifex.

        For now, this is copied from social_auth.backends.pipeline.user.
        """
        user = kwargs.get("user")
        if user is not None:
            return {"user": user}
        username = kwargs.get("username")
开发者ID:tymofij,项目名称:transifex,代码行数:33,代码来源:user.py


注:本文中的social_auth.models.UserSocialAuth.username_max_length方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。