From: Radek Czajka Date: Tue, 23 May 2023 10:24:23 +0000 (+0200) Subject: Fixes and experiments. X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/9d763695198b109f00b5d88a5cfe0190871271aa?ds=sidebyside;hp=031b8be3bf03baa724dd7e225b0555726d089341 Fixes and experiments. --- diff --git a/src/catalogue/views.py b/src/catalogue/views.py index 16b66f0fb..2b188e684 100644 --- a/src/catalogue/views.py +++ b/src/catalogue/views.py @@ -109,13 +109,14 @@ def object_list(request, objects, fragments=None, related_tags=None, tags=None, Tag.objects.usage_for_queryset( objects, counts=True ).exclude(category='set').exclude(pk__in=tag_ids)) - related_tag_lists.append( - Tag.objects.usage_for_queryset( - objects, counts=True - ).filter( - user=request.user - ).exclude(name='').exclude(pk__in=tag_ids) - ) + if request.user.is_authenticated: + related_tag_lists.append( + Tag.objects.usage_for_queryset( + objects, counts=True + ).filter( + user=request.user + ).exclude(name='').exclude(pk__in=tag_ids) + ) if not (extra and extra.get('theme_is_set')): if fragments is None: if list_type == 'gallery': diff --git a/src/experiments/base.py b/src/experiments/base.py index 726f451cd..92b1bc1bd 100644 --- a/src/experiments/base.py +++ b/src/experiments/base.py @@ -7,6 +7,7 @@ class Experiment: name = 'experiment' explicit = False size = 0 + switchable = True def qualify(self, request): return True @@ -27,12 +28,13 @@ class Experiment: if self.qualify(request) is False: return None, False - 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 + 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( diff --git a/src/experiments/experiments.py b/src/experiments/experiments.py index df1b23a4a..15c103ff7 100644 --- a/src/experiments/experiments.py +++ b/src/experiments/experiments.py @@ -14,6 +14,14 @@ class NewLayout(Experiment): return False +class Sowka(Experiment): + slug = 'sowka' + name = 'Pan Sówka' + size = settings.EXPERIMENTS_SOWKA + switchable = False + + experiments = [ NewLayout, + Sowka, ] diff --git a/src/experiments/templates/experiments/main_switch.html b/src/experiments/templates/experiments/main_switch.html index c02ca488a..7638e1f76 100644 --- a/src/experiments/templates/experiments/main_switch.html +++ b/src/experiments/templates/experiments/main_switch.html @@ -9,6 +9,7 @@ {% for exp in request.EXPERIMENTS.values %} + {% if exp.switchable or request.user.is_staff %}
{{ exp.name }} @@ -24,6 +25,7 @@ {% endif %} data-value="off">wyłączony
+ {% endif %} {% endfor %} {% endblock %} diff --git a/src/wolnelektury/settings/custom.py b/src/wolnelektury/settings/custom.py index fa1b8d29a..07c1bfee8 100644 --- a/src/wolnelektury/settings/custom.py +++ b/src/wolnelektury/settings/custom.py @@ -67,5 +67,6 @@ CIVICRM_ACTIVITIES = { } EXPERIMENTS_LAYOUT = 0 +EXPERIMENTS_SOWKA = 0 WIDGETS = {} diff --git a/src/wolnelektury/templates/2022/main_page.html b/src/wolnelektury/templates/2022/main_page.html index 551712390..ca9d9586c 100644 --- a/src/wolnelektury/templates/2022/main_page.html +++ b/src/wolnelektury/templates/2022/main_page.html @@ -141,8 +141,9 @@
{% if widget %} +

{{ widget.description }}

- +
{% endif %} diff --git a/src/wolnelektury/views.py b/src/wolnelektury/views.py index 49110e938..9f099bd3a 100644 --- a/src/wolnelektury/views.py +++ b/src/wolnelektury/views.py @@ -32,12 +32,16 @@ def main_page_2022(request): ctx['recommended_collection'] = Collection.objects.filter(listed=True, role='recommend').order_by('?').first() ctx['ambassadors'] = club.models.Ambassador.objects.all().order_by('?') ctx['widget'] = settings.WIDGETS.get(request.GET.get('w')) + if not ctx['widget'] and request.EXPERIMENTS['sowka'].value: + ctx['widget'] = settings.WIDGETS['pan-sowka'] return render(request, '2022/main_page.html', ctx) @never_cache def main_page(request): if request.GET.get('w') in settings.WIDGETS: request.EXPERIMENTS['layout'].override(True) + if request.EXPERIMENTS['sowka'].value: + request.EXPERIMENTS['layout'].override(True) if request.EXPERIMENTS['layout'].value: return main_page_2022(request)