X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/8a078a30db08afb680c48ce94d6e576236febeed..6dc65dcaa0245bfb27f1a857016b8c25f8214557:/src/experiments/base.py?ds=inline diff --git a/src/experiments/base.py b/src/experiments/base.py index 3430df289..92b1bc1bd 100644 --- a/src/experiments/base.py +++ b/src/experiments/base.py @@ -7,31 +7,34 @@ class Experiment: name = 'experiment' explicit = False size = 0 + switchable = True def qualify(self, request): return True def __init__(self, request): - self.value = self.get_value(request) + self.value, self.manual = self.get_value(request) def override(self, value): self.value = value + self.manual = False def get_value(self, request): overrides = getattr(settings, 'EXPERIMENTS_OVERRIDES', {}) slug = self.slug if slug in overrides: - return overrides[slug] + return overrides[slug], False if self.qualify(request) is False: - return None + return None, False - cookie_value = request.COOKIES.get(f'EXPERIMENT_{slug}') - if cookie_value is not None: - if cookie_value == 'on': - return True - elif cookie_value == 'off': - return False + if self.switchable or request.user.is_staff: + cookie_value = request.COOKIES.get(f'EXPERIMENT_{slug}') + if cookie_value is not None: + if cookie_value == 'on': + return True, True + elif cookie_value == 'off': + return False, True number = int( hashlib.md5( @@ -39,4 +42,4 @@ class Experiment: ).hexdigest(), 16 ) % 10e6 / 10e6 - return number < self.size + return number < self.size, False