def reset_match(request): group = Group.objects.get(name='Scorekeepers') if group not in request.user.groups.all(): raise Http404 ss = ScoringSystem.objects.all()[0] match = ss.current_match timer = (match.actual_start + datetime.timedelta(seconds=151)) - tz_aware_now() if timer.days >= 0 and ss.task_id: task = abort_match.delay() revoke(ss.task_id, terminate=True) from celery.task.control import discard_all discard_all() else: prematch_lighting() match.reset() ScoringDevice.objects.all().update(on_center=False) for tower_name in ['low_red', 'high_red', 'low_blue', 'high_blue']: setattr(match, 'scorer_' + tower_name, None) for sd in ScoringDevice.objects.filter(tower__isnull=False): setattr(match, 'scorer_' + sd.tower.name, sd.scorer) match.save() return scorekeeper(request)
def delete_match_event(request): group = Group.objects.get(name='Scorekeepers') if group not in request.user.groups.all(): raise Http404 me = MatchEvent.objects.get(id=request.GET.get('me_id')) me.delete() match = ScoringSystem.objects.all()[0].current_match match.reset_score() start_match_lighting(dry_run_only=True) for me in match.matchevent_set.all().order_by('id'): update_from_match_event(me) match.calculate_scores() return scorekeeper(request)
def select_match(request): group = Group.objects.get(name='Scorekeepers') if group not in request.user.groups.all(): raise Http404 ss = ScoringSystem.objects.all()[0] match = Match.objects.get(id=request.GET.get('match_id')) ss.current_match = match ss.save() if not match.actual_start: for sd in ScoringDevice.objects.filter(tower__isnull=False): if sd.tower.name == 'low_red': match.scorer_low_red = sd.scorer elif sd.tower.name == 'high_red': match.scorer_high_red = sd.scorer elif sd.tower.name == 'low_blue': match.scorer_low_blue = sd.scorer elif sd.tower.name == 'high_blue': match.scorer_high_blue = sd.scorer match.save() prematch_lighting() return scorekeeper(request)
def start_match(request): group = Group.objects.get(name='Scorekeepers') if group not in request.user.groups.all(): raise Http404 if settings.USE_CELERY: task = run_match.delay() print task ss = ScoringSystem.objects.all()[0] ss.task_id = task.task_id ss.save() else: match = ScoringSystem.objects.all()[0].current_match match.reset() ScoringDevice.objects.all().update(on_center=False) match.actual_start = tz_aware_now() match.save() start_match_lighting() return scorekeeper(request)
def pick_scorer(request): group = Group.objects.get(name='Scorekeepers') if group not in request.user.groups.all(): raise Http404 match = ScoringSystem.objects.all()[0].current_match tower_name = request.GET.get('tower_name', '') scorer_id = request.GET.get('scorer_id', '') try: sd = getattr(match, 'scorer_'+tower_name).scoringdevice sd.tower = None sd.save() except: pass if str(scorer_id) == '0': setattr(match, 'scorer_'+tower_name, None) else: setattr(match, 'scorer_'+ tower_name +'_id', scorer_id) match.save() if str(scorer_id) != '0': sd, _ = ScoringDevice.objects.get_or_create(scorer_id=scorer_id) sd.tower = Tower.objects.get(name = tower_name) sd.save() return scorekeeper(request)
def pick_scorer(request): group = Group.objects.get(name='Scorekeepers') if group not in request.user.groups.all(): raise Http404 match = ScoringSystem.objects.all()[0].current_match tower_name = request.GET.get('tower_name', '') scorer_id = request.GET.get('scorer_id', '') try: sd = getattr(match, 'scorer_' + tower_name).scoringdevice sd.tower = None sd.save() except: pass if str(scorer_id) == '0': setattr(match, 'scorer_' + tower_name, None) else: setattr(match, 'scorer_' + tower_name + '_id', scorer_id) match.save() if str(scorer_id) != '0': sd, _ = ScoringDevice.objects.get_or_create(scorer_id=scorer_id) sd.tower = Tower.objects.get(name=tower_name) sd.save() return scorekeeper(request)
def reset_match(request): group = Group.objects.get(name='Scorekeepers') if group not in request.user.groups.all(): raise Http404 ss = ScoringSystem.objects.all()[0] match = ss.current_match timer = (match.actual_start + datetime.timedelta(seconds=151)) - tz_aware_now() if timer.days >= 0 and ss.task_id: task = abort_match.delay() revoke(ss.task_id, terminate=True) from celery.task.control import discard_all discard_all() else: prematch_lighting() match.reset() ScoringDevice.objects.all().update(on_center=False) for tower_name in ['low_red', 'high_red', 'low_blue', 'high_blue']: setattr(match, 'scorer_'+tower_name, None) for sd in ScoringDevice.objects.filter(tower__isnull=False): setattr(match, 'scorer_'+sd.tower.name, sd.scorer) match.save() return scorekeeper(request)