コード例 #1
0
ファイル: event.py プロジェクト: BrATdev/donation-tracker
    def save(self, fix_time=True, fix_runners=True, *args, **kwargs):
        can_fix_time = self.order != None and self.run_time != None and self.setup_time != None
        i = TimestampField.time_string_to_int

        # fix our own time
        if fix_time and can_fix_time:
            prev = SpeedRun.objects.filter(event=self.event,
                                           order__lt=self.order).last()
            if prev:
                self.starttime = prev.starttime + datetime.timedelta(
                    milliseconds=i(prev.run_time) + i(prev.setup_time))
            else:
                self.starttime = self.event.timezone.localize(
                    datetime.datetime.combine(self.event.date,
                                              datetime.time(11, 30)))
            self.endtime = self.starttime + datetime.timedelta(
                milliseconds=i(self.run_time) + i(self.setup_time))

        if fix_runners and self.id:
            if not self.runners.exists():
                try:
                    self.runners.add(*[
                        Runner.objects.get_by_natural_key(r)
                        for r in util.natural_list_parse(
                            self.deprecated_runners, symbol_only=True)
                    ])
                except Runner.DoesNotExist:
                    pass
            if self.runners.exists():
                self.deprecated_runners = u', '.join(
                    unicode(r) for r in self.runners.all())

        super(SpeedRun, self).save(*args, **kwargs)

        # fix up all the others if requested
        if fix_time:
            if can_fix_time:
                next = SpeedRun.objects.filter(event=self.event,
                                               order__gt=self.order).first()
                starttime = self.starttime + datetime.timedelta(
                    milliseconds=i(self.run_time) + i(self.setup_time))
                if next and next.starttime != starttime:
                    return [self] + next.save(*args, **kwargs)
            elif self.starttime:
                prev = SpeedRun.objects.filter(
                    event=self.event,
                    starttime__lte=self.starttime).exclude(order=None).last()
                if prev:
                    self.starttime = prev.starttime + datetime.timedelta(
                        milliseconds=i(prev.run_time) + i(prev.setup_time))
                else:
                    self.starttime = self.event.timezone.localize(
                        datetime.datetime.combine(self.event.date,
                                                  datetime.time(11, 30)))
                next = SpeedRun.objects.filter(
                    event=self.event,
                    starttime__gte=self.starttime).exclude(order=None).first()
                if next and next.starttime != self.starttime:
                    return [self] + next.save(*args, **kwargs)
        return [self]
コード例 #2
0
    def save(self, fix_time=True, fix_runners=True, *args, **kwargs):
        i = TimestampField.time_string_to_int
        can_fix_time = self.order is not None and (
            i(self.run_time) != 0 or i(self.setup_time) != 0)

        # fix our own time
        if fix_time and can_fix_time:
            prev = SpeedRun.objects.filter(
                event=self.event, order__lt=self.order).last()
            if prev:
                self.starttime = prev.starttime + \
                    datetime.timedelta(milliseconds=i(
                        prev.run_time) + i(prev.setup_time))
            else:
                self.starttime = self.event.datetime
            self.endtime = self.starttime + \
                datetime.timedelta(milliseconds=i(
                    self.run_time) + i(self.setup_time))

        if fix_runners and self.id:
            if not self.runners.exists():
                try:
                    self.runners.add(*[Runner.objects.get_by_natural_key(r) for r in
                                       util.natural_list_parse(self.deprecated_runners, symbol_only=True)])
                except Runner.DoesNotExist:
                    pass
            if self.runners.exists():
                self.deprecated_runners = u', '.join(
                    unicode(r) for r in self.runners.all())

        super(SpeedRun, self).save(*args, **kwargs)

        # fix up all the others if requested
        if fix_time:
            if can_fix_time:
                next = SpeedRun.objects.filter(
                    event=self.event, order__gt=self.order).first()
                starttime = self.starttime + \
                    datetime.timedelta(milliseconds=i(
                        self.run_time) + i(self.setup_time))
                if next and next.starttime != starttime:
                    return [self] + next.save(*args, **kwargs)
            elif self.starttime:
                prev = SpeedRun.objects.filter(event=self.event, starttime__lte=self.starttime).exclude(
                    order=None).last()
                if prev:
                    self.starttime = prev.starttime + datetime.timedelta(
                        milliseconds=i(prev.run_time) + i(prev.setup_time))
                else:
                    self.starttime = self.event.timezone.localize(
                        datetime.datetime.combine(self.event.date, datetime.time(12)))
                next = SpeedRun.objects.filter(event=self.event, starttime__gte=self.starttime).exclude(
                    order=None).first()
                if next and next.starttime != self.starttime:
                    return [self] + next.save(*args, **kwargs)
        return [self]