Beispiel #1
0
    def clean(self):
        if any(self.errors):
            return
        dates = []
        additional_column = None
        if self.usage_type.by_warehouse:
            additional_column = 'warehouse'
        elif self.usage_type.by_team:
            additional_column = 'team'
        elif self.usage_type.by_internet_provider:
            additional_column = 'internet_provider'
        msg = _("Another cost time interval with the same type "
                "(and warehouse/team/internet_provider) overlaps with this "
                "time interval.")

        for i in xrange(self.total_form_count()):
            form = self.forms[i]
            start = form.cleaned_data.get('start')
            end = form.cleaned_data.get('end')
            additional_value = form.cleaned_data.get(additional_column)
            if not start or not end:
                continue
            for other_start, other_end, other_additional in dates:
                # if additional values (eg. warehouse or team) are the same
                # or there is no additional column and dateranges are
                # overlapping
                if ((other_additional == additional_value
                     and additional_column)
                        or not additional_column) and ranges_overlap(
                            start, end, other_start, other_end):
                    form._errors['start'] = form.error_class([msg])
                    form._errors['end'] = form.error_class([msg])
                    break
            else:
                dates.append((start, end, additional_value))
Beispiel #2
0
    def clean(self):
        if any(self.errors):
            return
        dates = []
        additional_column = None
        if self.usage_type.by_warehouse:
            additional_column = 'warehouse'
        elif self.usage_type.by_team:
            additional_column = 'team'
        elif self.usage_type.by_internet_provider:
            additional_column = 'internet_provider'
        msg = _("Another cost time interval with the same type "
                "(and warehouse/team/internet_provider) overlaps with this "
                "time interval.")

        for i in xrange(self.total_form_count()):
            form = self.forms[i]
            start = form.cleaned_data.get('start')
            end = form.cleaned_data.get('end')
            additional_value = form.cleaned_data.get(additional_column)
            if not start or not end:
                continue
            for other_start, other_end, other_additional in dates:
                # if additional values (eg. warehouse or team) are the same
                # or there is no additional column and dateranges are
                # overlapping
                if (
                   (other_additional == additional_value and additional_column)
                   or not additional_column
                   ) and ranges_overlap(start, end, other_start, other_end):
                    form._errors['start'] = form.error_class([msg])
                    form._errors['end'] = form.error_class([msg])
                    break
            else:
                dates.append((start, end, additional_value))
Beispiel #3
0
 def test_not_overlapping(self):
     self.assertFalse(utils.ranges_overlap(10, 15, 16, 30))
     self.assertFalse(utils.ranges_overlap(15, 30, 10, 14))
Beispiel #4
0
 def test_overlap_outside(self):
     self.assertTrue(utils.ranges_overlap(15, 25, 10, 30))
Beispiel #5
0
 def test_overlap_inside(self):
     self.assertTrue(utils.ranges_overlap(10, 30, 15, 25))
Beispiel #6
0
 def test_overlap_on_end(self):
     self.assertTrue(utils.ranges_overlap(20, 30, 15, 25))
Beispiel #7
0
 def test_overlap_on_start(self):
     self.assertTrue(utils.ranges_overlap(10, 20, 15, 25))