当前位置: 首页>>代码示例>>Python>>正文


Python Player.save方法代码示例

本文整理汇总了Python中models.Player.save方法的典型用法代码示例。如果您正苦于以下问题:Python Player.save方法的具体用法?Python Player.save怎么用?Python Player.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Player的用法示例。


在下文中一共展示了Player.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: player_put

# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import save [as 别名]
def player_put(pid, name):
    """ Insert player via DotA2 ID """
    if not player_check(pid):
        query = Player(player_id=pid, name=name)
        query.save()
        return True
    return False
开发者ID:UltimatePancake,项目名称:pqn_dota,代码行数:9,代码来源:factory.py

示例2: player

# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import save [as 别名]
    def player(self, message, first, last):
        ''' format sms: player first last
        
        la fonction repond une phrase au hasard a un player '''
        # creation d'un player 
        player = Player(first_name=first, \
                                last_name=last, \
                                
                                number=message.peer)
                                
        # ma liste de reponse 
        list= ["vous etes un as", 
                "vous etes formidable",
                "reesayez vous pouvez le faire", 
                'vive le SENEGAL',
                u"vous n'etes pas trop doué",
                "vous êtes un pythonier"]
        # je melange ma liste et je tire une phrase au hasard
        ran = random.choice(list)
        
        # renvoie d'une reponse        
        message.respond(u"%(att)s, %(att1)s." % {'att': player, 'att1':ran})
        # sauvegarde le player
        player.save()

        return True
开发者ID:rgaudin,项目名称:souktelws,代码行数:28,代码来源:app.py

示例3: post

# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import save [as 别名]
    def post(self, request):
        email = request.DATA['email']
        username = request.DATA['username']
        password = request.DATA['password']

        pre_existing = Player.objects.filter(Q(username__iexact=username) | Q(email__iexact=email))
        if ' ' in username:
            return Response([{'type': 'danger', 'msg': 'Yeah soo.. no spaces in username please. Gracias Amigo.'}], status=status.HTTP_403_FORBIDDEN)
        if username == '' or email == '' or password == '':
            return Response([{'type': 'danger', 'msg': 'All Fields are required buddy'}], status=status.HTTP_403_FORBIDDEN)
        if len(pre_existing) is not 0:
            return Response([{'type': 'danger', 'msg': 'username/email already exists.'}], status=status.HTTP_403_FORBIDDEN)
        else:
            player = Player()
            player.email = email
            player.username = username
            player.is_active = True
            player.set_password(password)
            player.save()
            authed = authenticate(username=username, password=password)
            login(request, authed)

            serialized = PlayerSerializer(player)

            return Response(serialized.data, status=status.HTTP_201_CREATED)
开发者ID:deanblacc,项目名称:pingpong,代码行数:27,代码来源:views.py

示例4: new_player

# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import save [as 别名]
def new_player(user):
    player = Player(
        user=user, level=1, points=10)
    player.save()
    player.add_sentence
    player.add_sentence
    player.add_sentence
开发者ID:Crimolt,项目名称:PlayEnglish,代码行数:9,代码来源:views.py

示例5: testSaveOkCheckEmail

# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import save [as 别名]
 def testSaveOkCheckEmail(self):
     player = Player(self.collection, self.name, self.email, self.fbid, self.artist)
     expected = self.email
     player.save()
     q = {'e': self.email}
     actual = self.collection.find_one(q)['e']
     assert_equal(expected, actual)
开发者ID:nleite,项目名称:teamr,代码行数:9,代码来源:tests.py

示例6: build_players

# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import save [as 别名]
def build_players():
    clubs = Club.objects.all()
    for c in clubs:
        # generate men
        men_count = randint(20, 30)
        index = 0
        while index < men_count:
            p = Player(first_name=men_first_names[randint(0, len(men_first_names) - 1)],
                       last_name=men_last_names[randint(0, len(men_last_names) - 1)],
                       date_of_birth=random_dob(),
                       gender=Gender.MALE,
                       club=c)
            p.save()
            index += 1

        # generate women
        women_count = randint(20, 30)
        index = 0
        while index < women_count:
            p = Player(first_name=women_first_names[randint(0, len(women_first_names) - 1)],
                       last_name=women_last_names[randint(0, len(women_last_names) - 1)],
                       date_of_birth=random_dob(),
                       gender=Gender.FEMALE,
                       club=c)
            p.save()
            index += 1
开发者ID:tufyx,项目名称:amh_api,代码行数:28,代码来源:generate_data.py

示例7: newplayer

# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import save [as 别名]
def newplayer(request):
  success = 0
  playerid = 0
  playername = ''
  if request.method == 'POST':
    form = NewPlayerForm(request.POST)
    if form.is_valid():
      cd = form.cleaned_data
      player = Player(name=cd['name'])
      player.save()
      squares = Square.objects.all().order_by('pk')
      if len(squares)-1 >= 24:
        squarei = random.sample(range(1,len(squares)),24)
      elif len(squares)-1 > 0:
        squarei = []
        for i in range(24):
          squarei.append(random.randint(1,len(squares)-1))
      else:
        squarei = []
        for i in range(24):
          squarei.append(0)
      for i in range(25):
        if i < 12:
          spot = Boardsquare(player=player,square=squares[squarei[i]],checked=False,order=i)
        elif i == 12:
          spot = Boardsquare(player=player,square=squares[0],checked=True,order=i)
        else:
          spot = Boardsquare(player=player,square=squares[squarei[i-1]],checked=False,order=i)
        spot.save()
      playerid = player.pk
      playername = player.name
      success = 1
  else:
    form = NewPlayerForm()
  return render(request, 'bingo/newplayer.html', {'form': form, 'success': success, 'id': playerid, 'name': playername})
