Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def swiss(request):
- args = {}
- args.update(csrf(request))
- index = Bill.objects.all()
- nov_por = Bill.objects.filter().order_by('-bill_mat_ozh')
- a = nov_por.count() // 2
- nov_por_1 = (nov_por[:a])
- nov_por_2 = (nov_por[a:])
- res_1 = [(nov_por_1[n].bill_fio) for n in range(nov_por_1.count()) if nov_por_1[n] in nov_por_1]
- res_2 = [(nov_por_2[n].bill_fio) for n in range(nov_por_2.count()) if nov_por_2[n] in nov_por_2]
- players = zip_longest(res_1, res_2)
- return render_to_response('swiss.html', {'players':players, 'index':index},
- context_instance=RequestContext(request))
- def first_step(request):
- game_data = request.POST
- print(game_data)
- for key, value in game_data.items():
- if key == 'csrfmiddlewaretoken':
- pass
- elif value == 'no':
- split_player = key.split(', ')
- for player in split_player:
- player_name = re.sub(r'[^ws-]+', r'', player).strip()
- standoff = Bill.objects.get(bill_fio = player_name)
- standoff.swiss_bill_score = standoff.swiss_bill_score + 0.5
- standoff.save()
- else:
- bill = Bill.objects.get(bill_fio = value)
- bill.swiss_bill_score = bill.swiss_bill_score + 1
- bill.save()
- for key, value in game_data.items():
- if key == 'csrfmiddlewaretoken':
- pass
- else:
- spisok = []
- if 'None' in key:
- pass
- else:
- wr_split_player = key.split(', ')
- for rw_player in wr_split_player:
- rw_player_name = re.sub(r'[^ws-]+', r'', rw_player).strip()
- rw_player_id = Bill.objects.get(bill_fio = rw_player_name).id
- spisok.append(rw_player_id)
- spisok.sort()
- length = len(spisok)
- if length == 2:
- rival_1 = Bill.objects.get(id = spisok[0])
- rival_2 = Bill.objects.get(id = spisok[1])
- rival_1.swiss_rivel = spisok[1]
- rival_2.swiss_rivel = spisok[0]
- rival_1.save()
- rival_2.save()
- else:
- pass
- swiss_players = Bill.objects.all().order_by('-swiss_bill_score')
- new_game = swiss_players.count() // 2
- new_group_1 = (swiss_players[:new_game])
- new_group_2 = (swiss_players[new_game:])
- id_new_group_1 = []
- id_new_group_2 = []
- for n1 in new_group_1:
- igrok = Bill.objects.get(bill_fio = n1)
- id_igrok = igrok.id
- id_new_group_1.append(id_igrok)
- for n2 in new_group_2:
- igrok = Bill.objects.get(bill_fio = n2)
- id_igrok = igrok.id
- id_new_group_2.append(id_igrok)
- result_finish = []
- for single_id in id_new_group_1:
- result = [single_id, random.choice(id_new_group_2)]
- print(request)
- if Bill.objects.get(id=result[0]).swiss_rivel is not None:
- while str(result[1]) in Bill.objects.get(id=result[0]).swiss_rivel:
- result = [single_id, random.choice(id_new_group_2)]
- break
- else:
- result = [single_id, random.choice(id_new_group_2)]
- id_new_group_2.remove(result[1])
- result_2 = [Bill.objects.get(id=result[0]), Bill.objects.get(id=result[1])]
- result_finish.append(result_2)
- if id_new_group_2 != None:
- end_player = [None, Bill.objects.get(id=id_new_group_2[0])]
- result_finish.append(end_player)
- return render_to_response('swiss_result.html', {'swiss_players':swiss_players, 'result_finish':result_finish},
- context_instance=RequestContext(request))
Add Comment
Please, Sign In to add comment