本文整理汇总了Python中models.Player.member方法的典型用法代码示例。如果您正苦于以下问题:Python Player.member方法的具体用法?Python Player.member怎么用?Python Player.member使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Player
的用法示例。
在下文中一共展示了Player.member方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handlefbrequestcallback
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import member [as 别名]
def handlefbrequestcallback(request):
fp = open( 'tmp.3.log', 'w' )
print >> fp, request
request_str = ( request.GET.get('request') )
request_to = ( request.GET.get('to') )
#request_from = ( request.GET.get('from') )
request_id = ( request.GET.get('id') )
request_from = request.session['fb_id']
#if request_to:
# request_to = int(request_to.encode('ascii'))
#if request_from:
# request_from = int(request_from.encode('ascii'))
#if request_id:
# request_id = int(request_id.encode('ascii'))
print >> fp, "request id", request_id
print >> fp, "request string", request_str
print >> fp, "request to", request_to
print >> fp, "request from", request_from
print >> fp, "request fb id", request.session['fb_id']
try:
m_to = Member.objects.get(fb_id=request_to)
except:
# need to make member
m_to = Member(fb_id=request_to)
try:
m_from = Member.objects.get(fb_id=request_from)
except:
# need to make member
m_from = Member(fb_id=request_from)
# name is set
gamename = "%s_%s_%s" % ( request_from, request_to, time.asctime(time.gmtime()) )
r = Room(name=gamename)
r.fb_request_id = request_id
r.save()
g = Game(room=r)
# game name and room name duplicated
g.name = gamename
g.save()
p = Player(game=g,turn=0)
p.member = m_from
p.save()
# TODO assumes two player game - generalize
p = Player(game=g,turn=1)
p.member = m_to
p.save()
#return HttpResponseRedirect('requestpage.html')
return HttpResponseRedirect( reverse('lupalo.views.lupalo') ) # Redirect after POST
示例2: loggedin
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import member [as 别名]
#.........这里部分代码省略.........
if m == None:
try:
m = Member.objects.get( fb_id=request.session['fb_id'] )
m.user_name = profile['name']
m.fb_first_name = profile['first_name']
m.fb_last_name = profile['last_name']
m.save()
except Member.DoesNotExist:
m = None
return HttpResponseRedirect( reverse('lupalo.views.lupalo') ) # Redirect after POST
#return HttpResponseRedirect(reverse('lupalo.views.requestpage'))
if True:
#if request.method == 'POST': # If the form has been submitted...
#form = ContactForm(request.POST) # A form bound to the POST data
#print >> fp, "validating"
#print >> fp, form.is_valid()
#print >> fp, form.errors
#if form.is_valid():
if True:
#user = form.cleaned_data['user']
#user = request.user.id
user = request.user.username
t = time.gmtime()
name = time.asctime(t)
gamename = time.asctime(t)
#gamename = form.cleaned_data['room']
#newgame = form.cleaned_data['newgame']
newgame = True
print >> fp, "New Game", newgame
if newgame == True:
#Room.objects.all().delete()
r = Room(name=name)
r.save()
Game.objects.all().delete()
g = Game(name=name,room=r)
g.save()
r = Room(name=gamename)
r.save()
g = Game(name=name,room=r)
g.save()
else:
r = Room(name=gamename)
g = Game(name=name,room=r)
m = Member.objects.get( fb_id=request.session['fb_id'] )
game = Game.objects.all()
#g = game[0]
request.session['game_id'] = g.id
# TODO get room id from game
#r = g.room
# TODO get player id from room
#players = Player.objects.get(game=g)
try:
players = get_list_or_404(Player, game=g)
except:
players = None
if players:
turn = len(players)
else:
turn = 0
p = Player(game=g,turn=turn)
p.member = m
p.save()
print >> fp, "Player turn:", p.turn
request.session['player_id'] = p.turn
return HttpResponseRedirect( reverse('lupalo.views.lupalo') ) # Redirect after POST
#return render(request, 'polls/login.html', {
# 'form': form,
#})
else:
form = ContactForm() # An unbound form
fp.close()
#m = Member.objects.get(user_name=request.POST['username'])
#request.session['member_id'] = m.id
return render(request, 'foyer.html', {
'form': form, 'user':request.user.first_name
})