本文整理汇总了Python中models.Player.gender方法的典型用法代码示例。如果您正苦于以下问题:Python Player.gender方法的具体用法?Python Player.gender怎么用?Python Player.gender使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Player
的用法示例。
在下文中一共展示了Player.gender方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: new_register
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import gender [as 别名]
def new_register(request):
""" This is for a new user who wishes to register independent of twitter and facebook;
we use gravatar for these users.
"""
if request.method == 'POST':
form = NewPlayerForm(request.POST)
if form.is_valid():
first_name = form.cleaned_data['first_name']
last_name = form.cleaned_data['last_name']
username = form.cleaned_data['username']
email = form.cleaned_data['email']
phone_number = form.cleaned_data['phone_number']
sports = form.cleaned_data['sports']
gender = form.cleaned_data['gender']
password1 = form.cleaned_data['password1']
#password2 = form.cleaned_data['password2'] # unused
user = User.objects.create_user(username=username, email=email, password=password1)
user.first_name = first_name
user.last_name = last_name
user.save()
player = Player()
player.gender = gender
player.user = user
player.phone_number = phone_number
player.image_url = get_gravatar(player.user.email)
player.save()
player.sports = sports
user = authenticate(username=player.user, password=password1)
login(request, user)
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
from django.core.mail import EmailMessage
from django.template.loader import render_to_string
from django.utils.html import strip_tags
subject, from_email, to = 'Welcome', '[email protected]', user.email
html_content = render_to_string('email_signup.html', {'user': user.first_name})
text_content = strip_tags(html_content)
msg = EmailMessage(subject, text_content, to=[to])
msg.send()
# task here to email user
SignUpTask.delay(user)
return HttpResponseRedirect('/')
else:
if 'email' in request.GET:
form = NewPlayerForm(initial={'email': request.GET['email']})
else:
form = NewPlayerForm()
return render(request, 'new_register.html', {'form': form})
示例2: new_register
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import gender [as 别名]
def new_register(request):
""" This is for a new user who wishes to register independent of twitter and facebook;
we use gravatar for these users.
"""
if request.method == 'POST':
form = NewPlayerForm(request.POST)
if form.is_valid():
first_name = form.cleaned_data['first_name']
last_name = form.cleaned_data['last_name']
username = form.cleaned_data['username']
email = form.cleaned_data['email']
phone_number = form.cleaned_data['phone_number']
sports = form.cleaned_data['sports']
gender = form.cleaned_data['gender']
password1 = form.cleaned_data['password1']
#password2 = form.cleaned_data['password2'] # unused
user = User.objects.create_user(username=username, email=email, password=password1)
user.first_name = first_name
user.last_name = last_name
user.save()
player = Player()
player.gender = gender
player.user = user
player.phone_number = phone_number
player.image_url = get_gravatar(player.user.email)
player.save()
player.sports = sports
user = authenticate(username=player.user, password=password1)
login(request, user)
# task here to email user
SignUpTask.delay(user)
return HttpResponseRedirect('/')
else:
if 'email' in request.GET:
form = NewPlayerForm(initial={'email': request.GET['email']})
else:
form = NewPlayerForm()
return render(request, 'new_register.html', {'form': form})
示例3: facebook_callback
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import gender [as 别名]
def facebook_callback(request):
""" This method is responsible for the facebook callback and generating the facebook user.
"""
if 'error' in request.GET:
return HttpResponseRedirect('/')
code = request.GET["code"]
args = dict(
client_id = keys.FACEBOOK_APP_ID,
redirect_uri = 'http://tini.ep.io/facebook/callback',
client_secret = keys.FACEBOOK_APP_SECRET,
code = code
)
token_url = 'https://graph.facebook.com/oauth/access_token?' + urllib.urlencode(args)
data = urllib.urlopen(token_url)
response = data.read()
data.close()
# print 'Token URL:' + token_url
# print 'Response:'
# print response
try:
split = response.split('=')
access_token = split[1].strip('&expires')
expires = split[2]
# print 'Access Token: ' + access_token
# print 'Expires: ' + expires
except:
error = json.loads(response)
return HttpResponseRedirect('/error')
profile = json.load(urllib.urlopen('https://graph.facebook.com/me?' + urllib.urlencode(dict(access_token=access_token))))
args = dict(
access_token = access_token
)
graph_url = 'https://graph.facebook.com/me?' + urllib.urlencode(args)
#print graph_url
response = urllib.urlopen(graph_url)
facebook_user = json.load(response)
username = facebook_user.get('username', '')
gender = facebook_user.get('gender', '')
try:
player = Player.objects.get(facebook_id=facebook_user.get('id', None))
except ObjectDoesNotExist:
user = User(username=username)
user.set_password(access_token)
user.first_name = facebook_user['first_name']
user.last_name = facebook_user['last_name']
user.email = facebook_user['email']
player = Player()
player.user = user
player.gender = get_gender_initial(gender=gender)
player.facebook_id = facebook_user['id']
player.facebook_oauth_token = access_token
request.session['facebook'] = player
form = PlayerForm(initial={'username': player.user.username, 'first_name': user.first_name, 'last_name': user.last_name, 'email': player.user.email, 'gender': player.gender})
return render(request, 'register.html', {'form': form})
# player = Player.objects.get(user=user)
# print player
user = authenticate(username=player.user.username, password=player.facebook_oauth_token)
login(request, user)
return HttpResponseRedirect('/')