from django.conf import settings VALUES = ["low", "mid", "high"] def production_year_to_value(production_year): return VALUES[["Dawno", "Średnio", "Niedawno"].index(production_year)] def mileage_to_value(mileage): return VALUES[["Niski", "Średni", "Duży"].index(mileage)] def engine_capacity_to_value(engine_capacity): return VALUES[["Mała", "Średnia", "Ogromna"].index(engine_capacity)] def combustion_to_value(combustion): return VALUES[["Niskie", "Średnie", "Wysokie"].index(combustion)] def map_query_params(query_params): values = {} params = ["production_year", "mileage", "engine_capacity", "combustion"] funcs = [ production_year_to_value, mileage_to_value, engine_capacity_to_value, combustion_to_value, ] for param, func in zip(params, funcs): if query_param := query_params.get(param): values[param] = func(query_param) return values def set_settings_values(data): settings.PRODUCTION_YEAR = get_values(data["production_year"]) settings.MILEAGE = get_values(data["mileage"]) settings.ENGINE_CAPACITY = get_values(data["engine_capacity"]) settings.COMBUSTION = get_values(data["combustion"]) settings.COMPARATOR = float(data["comparator"]["items"][0]["value"]) def get_values(label): low = list(map(float, label["items"][0]["value"].split(","))) mid = list(map(float, label["items"][1]["value"].split(","))) high = list(map(float, label["items"][2]["value"].split(","))) return {"low": low, "mid": mid, "high": high}