Fixes and experiments.
authorRadek Czajka <rczajka@rczajka.pl>
Tue, 23 May 2023 10:24:23 +0000 (12:24 +0200)
committerRadek Czajka <rczajka@rczajka.pl>
Tue, 23 May 2023 10:24:23 +0000 (12:24 +0200)
src/catalogue/views.py
src/experiments/base.py
src/experiments/experiments.py
src/experiments/templates/experiments/main_switch.html
src/wolnelektury/settings/custom.py
src/wolnelektury/templates/2022/main_page.html
src/wolnelektury/views.py

index 16b66f0..2b188e6 100644 (file)
@@ -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':
index 726f451..92b1bc1 100644 (file)
@@ -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(
index df1b23a..15c103f 100644 (file)
@@ -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,
 ]
index c02ca48..7638e1f 100644 (file)
@@ -9,6 +9,7 @@
   <img src="https://upload.wikimedia.org/wikipedia/commons/c/c8/MH1Asimulator.JPG" style="width:100%">
 
   {% for exp in request.EXPERIMENTS.values %}
+    {% if exp.switchable or request.user.is_staff %}
     <div class="experiment nice-controls" data-slug="{{ exp.slug }}">
       <span>
         {{ exp.name }}
@@ -24,6 +25,7 @@
           {% endif %}
           data-value="off">wyłączony</button>
     </div>
+    {% endif %}
   {% endfor %}
 {% endblock %}
 
index fa1b8d2..07c1bfe 100644 (file)
@@ -67,5 +67,6 @@ CIVICRM_ACTIVITIES = {
 }
 
 EXPERIMENTS_LAYOUT = 0
+EXPERIMENTS_SOWKA = 0
 
 WIDGETS = {}
index 5517123..ca9d958 100644 (file)
   <main class="l-main">
 
     {% if widget %}
+      <div class="l-change-pop show"><p>{{ widget.description }}</p></div>
       <section class="l-section">
-        <iframe src="{{ widget}}" style="width: 100%; height: 600px; border: none;"></iframe>
+        <iframe src="{{ widget.url }}" style="width: 100%; height: 600px; border: none;"></iframe>
       </section>
     {% endif %}
 
index 49110e9..9f099bd 100644 (file)
@@ -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)