f491fb33b0d0326a9d0238ffbad82118f6a3b9ca
[wolnelektury.git] / src / experiments / templatetags / experiments.py
1 from django.conf import settings
2 from django.template import Library
3
4
5 register = Library()
6
7
8 @register.inclusion_tag('experiments/switch.html', takes_context=True)
9 def experiments_switcher(context):
10     tests = []
11     explicit = False
12     for exp in settings.EXPERIMENTS:
13         currval = context['request'].EXPERIMENTS.get(exp['slug'])
14         if exp.get('switchable') or context.get('EXPERIMENTS_SWITCHABLE_' + test['slug']):
15             tests.append((exp, currval))
16             for cohort in exp.get('cohorts'):
17                 if cohort.get('explicit') and cohort.get('value') == currval:
18                     explicit = True
19     return {
20         'tests': tests,
21         'explicit': explicit,
22     }