コード例 #1
0
ファイル: views.py プロジェクト: TK-IT/kasse
 def form_valid(self, form):
     data = form.cleaned_data
     now = timezone.now()
     tt = TimeTrial(profile=data['profile'],
                    result='',
                    start_time=data['start_time'],
                    creator=self.request.get_or_create_profile(),
                    created_time=now)
     tt.save()
     return HttpResponseRedirect(
         reverse('timetrial_stopwatch',
                 kwargs={'pk': tt.pk}))
コード例 #2
0
 def form_valid(self, form):
     data = form.cleaned_data
     now = timezone.now()
     tt = TimeTrial(profile=data['profile'],
                    result='',
                    start_time=data['start_time'],
                    creator=self.request.get_or_create_profile(),
                    created_time=now)
     tt.save()
     return HttpResponseRedirect(
         reverse('timetrial_stopwatch',
                 kwargs={'pk': tt.pk}))
コード例 #3
0
ファイル: test.py プロジェクト: TK-IT/kasse
 def __iter__(self):
     for tt in self.qs:
         if tt.created_time > self.now:
             continue
         fields = ("pk profile start_time created_time " + "result state residue comment " "").split()
         kwargs = {f: getattr(tt, f) for f in fields}
         res = TimeTrial(**kwargs)
         legs = list(tt.leg_set.all())
         legs = [l for l in legs if l.time < self.now]
         res.leg_count = len(legs)
         res.duration = sum(l.duration for l in legs)
         if res.start_time > self.now:
             res.start_time = None
             res.leg_count = None
             res.duration = None
             res.result = ""
             res.state = "initial"
         elif res.leg_count != tt.leg_count:
             res.result = ""
             res.state = "running"
         yield res
コード例 #4
0
ファイル: views.py プロジェクト: TK-IT/kasse
 def form_valid(self, form):
     data = form.cleaned_data
     now = timezone.now()
     stopwatch = False
     if data['individual_times'] == 'individual':
         durations = data['durations']
     elif data['individual_times'] == 'total':
         zero = datetime.timedelta(seconds=0)
         durations = [zero] * (data['legs'] - 1) + [data['total_time']]
     elif data['individual_times'] == 'stopwatch':
         stopwatch = True
         data['result'] = ''
     else:
         raise ValueError(data['individual_times'])
     tt = TimeTrial(profile=data['profile'],
                    result=data['result'],
                    start_time=data['start_time'],
                    creator=self.request.get_or_create_profile(),
                    created_time=now)
     tt.save()
     if stopwatch:
         return HttpResponseRedirect(
             reverse('timetrial_stopwatch',
                     kwargs={'pk': tt.pk}))
     for i, duration in enumerate(durations):
         leg = Leg(timetrial=tt,
                   duration=duration.total_seconds(),
                   order=i + 1)
         leg.save()
     logger.info("%s %s created by %s",
                 TimeTrial.objects.get(pk=tt.pk),
                 ' '.join(map(str, durations)),
                 self.request.profile,
                 extra=self.request.log_data)
     return HttpResponseRedirect(
         reverse('timetrial_detail',
                 kwargs={'pk': tt.pk}))
コード例 #5
0
 def form_valid(self, form):
     data = form.cleaned_data
     now = timezone.now()
     stopwatch = False
     if data['individual_times'] == 'individual':
         durations = data['durations']
     elif data['individual_times'] == 'total':
         zero = datetime.timedelta(seconds=0)
         durations = [zero] * (data['legs'] - 1) + [data['total_time']]
     elif data['individual_times'] == 'stopwatch':
         stopwatch = True
         data['result'] = ''
     else:
         raise ValueError(data['individual_times'])
     tt = TimeTrial(profile=data['profile'],
                    result=data['result'],
                    start_time=data['start_time'],
                    creator=self.request.get_or_create_profile(),
                    created_time=now)
     tt.save()
     if stopwatch:
         return HttpResponseRedirect(
             reverse('timetrial_stopwatch',
                     kwargs={'pk': tt.pk}))
     for i, duration in enumerate(durations):
         leg = Leg(timetrial=tt,
                   duration=duration.total_seconds(),
                   order=i + 1)
         leg.save()
     logger.info("%s %s created by %s",
                 TimeTrial.objects.get(pk=tt.pk),
                 ' '.join(map(str, durations)),
                 self.request.profile,
                 extra=self.request.log_data)
     return HttpResponseRedirect(
         reverse('timetrial_detail',
                 kwargs={'pk': tt.pk}))
コード例 #6
0
ファイル: views.py プロジェクト: TK-IT/kasse
 def get_timetrial_list(self, **kwargs):
     qs = (
         TimeTrial.leg_prefix(int(self.kwargs['legs']))
         .filter(result='f', **kwargs)
         .order_by('duration')
     )
     qs = self.request.filter_association(qs)
     try:
         qs_distinct = qs.distinct('profile')
         return list(qs_distinct)
     except NotImplementedError:
         res = {}
         for tt in qs:
             res.setdefault(tt.profile_id, tt)
         return sorted(res.values(), key=lambda tt: tt.duration)
コード例 #7
0
 def get_timetrial_list(self, **kwargs):
     qs = (
         TimeTrial.leg_prefix(int(self.kwargs['legs']))
         .filter(result='f', **kwargs)
         .order_by('duration')
     )
     qs = self.request.filter_association(qs)
     try:
         qs_distinct = qs.distinct('profile')
         return list(qs_distinct)
     except NotImplementedError:
         res = {}
         for tt in qs:
             res.setdefault(tt.profile_id, tt)
         return sorted(res.values(), key=lambda tt: tt.duration)
コード例 #8
0
 def get_context_data(self, **kwargs):
     kwargs['do_post'] = False
     kwargs['do_fetch'] = False
     kwargs['form'] = StopwatchForm(instance=TimeTrial(), initial={})
     return super(TimeTrialStopwatchOffline, self).get_context_data(
         **kwargs)
コード例 #9
0
ファイル: test.py プロジェクト: TK-IT/kasse
 def __iter__(self):
     for tt in self.qs:
         if tt.created_time > self.now:
             continue
         fields = ('pk profile start_time created_time ' +
                   'result state residue comment '
                   '').split()
         kwargs = {f: getattr(tt, f) for f in fields}
         res = TimeTrial(**kwargs)
         legs = list(tt.leg_set.all())
         legs = [l for l in legs if l.time < self.now]
         res.leg_count = len(legs)
         res.duration = sum(l.duration for l in legs)
         if res.start_time > self.now:
             res.start_time = None
             res.leg_count = None
             res.duration = None
             res.result = ''
             res.state = 'initial'
         elif res.leg_count != tt.leg_count:
             res.result = ''
             res.state = 'running'
         yield res