(self, value)
return filtered
Determine if passed value should be filtered or not
Determine if passed value should be filtered or not
Determine if passed value should be filtered or not
def filter_property(self, value):
        """ Determine if passed value should be filtered or not """
        filter_field = self
        filter_type = filter_field.filter_type
        filter_value = filter_field.filter_value
        filtered = True
        WEEKDAY_INTS = {
            'monday': 0,
            'tuesday': 1,
            'wednesday': 2,
            'thursday': 3,
            'friday': 4,
            'saturday': 5,
            'sunday': 6,
        }
        if filter_type == 'exact' and str(value) == filter_value:
            filtered = False
        if filter_type == 'iexact' and str(value).lower() == str(filter_value).lower():
            filtered = False
        if filter_type == 'contains' and filter_value in value:
            filtered = False
        if filter_type == 'icontains' and str(filter_value).lower() in str(value).lower():
            filtered = False
        if filter_type == 'in' and value in filter_value:
            filtered = False
        # convert dates and datetimes to timestamps in order to compare digits and date/times the same
        if isinstance(value, datetime.datetime) or isinstance(value, datetime.date):
            value = str(time.mktime(value.timetuple()))
            try:
                filter_value_dt = parser.parse(filter_value)
                filter_value = str(time.mktime(filter_value_dt.timetuple()))
            except ValueError:
                pass
        if filter_type == 'gt' and Decimal(value) > Decimal(filter_value):
            filtered = False
        if filter_type == 'gte' and Decimal(value) >= Decimal(filter_value):
            filtered = False
        if filter_type == 'lt' and Decimal(value) < Decimal(filter_value):
            filtered = False
        if filter_type == 'lte' and Decimal(value) <= Decimal(filter_value):
            filtered = False
        if filter_type == 'startswith' and str(value).startswith(str(filter_value)):
            filtered = False
        if filter_type == 'istartswith' and str(value).lower().startswith(str(filter_value)):
            filtered = False
        if filter_type == 'endswith' and str(value).endswith(str(filter_value)):
            filtered = False
        if filter_type == 'iendswith' and str(value).lower().endswith(str(filter_value)):
            filtered = False
        if filter_type == 'range' and value in [int(x) for x in filter_value]:
            filtered = False
        if filter_type == 'week_day' and WEEKDAY_INTS.get(str(filter_value).lower()) == value.weekday:
            filtered = False
        if filter_type == 'isnull' and value is None:
            filtered = False
        if filter_type == 'regex' and re.search(filter_value, value):
            filtered = False
        if filter_type == 'iregex' and re.search(filter_value, value, re.I):
            filtered = False

        if filter_field.exclude:
            return not filtered
        return filtered
def filter_property ( self , value ) : filter_field = self filter_type = filter_field . filter_type filter_value = filter_field . filter_value filtered = True WEEKDAY_INTS = { 'monday' : 0 , 'tuesday' : 1 , 'wednesday' : 2 , 'thursday' : 3 , 'friday' : 4 , 'saturday' : 5 , 'sunday' : 6 , } if filter_type == 'exact' and str ( value ) == filter_value : filtered = False if filter_type == 'iexact' and str ( value ) . lower ( ) == str ( filter_value ) . lower ( ) : filtered = False if filter_type == 'contains' and filter_value in value : filtered = False if filter_type == 'icontains' and str ( filter_value ) . lower ( ) in str ( value ) . lower ( ) : filtered = False if filter_type == 'in' and value in filter_value : filtered = False # convert dates and datetimes to timestamps in order to compare digits and date/times the same if isinstance ( value , datetime . datetime ) or isinstance ( value , datetime . date ) : value = str ( time . mktime ( value . timetuple ( ) ) ) try : filter_value_dt = parser . parse ( filter_value ) filter_value = str ( time . mktime ( filter_value_dt . timetuple ( ) ) ) except ValueError : pass if filter_type == 'gt' and Decimal ( value ) > Decimal ( filter_value ) : filtered = False if filter_type == 'gte' and Decimal ( value ) >= Decimal ( filter_value ) : filtered = False if filter_type == 'lt' and Decimal ( value ) < Decimal ( filter_value ) : filtered = False if filter_type == 'lte' and Decimal ( value ) <= Decimal ( filter_value ) : filtered = False if filter_type == 'startswith' and str ( value ) . startswith ( str ( filter_value ) ) : filtered = False if filter_type == 'istartswith' and str ( value ) . lower ( ) . startswith ( str ( filter_value ) ) : filtered = False if filter_type == 'endswith' and str ( value ) . endswith ( str ( filter_value ) ) : filtered = False if filter_type == 'iendswith' and str ( value ) . lower ( ) . endswith ( str ( filter_value ) ) : filtered = False if filter_type == 'range' and value in [ int ( x ) for x in filter_value ] : filtered = False if filter_type == 'week_day' and WEEKDAY_INTS . get ( str ( filter_value ) . lower ( ) ) == value . weekday : filtered = False if filter_type == 'isnull' and value is None : filtered = False if filter_type == 'regex' and re . search ( filter_value , value ) : filtered = False if filter_type == 'iregex' and re . search ( filter_value , value , re . I ) : filtered = False if filter_field . exclude : return not filtered return filtered