X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/24721591455e048cffca365384e6759daae05916..24f09a9815fff57bde69683b12980480fd8dc6a2:/src/experiments/middleware.py diff --git a/src/experiments/middleware.py b/src/experiments/middleware.py index 080aee2bc..73e93e400 100644 --- a/src/experiments/middleware.py +++ b/src/experiments/middleware.py @@ -1,38 +1,12 @@ -import hashlib -from django.conf import settings +from .experiments import experiments def experiments_middleware(get_response): def middleware(request): exps = {} - overrides = getattr(settings, 'EXPERIMENTS_OVERRIDES', {}) - for exp in settings.EXPERIMENTS: - slug = exp['slug'] - if slug in overrides: - exps[slug] = overrides[slug] - continue - - cookie_value = request.COOKIES.get(f'EXPERIMENT_{slug}') - if cookie_value is not None: - for cohort in exp.get('cohorts', []): - if cohort['value'] == cookie_value: - exps[slug] = cookie_value - break - - if slug not in exps: - number = int( - # TODO sth else? - hashlib.md5( - (slug + request.META['REMOTE_ADDR']).encode('utf-8') - ).hexdigest(), - 16 - ) % 10e6 / 10e6 - for cohort in exp.get('cohorts', []): - number -= cohort.get('size', 1) - if number < 0: - exps[slug] = cohort['value'] - break + for exp in experiments: + exps[exp.slug] = exp(request) request.EXPERIMENTS = exps response = get_response(request)