本文整理汇总了Python中userprofile.models.UserProfile.info方法的典型用法代码示例。如果您正苦于以下问题:Python UserProfile.info方法的具体用法?Python UserProfile.info怎么用?Python UserProfile.info使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类userprofile.models.UserProfile
的用法示例。
在下文中一共展示了UserProfile.info方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edit_user
# 需要导入模块: from userprofile.models import UserProfile [as 别名]
# 或者: from userprofile.models.UserProfile import info [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})