def parser(self, param): datas = self.args.get(param) if self.request else None parser = {} if test(datas): for data in datas.split(self.Separators._separator): fields_separator, category, fields = self.dispatch(data) if category not in parser: parser[category] = {"fields": [], "operator": operator.or_} qfields = [fields_separator] for field in fields: qfields.append(self.field(field[0], field[1])) parser[category]["fields"].append(qfields) logger.info("%s - array: %s" % (param, parser), self.request.user if self.request else None, app=self.__class__.__name__) sql = [] for category, options in parser.items(): sql.append( reduce(options["operator"], [ reduce(fields.pop(0), (field for field in fields)) for fields in options["fields"] ])) logger.info("%s - sql: %s" % (param, sql), self.request.user if self.request else None, app=self.__class__.__name__) return [parser, sql] return []
def get_fdistinct(self): param = self.args.get( self.Arguments.fdistinct) if self.request else None logger.info("fdistinct: %s" % param, self.request.user if self.request else None, app=self.__class__.__name__) return param.split( self.Separators._category) if test(param) else self.fdistinct
def search(self, param="search", *args, **kwargs): psearch = param search_param = self.request.GET.get(self.param(psearch)) if test(search_param): search_param = search_param.split(self.separator(psearch)) the_Q = self.get_S(search_param[0], param) if len(search_param) > 1: for search in search_param[1:]: the_Q.add( self.get_S(search, param), kwargs["operator"] if "operator" in kwargs else Q.AND) return the_Q return None
def params(self): Qparams = Q() for param, options in self.nparams.items(): datas = self.args.get(param) if self.request else None if test(datas): datas = datas.split(self.Separators._separator) Qparam = reduce(operator.or_, (self.getQ("%s__%s" % (field, options["mask"]), datas[0]) for field in options["fields"])) if len(datas) > 1: for data in datas[1:]: Qparam.add( reduce( operator.or_, (self.getQ("%s__%s" % (field, options["mask"]), data) for field in options["fields"])), Q.AND) Qparams.add(Qparam, Q.AND) return Qparams
def filter(self, *args, **kwargs): param = kwargs["param"] if "param" in kwargs else "filter" operator = kwargs["operator"] if "operator" in kwargs else Q.OR negative = kwargs["negative"] if "negative" in kwargs else False filter_param = self.request.GET.get(self.param(param)) if test(filter_param): filters = {} for filtr in filter_param.split(self.separator(param)): category, field, value = self.dispatch(param, filtr) if category not in filters: filters[category] = [] filters[category].append(self.get_F(field, value, **kwargs)) for category, filtr in filters.items(): newf = Q() for filtr in filters[category]: newf |= filtr filters[category] = newf newf = Q() for category, filtr in filters.items(): newf &= filtr filters = newf return filters return None
def get_order(self): param = self.args.get(self.Arguments.order) if self.request else None logger.info("order: %s" % param, self.request.user if self.request else None, app=self.__class__.__name__) return param.split(self.Separators._pos) if test(param) else self.order
def test(self, data): return functions.test(data, search=self.testconfig)
def set_display(self): if self.FORCE_UPDATE_DISPLAY or self.display is None and test( self.__str__()): self.display = str(self.__str__())
def limit(self): limit_param = self.request.GET.get(self.param("limit")) return limit_param.split(":") if test(limit_param) else False
def order(self): order_param = self.request.GET.get(self.param("order")) return order_param.split() if test(order_param) else list( self.fields("order").keys())
def distinct(self): distinct_param = self.request.GET.get(self.param("distinct")) return distinct_param.split() if test(distinct_param) else list( self.fields("distinct").keys())