本文整理汇总了Python中accounts.models.User.last_name方法的典型用法代码示例。如果您正苦于以下问题:Python User.last_name方法的具体用法?Python User.last_name怎么用?Python User.last_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类accounts.models.User
的用法示例。
在下文中一共展示了User.last_name方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save_profile
# 需要导入模块: from accounts.models import User [as 别名]
# 或者: from accounts.models.User import last_name [as 别名]
def save_profile(backend, user, response, *args, **kwargs):
data = {}
data['is_social'] = True
if backend.name == 'facebook':
if kwargs['is_new']:
data['first_name'] = kwargs['details']['first_name']
data['last_name'] = kwargs['details']['last_name']
data['email'] = kwargs['details']['email']
register_form = SocialForm(data=data)
if register_form.is_valid():
new_user_instance = User.objects.filter(email=kwargs['details']['email'])
if not new_user_instance:
new_user_instance = User()
new_user_instance.first_name = kwargs['details']['first_name']
new_user_instance.email = kwargs['details']['email']
new_user_instance.last_name = kwargs['details']['last_name']
new_user_instance.profile_status = 1
new_user_instance.save()
else:
new_user_instance = User.objects.get(email=kwargs['details']['email'])
return {
'is_new': True,
'user': new_user_instance
}
else:
backend.strategy.session_set('social_data', data)
return HttpResponseRedirect('/registration/')
elif backend.name == 'google-oauth2':
if kwargs['is_new']:
data['first_name'] = kwargs['details']['first_name']
data['last_name'] = kwargs['details']['last_name']
data['email'] = kwargs['details']['email']
register_form = SocialForm(data=data)
if register_form.is_valid():
new_user_instance = User.objects.filter(email=kwargs['details']['email'])
if not new_user_instance:
new_user_instance = User()
new_user_instance.first_name = kwargs['details']['first_name']
new_user_instance.email = kwargs['details']['email']
new_user_instance.last_name = kwargs['details']['last_name']
new_user_instance.profile_status = 1
new_user_instance.save()
else:
new_user_instance = User.objects.get(email=kwargs['details']['email'])
return {
'is_new': True,
'user': new_user_instance
}
else:
backend.strategy.session_set('social_data', data)
return HttpResponseRedirect('/registration/')
示例2: authenticate
# 需要导入模块: from accounts.models import User [as 别名]
# 或者: from accounts.models.User import last_name [as 别名]
def authenticate(self, token):
response_profile = requests.get(
'https://graph.facebook.com/me/',
params={
'access_token': token,
}
)
facebook_profile = response_profile.json()
if 'error' in facebook_profile:
return None
try:
user = User.objects.get(facebook_id=facebook_profile.get('id'))
except User.DoesNotExist:
user = User(facebook_id=facebook_profile.get('id'))
if facebook_profile.get('id') in settings.FACEBOOK_ADMINS:
user.is_staff = True
user.is_superuser = True
user.username = facebook_profile.get('id')
user.set_unusable_password()
user.facebook_access_token = token
user.email = facebook_profile.get('email', '')
user.first_name = facebook_profile.get('first_name')
user.last_name = facebook_profile.get('last_name')
user.save()
return user
示例3: post
# 需要导入模块: from accounts.models import User [as 别名]
# 或者: from accounts.models.User import last_name [as 别名]
def post(self, request):
form = RegistrationForm(data=request.POST)
response = HttpResponseRedirect('/')
if form.is_valid():
user = User()
year = request.POST['birthdate_year']
month = request.POST['birthdate_month']
day = request.POST['birthdate_day']
date_of_birth = year+'-'+month+'-'+day
user.birthday = date_of_birth
user.email = form.cleaned_data['email']
user.role = 'client'
user.first_name = form.cleaned_data['first_name']
user.phone_number = ''
user.zip_code = form.cleaned_data['zip_code']
user.last_name = form.cleaned_data['last_name']
user.set_password(form.cleaned_data['password'])
user.save()
confirm_register_mail(request, user.email, user.first_name, user.last_name, user.zip_code)
new_user = authenticate(email=form.cleaned_data['email'],
password=form.cleaned_data['password'],
)
login(request, new_user)
messages.success(request, "You have registered successfully.")
else:
response.set_cookie('registr_error', 'error')
cache.set('registartion_error', RegistrationForm(request.POST))
return response
示例4: create
# 需要导入模块: from accounts.models import User [as 别名]
# 或者: from accounts.models.User import last_name [as 别名]
def create(self, validated_data):
user = User()
user.set_password(validated_data["password"])
user.email = validated_data['email']
user.first_name = validated_data['first_name']
user.last_name = validated_data['last_name']
user.phone_number = validated_data['phone_number']
return user
示例5: create_user
# 需要导入模块: from accounts.models import User [as 别名]
# 或者: from accounts.models.User import last_name [as 别名]
def create_user():
user = User()
user.username = request.form.get('username', None)
user.first_name = request.form.get('first_name', '')
user.last_name = request.form.get('last_name', '')
user.email = request.form.get('email', '')
user.account = request.form.get('account', None)
user.set_password(request.form.get('password', ''))
user.save()
return redirect(url_for('accounts.users'))