예제 #1
0
def toPlayersView(players):
    result = []
    for player in players:
        obj = {}
        obj['id_code'] = player.id_code
        obj['name'] = player.user.first_name
        obj['nickname'] = player.user.last_name
        obj['phone'] = player.user.phone
        obj['qq'] = player.user.qq
        obj['img_path'] = player.user.img_path
        obj['position'] = player.position
        obj['height'] = player.height
        obj['school'] = player.school
        obj['weight'] = player.weight
        obj['number'] = player.number
        obj['create_time'] = player.create_time
        obj['desc'] = player.desc
        data = Logics.getPlayerProfile(player.id_code)
        obj['player_data'] = toPlayerProfileView(data)
        if player.team is not None:
            obj['team'] = player.team.name
        else:
            obj['team'] = '无'
        result.append(obj)
    return result
예제 #2
0
def playerDetail(request):
    if request.method == 'GET':
        id_code = request.GET['id_code']
        player = Player.objects.get(id_code=id_code);
        data = Logics.getPlayerProfile(id_code)
        player_game_profile = PlayerGameProfile.objects.filter(id_code=player.id_code).order_by("-_id")[0:5]
        games = []
        for each in player_game_profile:
            game_id_code = each.team_game.game_id_code
            print("game id code",game_id_code)
            games.append(Game.objects.get(id_code=game_id_code))
        if player.team is not None:
            teammates = list(player.team.players.all())
            teammates.remove(player)
        else:
            teammates = []
        return render(request,"team/playerDetail.html",{"player":player,"player_data":data,"teammates":teammates,"games":games})
    else:
        id_code = request.POST['id_code']
        player = Player.objects.get(id_code=id_code);
        response_data ={}
        response_data['players'] = toPlayersView([player])
        return HttpResponse(json.dumps(response_data,cls=CJsonEncoder),content_type='application/json')