示例#1
0
def admin_points(request):
    if request.method == 'POST':
        form = PointsForm(request.POST)
        if form.is_valid():
            recalculate_points = form.cleaned_data['recalculate_points']
            clear_cache = form.cleaned_data['clear_cache']
            repopulate_cache = form.cleaned_data['repopulate_cache']

            if recalculate_points:
                rounds = Round.objects.all()
                for nmk_round in rounds:
                    recalculate_round_points(nmk_round,
                                             recalculate_total=False)
                recalculate_total_points()
            if clear_cache or repopulate_cache:
                groups = Group.objects.all()
                for group in groups:
                    StandingsCache(group).clear()
                StandingsCache().clear()
                for nmk_round in rounds:
                    RoundStandingsCache.clear_round(nmk_round)
            if repopulate_cache:
                groups = Group.objects.all()
                rounds = Round.objects.order_by('id')
                for group in groups:
                    StandingsCache(group).get(rounds)
                StandingsCache().get(rounds)
                for nmk_round in rounds:
                    for group in groups:
                        RoundStandingsCache(nmk_round, group).get()
                    RoundStandingsCache(nmk_round).get()
    else:
        form = PointsForm()
    return render(request, 'admin_points.html', {'form': form})
示例#2
0
def round_standings(request, round_id):
    this_round = get_object_or_404(Round, pk=int(round_id))
    matches = Match.objects.select_related('round', 'home_team', 'away_team').\
        filter(round=this_round).order_by('start_time', 'id')

    selected_group = request.GET.get('group', '')

    logger.info('User %s is on round standings page for round %s for group %s',
                request.user, this_round.name, selected_group)

    all_groups = Group.objects.filter(players__in=[request.user])
    group = Group.objects.filter(players__in=[request.user]).filter(
        name=selected_group)
    if len(group) != 1:
        selected_group = ''
        group = None
    else:
        group = group[0]

    can_see_standings = False
    is_any_match_started = False
    for match in matches:
        if match.start_time < timezone.now():
            is_any_match_started = True
            break
    if is_any_match_started:
        can_see_standings = True
    else:
        logged_user_rounds = UserRound.objects.filter(user=request.user,
                                                      round=this_round)
        if len(logged_user_rounds
               ) == 1 and not logged_user_rounds[0].shot_allowed:
            can_see_standings = True

    round_standings_list = []

    if can_see_standings:
        round_standings_list = RoundStandingsCache(this_round, group).get()

    return render(
        request, 'roundstandings.html', {
            'can_see_standings': can_see_standings,
            'matches': matches,
            'round_standings': round_standings_list,
            'round': this_round,
            'groups': all_groups,
            'selected_group': selected_group
        })