def generate(self, value): # in format: # field_name<10 # or field_name>10 # or field_name=10 # or field_name<10,field_name>10 # 10<field_name<20 don't work # <= and >= don't work try: value = value.lstrip().rstrip() if '<' in value: values = value.split('<') if len(values) == 2: if TypeParser.try_parse(values[1], int): first_value = int(values[1]) return {self.field_name: {'$lt': first_value}} if '>' in value: values = value.split('>') if len(values) == 2: if TypeParser.try_parse(values[1], int): first_value = int(values[1]) return {self.field_name: {'$gt': first_value}} if '>=' in value: values = value.split('>=') if len(values) == 2: if TypeParser.try_parse(values[1], int): first_value = int(values[1]) return {self.field_name: {'$gte': first_value}} if '<=' in value: values = value.split('<=') if len(values) == 2: if TypeParser.try_parse(values[1], int): first_value = int(values[1]) return {self.field_name: {'$lte': first_value}} else: if TypeParser.try_parse(value, int): first_value = int(value) return {self.field_name: first_value} except Exception: return None
def generate(self, value): if TypeParser.try_parse(value, self.list_items_type): return {self.field_name: {"$in": list([self.list_items_type(value)])}} return None
def generate(self, value): if TypeParser.try_parse(value, self.field_type): return {self.field_name: self.field_type(value)} return None