def review_nominated_games_view(self, request, object_id):
season = get_object_or_404(Season, pk=object_id)
if not request.user.has_perm('tournament.review_nominated_games', season.league):
raise PermissionDenied
selections = GameSelection.objects.filter(season=season).order_by('pairing__teamplayerpairing__board_number')
nominations = GameNomination.objects.filter(season=season).order_by('pairing__teamplayerpairing__board_number', 'date_created')
selected_links = set((s.game_link for s in selections))
link_counts = {}
link_to_nom = {}
first_nominations = []
for n in nominations:
value = link_counts.get(n.game_link, 0)
if value == 0:
first_nominations.append(n)
link_to_nom[n.game_link] = n
link_counts[n.game_link] = value + 1
selections = [(link_counts.get(s.game_link, 0), s, link_to_nom.get(s.game_link, None)) for s in selections]
nominations = [(link_counts.get(n.game_link, 0), n) for n in first_nominations if n.game_link not in selected_links]
if season.nominations_open:
self.message_user(request, 'Nominations are still open. You should edit the season and close nominations before reviewing.', messages.WARNING)
context = {
'has_permission': True,
'opts': self.model._meta,
'site_url': '/',
'original': season,
'title': 'Review nominated games',
'selections': selections,
'nominations': nominations,
'is_team': season.league.competitor_type == 'team',
}
return render(request, 'tournament/admin/review_nominated_games.html', context)
评论列表
文章目录