本文整理汇总了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}
示例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}
示例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
示例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}
示例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}
示例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}
示例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}
示例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")