本文整理汇总了Python中models.Profile.nickname方法的典型用法代码示例。如果您正苦于以下问题:Python Profile.nickname方法的具体用法?Python Profile.nickname怎么用?Python Profile.nickname使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Profile
的用法示例。
在下文中一共展示了Profile.nickname方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edit_profile
# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import nickname [as 别名]
def edit_profile(request):
"""
Show and edit user profile.
"""
username = request.user.username
if request.method == 'POST':
form = ProfileForm(request.POST)
if form.is_valid():
nickname = form.cleaned_data['nickname']
intro = form.cleaned_data['intro']
try:
profile = Profile.objects.get(user=request.user.username)
except Profile.DoesNotExist:
profile = Profile()
profile.user = username
profile.nickname = nickname
profile.intro = intro
profile.save()
messages.success(request, _(u'Successfully edited profile.'))
# refresh nickname cache
refresh_cache(request.user.username)
return HttpResponseRedirect(reverse('edit_profile'))
else:
messages.error(request, _(u'Failed to edit profile'))
else:
try:
profile = Profile.objects.get(user=request.user.username)
form = ProfileForm({
'nickname': profile.nickname,
'intro': profile.intro,
})
except Profile.DoesNotExist:
form = ProfileForm()
# common logic
try:
server_crypto = UserOptions.objects.is_server_crypto(username)
except CryptoOptionNotSetError:
# Assume server_crypto is ``False`` if this option is not set.
server_crypto = False
sub_lib_enabled = UserOptions.objects.is_sub_lib_enabled(username)
return render_to_response('profile/set_profile.html', {
'form': form,
'server_crypto': server_crypto,
"sub_lib_enabled": sub_lib_enabled,
}, context_instance=RequestContext(request))
示例2: edit_profile
# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import nickname [as 别名]
def edit_profile(request):
"""
Show and edit user profile.
"""
if request.method == 'POST':
form = ProfileForm(request.POST)
if form.is_valid():
nickname = form.cleaned_data['nickname']
intro = form.cleaned_data['intro']
try:
profile = Profile.objects.get(user=request.user.username)
except Profile.DoesNotExist:
profile = Profile()
profile.user = request.user.username
profile.nickname = nickname
profile.intro = intro
profile.save()
messages.success(request, _(u'Successfully edited profile.'))
# refresh nickname cache
refresh_cache(request.user.username)
return HttpResponseRedirect(reverse('edit_profile'))
else:
messages.error(request, _(u'Failed to edit profile'))
else:
try:
profile = Profile.objects.get(user=request.user.username)
form = ProfileForm({
'nickname': profile.nickname,
'intro': profile.intro,
})
except Profile.DoesNotExist:
form = ProfileForm()
return render_to_response('profile/set_profile.html', {
'form': form,
}, context_instance=RequestContext(request))