本文整理汇总了Python中forms.MyRegistrationForm.get_username方法的典型用法代码示例。如果您正苦于以下问题:Python MyRegistrationForm.get_username方法的具体用法?Python MyRegistrationForm.get_username怎么用?Python MyRegistrationForm.get_username使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.MyRegistrationForm
的用法示例。
在下文中一共展示了MyRegistrationForm.get_username方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: register
# 需要导入模块: from forms import MyRegistrationForm [as 别名]
# 或者: from forms.MyRegistrationForm import get_username [as 别名]
def register(request):
if request.user.is_authenticated():
return HttpResponseRedirect('/')
else:
args = {}
args['register_active'] = True
if request.GET.get('inv'):
args['invite'] = request.GET.get('inv')
if request.method == 'POST':
form = MyRegistrationForm(request.POST)
args['form'] = form
if form.is_valid():
# Pick data
invite = request.POST.get('invite')
initial_balance = int(request.POST.get('balance'))
# Save user with Default properties
form.save()
# Pick the user
user = User.objects.get(username=form.get_username())
# Custom USER data
uinfo = UserProfile()
uinfo.user = user
# BALANCE
if initial_balance > 50:
initial_balance = initial_balance + (initial_balance * 0.10)
# Check invite
if invite:
try:
host_user = UserProfile.objects.get(invite_id=invite)
except UserProfile.DoesNotExist:
host_user = None
if host_user:
initial_balance = initial_balance + 10
# SAVE USER CUSTOM DATA
uinfo.initial_balance = initial_balance
uinfo.invite_id = get_random_string(length=30)
uinfo.save()
return HttpResponseRedirect('/accounts/register_success')
args['register_active'] = True
return render(request, 'register.html', args)
else:
args['form'] = MyRegistrationForm()
args.update(csrf(request))
return render_to_response('register.html', args)