Beispiel #1
0
    def build_filters(self, filters=None):
        """allow filtering by unit"""
        if filters is None:
            filters = {}

        orm_filters = super(TestInstanceResource, self).build_filters()

        today = timezone.timezone.now()
        last_year = today - timezone.timezone.timedelta(days=365)
        filters_requiring_processing = (
            ("from_date", "work_completed__gte", "date",
             today.strftime(settings.SIMPLE_DATE_FORMAT)),
            ("to_date", "work_completed__lte", "date",
             last_year.strftime(settings.SIMPLE_DATE_FORMAT)),
            ("unit", "unit_test_info__unit__number__in", None, []),
            ("slug", "unit_test_info__test__slug__in", None, []),
            ("status", "status__slug__in", None, []),
        )

        for field, filter_string, filter_type, default in filters_requiring_processing:

            value = filters.pop(field, default)

            if filter_type == "date":
                try:
                    value = timezone.datetime.datetime.strptime(
                        value[0], settings.SIMPLE_DATE_FORMAT)
                    value = timezone.make_aware(value)
                    orm_filters[filter_string] = value
                except (ValueError, IndexError, TypeError):
                    pass
            else:
                orm_filters[filter_string] = value

        # non specfic list filters
        for key in filters:
            if key in self.Meta.filtering:
                orm_filters["%s__in" % key] = filters.getlist(key)

        return orm_filters
Beispiel #2
0
    def build_filters(self, filters=None):
        """allow filtering by unit"""
        if filters is None:
            filters = {}

        orm_filters = super(TestInstanceResource, self).build_filters()

        today = timezone.timezone.now()
        last_year = today - timezone.timezone.timedelta(days=365)
        filters_requiring_processing = (
            ("from_date", "work_completed__gte", "date", today.strftime(settings.SIMPLE_DATE_FORMAT)),
            ("to_date", "work_completed__lte", "date", last_year.strftime(settings.SIMPLE_DATE_FORMAT)),
            ("unit", "unit_test_info__unit__number__in", None, []),
            ("slug", "unit_test_info__test__slug__in", None, []),
            ("status", "status__slug__in", None, []),
        )

        for field, filter_string, filter_type, default in filters_requiring_processing:

            value = filters.pop(field, default)

            if filter_type == "date":
                try:
                    value = timezone.datetime.datetime.strptime(value[0], settings.SIMPLE_DATE_FORMAT)
                    value = timezone.make_aware(value)
                    orm_filters[filter_string] = value
                except (ValueError, IndexError, TypeError):
                    pass
            else:
                orm_filters[filter_string] = value

        # non specfic list filters
        for key in filters:
            if key in self.Meta.filtering:
                orm_filters["%s__in" % key] = filters.getlist(key)

        return orm_filters
Beispiel #3
0
 def mk_datetime(string):
     return make_aware(
         datetime.datetime.fromtimestamp(
             time.mktime(email.utils.parsedate(string))))
 def mk_datetime(string):
     return make_aware(datetime.datetime.fromtimestamp(time.mktime(
         email.utils.parsedate(string))))