本文整理汇总了Python中userprofile.models.UserProfile.user方法的典型用法代码示例。如果您正苦于以下问题:Python UserProfile.user方法的具体用法?Python UserProfile.user怎么用?Python UserProfile.user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类userprofile.models.UserProfile
的用法示例。
在下文中一共展示了UserProfile.user方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: user_registration
# 需要导入模块: from userprofile.models import UserProfile [as 别名]
# 或者: from userprofile.models.UserProfile import user [as 别名]
def user_registration(request):
if request.user.is_authenticated():
return redirect('/')
form = RegisterForm(request.POST or None)
if form.is_valid():
user = form.save()
user.set_password(user.password)
user.save()
profile = UserProfile()
profile.user = user
profile.save()
send_mail(
'Welcome to ' + DOMAIN + '!',
'Someone try register on site ' + DOMAIN +
'. To confirm registration visit this link ' + confirmation_link +
'. If you aren\'t try to register than just ignore this email. ''',
'[email protected]',
['[email protected]'],
fail_silently=False)
return redirect('/')
context = RequestContext(request)
return render_to_response('userprofile/registration.html',
{'form': form}, context)
示例2: test_avatar
# 需要导入模块: from userprofile.models import UserProfile [as 别名]
# 或者: from userprofile.models.UserProfile import user [as 别名]
def test_avatar(self):
user = UserProfile()
user.user = User()
self.assertEqual(user.get_user_avatar(), 'images/default.jpeg')
path = 'images/bill.jpeg'
user.avatar = path
self.assertEqual(user.get_user_avatar(), path)
user.user.username = 'bill'
self.assertEqual('bill', user.__str__())
示例3: edit_user
# 需要导入模块: from userprofile.models import UserProfile [as 别名]
# 或者: from userprofile.models.UserProfile import user [as 别名]
def edit_user(request, id=None):
if id:
action = "edit"
userprofile = get_object_or_404(UserProfile, id=id)
user = userprofile.user
initial = { 'username':user.username,
'name':userprofile.name,
'password':"",
'email':user.email,
'phone_number':userprofile.phone_number,
'info':userprofile.info,
'is_staff':user.is_staff,
}
else:
action = "add"
userprofile = None
initial = None
if request.POST:
form = UserForm(request.POST, instance=userprofile)
if form.is_valid():
if userprofile:
user = userprofile.user
else:
userprofile = UserProfile()
user = User()
userprofile.user = user
userprofile.user.username = form.cleaned_data['username']
userprofile.name = form.cleaned_data['name']
userprofile.user.email = form.cleaned_data['email']
userprofile.phone_number = form.cleaned_data['phone_number']
userprofile.info = form.cleaned_data['info']
userprofile.user.is_staff = form.cleaned_data['is_staff']
if form.cleaned_data['password']:
userprofile.user.set_password(form.cleaned_data['password'])
user.save()
userprofile.user = user
userprofile.save()
request.user.message_set.create(message="User '%s' was %sed." % (userprofile.name, action))
return HttpResponseRedirect("/user/manage/")
else:
form = UserForm(initial=initial, instance=userprofile)
return render_to_response_context(request, 'userprofile/manage/edit.html', {'form':form, 'action':action})
示例4: save
# 需要导入模块: from userprofile.models import UserProfile [as 别名]
# 或者: from userprofile.models.UserProfile import user [as 别名]
def save(self, commit=True):
user = super(MyRegistrationForm, self).save(commit=False)
user.email = self.cleaned_data['email']
user.set_password(self.cleaned_data['password1'])
profile = UserProfile(user=user)
profile.user = user
profile.user.self_description = "self_description"
profile.user.line_of_work = "line_of_work"
profile.user.hobbies = "hobbies"
profile.user.owns_car = "owns_car"
profile.user.vehicle_model = "vehicle_model"
if commit:
user.save()
profile.save()
return user
示例5: user_details
# 需要导入模块: from userprofile.models import UserProfile [as 别名]
# 或者: from userprofile.models.UserProfile import user [as 别名]
def user_details(strategy, details, response, is_new=False,
user=None, *args, **kwargs):
"""Update user details using data from provider."""
if user:
if is_new:
# get special extra data
# if strategy.backend.__class__.__name__ == 'TwitterOAuth':
# twitter_data = {}
# elif strategy.backend.__class__.__name__ == 'FacebookOAuth2':
# fb_data = {
# 'locale': response['locale'],
# }
# elif strategy.backend.__class__.__name__ == 'GithubOAuth2':
profile = UserProfile()
profile.user = user
profile.picture = get_user_avatar()
profile.save()
示例6: edit
# 需要导入模块: from userprofile.models import UserProfile [as 别名]
# 或者: from userprofile.models.UserProfile import user [as 别名]
def edit(request):
if request.method == 'POST': # If the form has been submitted...
form = UserProfileForm(request.POST) # A form bound to the POST data
if form.is_valid():
userprofile = UserProfile()
userprofile.user = request.user
userprofile.firstname = form.cleaned_data['firstname']
userprofile.lastname = form.cleaned_data['lastname']
userprofile.number = form.cleaned_data['number']
userprofile.serie = form.cleaned_data['serie']
userprofile.sexe = form.cleaned_data['sexe']
userprofile.phoneNumber = form.cleaned_data['phoneNumber']
userprofile.save()
return redirect('userprofile.views.display') # Redirect after POST
else:
return render(request,
'userprofile/userprofile_edit.html', {
'form': form,
}
)
else:
try:
userprofile = UserProfile.objects.get(pk=request.user)
form = UserProfileForm({
'firstname': userprofile.firstname,
'lastname': userprofile.lastname,
'number': userprofile.number,
'serie': userprofile.serie,
'sexe': userprofile.sexe,
'phoneNumber': userprofile.phoneNumber,
})
except Exception as ex:
print ex
form = UserProfileForm()
return render(request,
'userprofile/userprofile_edit.html', {
'form': form,
}
)