开发者ID:bonventre,项目名称:djingo,代码行数:37,代码来源:views.py

示例8: get

# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import save [as 别名]
 def get(self, request, game_name):
     player = None
     if 'user_id' not in request.session:
         player = Player(name="New guy")
         player.save()
         request.session['user_id'] = player.id
     else:
         try:
             player = Player.objects.get(id=request.session['user_id'])
         except Player.DoesNotExist:
             player = Player(id=request.session['user_id'], name="New guy")
             player.save()
             
             
     try:
         max_score = Score.objects.get(player_id=player.id, game__name=game_name).score
     except Score.DoesNotExist:
         max_score = 0
     
     max_score_records = []
     for record in Score.objects.filter(game__name=game_name).order_by('-score')[:10]:
         max_score_records.append({"score": record.score, "player_name": record.player.name})
 
     context = self.get_context_data()
     context.update({
         'user_id' : request.session['user_id'],
         'user_name' : player.name,
         'user_max_score' : max_score,
         'max_score_records': max_score_records,
     })
     return render(request, "games/" + game_name + ".html", context)
开发者ID:antoshkaplus,项目名称:Django_PersonalWebsite,代码行数:33,代码来源:views.py

示例9: add

# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import save [as 别名]
    def add(self, pid):
        player = Player(
            Pid=pid
        )
        player.save()

        return player.id
开发者ID:rejahrehim,项目名称:jukebox,代码行数:9,代码来源:api.py

示例10: testSaveOkCheckArtist

# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import save [as 别名]
    def testSaveOkCheckArtist(self):

        player = Player(self.collection, self.name, self.email, self.fbid, self.artist)
        expected = player.mobject
        #import ipdb;ipdb.set_trace()
        player.save()
        actual = self.collection.find_one({'e': player.email})
        assert_equal(actual['a'], expected['a'])
开发者ID:nleite,项目名称:teamr,代码行数:10,代码来源:tests.py

示例11: create_player

# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import save [as 别名]
def create_player(first, last):

    person = Person(first_name=first, last_name=last)
    person.save()
    player = Player(person=person)
    player.save()

    return player
开发者ID:tammolaube,项目名称:soccer-island,代码行数:10,代码来源:test_models.py

示例12: handlefbrequestcallback

# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import save [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
开发者ID:JanetGuo,项目名称:lupalo,代码行数:60,代码来源:views.old.py

示例13: findPlayer

# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import save [as 别名]
def findPlayer(username, channel):
	try:         
		# Try to find existing player by username in this channel.
		player = Player.objects.get(username=username, channel=channel)
        except Player.DoesNotExist:
                # Player does not exist yet. Create new player with username and channel.
                player = Player(username=username, channel=channel)
       		player.save()
	return player
开发者ID:stephanieychou,项目名称:tictactoe,代码行数:11,代码来源:views.py

示例14: new_game

# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import save [as 别名]
def new_game(request):
    if request.method.lower() == 'get':
        return render_to_response('asphodel/new_game_form.html',
                {
                    'user': request.user,
                    'users': User.objects.all(),
                    'selected_users': [],
                    'STATIC_URL': '/static',
                })

    game_name = request.POST['name']
    user_ids = set(map(int, request.POST.getlist('users')))
    user_ids.add(request.user.id)

    users = User.objects.filter(pk__in=user_ids)

    errors = []
    if not game_name:
        errors.append("Please name your game")
    if not users:
        errors.append("You need more users to play a game")

    if errors:
        return render_to_response('asphodel/new_game_form.html', {
                'errors': errors,
                'user': request.user,
                'users': User.objects.all(),
                'selected_users': user_ids,
                'STATIC_URL': '/static',
                })

    game = Game(name=game_name, start_date=datetime.now())
    game.save()

    players = []
    my_player = None
    for idx, user, color in zip(count(), users,
                                ["red", "blue", "green", "yellow"]):
        player = Player(game=game,
                        user=user,
                        color=color,
                        turn_index=idx,
                        resources=500)
        player.save()
        players.append(player)

        if user == request.user:
            my_player = player

    game.current_turn = my_player if my_player else players[0]
    game.save()
    gen.map.new_game_map(game, players)
    return redirect(game)
开发者ID:ojrac,项目名称:Asphodel,代码行数:55,代码来源:views.py

示例15: post_save

# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import save [as 别名]
 def post_save(self, obj, created=False):
     if not created:
         return
     # Assign computer player if one is missing
     if obj.players.count() == 1:
         try:
             com_player = Player.objects.filter(is_human=False)[0]
         except IndexError:
             com_player = Player(name='Mensa Monkey', color='#000')
             com_player.save()
         finally:
             obj.players.add(com_player)
开发者ID:zniper,项目名称:ckboard,代码行数:14,代码来源:views.py


注:本文中的models.Player.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。