Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add official support for Wagtail 5.0, 5.1 and 5.2 #61

Merged
merged 12 commits into from
Nov 15, 2023
14 changes: 11 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [Unreleased] - XXXX-XX-XX

- Wagtail 4.2 compatibility
- Wagtail 4.1 compatibility
- [Wagtail 4.1, 4.2, 5.0, 5.1 and 5.2 support 🎉](https://github.com/wagtail-nest/wagtail-ab-testing/pull/52)
- NO SUPPORT for Wagtail 4.0 and older, sorry
- [Revisions that are part of A/B test are now marked as protected to avoid data loss when the revision is deleted](https://github.com/wagtail-nest/wagtail-ab-testing/pull/54)

**Maintenance**

- The package was moved to Wagtail Nest
- Move to GitHub Actions for CI
- Move to Codecov for coverage
- [Add Trusted Publishing for publishing to PyPI](https://github.com/wagtail-nest/wagtail-ab-testing/pull/60)
- [Upload wheels to PyPI for faster installs](https://github.com/wagtail-nest/wagtail-ab-testing/pull/60)

## [0.7] - 2022-03-31

Expand Down
Binary file modified screenshot-create.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshot-finish.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env python

import sys, os

from setuptools import setup, find_packages

# Hack to prevent "TypeError: 'NoneType' object is not callable" error
Expand Down Expand Up @@ -38,8 +36,10 @@
"Framework :: Django :: 3.2",
"Framework :: Django :: 4.0",
"Framework :: Django :: 4.1",
"Framework :: Django :: 4.2",
"Framework :: Wagtail",
"Framework :: Wagtail :: 4",
"Framework :: Wagtail :: 5",
],
install_requires=[
"Wagtail>=4.1",
Expand Down
4 changes: 4 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ usedevelop = True
envlist =
py{38,39,310}-django{32,40,41}-wagtail{41,42}-{sqlite,postgres}
py311-django41-wagtail{41,42}-{sqlite,postgres}
py{38,39,310,311}-django{32,41,42}-wagtail{50,51,52}-{sqlite,postgres}

[flake8]
# E501: Line too long
Expand All @@ -31,6 +32,9 @@ deps =

wagtail41: wagtail~=4.1
wagtail42: wagtail~=4.2
wagtail50: wagtail~=5.0
wagtail51: wagtail~=5.1
wagtail52: wagtail~=5.2
wagtailmain: git+https://github.com/wagtail/wagtail.git

postgres: psycopg2>=2.9
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{% block content %}
{% trans "Create an A/B Test" as title %}
{% include "wagtailadmin/shared/header.html" with title=title subtitle=page.title icon='people-arrows' tabbed=1 merged=1 %}
{% include "wagtailadmin/shared/header.html" with title=title subtitle=page.title icon='people-arrows' merged=1 %}

<div class="nice-padding" style="padding-top: 20px;">
<p>{% trans "This will create an A/B test comparing the published version of this page and the draft with the following differences:" %}</p>
Expand Down
18 changes: 12 additions & 6 deletions wagtail_ab_testing/templates/wagtail_ab_testing/add_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{% block content %}
{% trans "Create an A/B Test" as title %}
{% include "wagtailadmin/shared/header.html" with title=title subtitle=page.title icon='people-arrows' tabbed=1 merged=1 %}
{% include "wagtailadmin/shared/header.html" with title=title subtitle=page.title icon='people-arrows' merged=1 %}

<form method="post">
{% csrf_token %}
Expand All @@ -16,8 +16,12 @@ <h3>{% trans "Enter test details" %}</h3>

<div class="section__content nice-padding">
<ul class="fields">
{% include "wagtailadmin/shared/field_as_li.html" with field=form.name %}
{% include "wagtailadmin/shared/field_as_li.html" with field=form.hypothesis %}
<li>
{% include "wagtailadmin/shared/field.html" with field=form.name %}
</li>
<li>
{% include "wagtailadmin/shared/field.html" with field=form.hypothesis %}
</li>
</ul>
</div>
</section>
Expand All @@ -41,7 +45,9 @@ <h3>{% trans "Sample size" %}</h3>

<div class="section__content nice-padding">
<ul class="fields">
{% include "wagtailadmin/shared/field_as_li.html" with field=form.sample_size %}
<li>
{% include "wagtailadmin/shared/field.html" with field=form.sample_size %}
</li>
</ul>
{% trans 'Need help calculating sample size for A/B tests? Try <a href="https://www.optimizely.com/uk/sample-size-calculator/" target="_blank">Optimisely</a>, <a href="https://www.evanmiller.org/ab-testing/sample-size.html" target="_blank">Evan Miller</a>, or <a href="https://www.abtasty.com/sample-size-calculator/" target="_blank">AB Tasty</a>.' %}
</div>
Expand All @@ -53,11 +59,11 @@ <h3>{% trans "Sample size" %}</h3>
</p>

<div class="nice-padding">
<div class="help-block help-info">
{% help_block status="info"%}
<p>{% trans "A/B tests are calculated using Pearson's chi squared test and are set at 95% confidence level." %}</p>
<p>{% trans "Traffic is split evenly between each version." %}</p>
<p>{% trans 'Users with "<a href="https://en.wikipedia.org/wiki/Do_Not_Track" target="_blank">Do Not Track</a>" enabled are not counted.' %}</p>
</div>
{% endhelp_block %}
</div>
</form>
{% endblock %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{% block content %}
{% trans "Compare A/B test versions" as title %}
{% include "wagtailadmin/shared/header.html" with title=title subtitle=page.title tabbed=1 merged=1 %}
{% include "wagtailadmin/shared/header.html" with title=title subtitle=page.title merged=1 %}

<div class="nice-padding" style="padding-top: 20px;">
{% include "./includes/comparison.html" %}
Expand Down
4 changes: 2 additions & 2 deletions wagtail_ab_testing/templates/wagtail_ab_testing/progress.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
<form action="{% url 'wagtailadmin_pages:edit' page.id %}" method="POST">
{% csrf_token %}

<footer>
<footer class="footer">
<nav aria-label="{% trans 'Actions' %}">
<ul>
<li class="actions actions--primary">
<li class="actions actions--primary footer__container">
<div class="dropdown dropup dropdown-button match-width">
{{ action_menu.render_html }}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{% block content %}
{% trans "A/B testing activity log" as title %}
{% include "wagtailadmin/shared/header.html" with title=title icon='people-arrows' tabbed=1 merged=1 %}
{% include "wagtailadmin/shared/header.html" with title=title icon='people-arrows' merged=1 %}

<div class="nice-padding">
<h2>{{ ab_test.name }}</h2>
Expand Down
3 changes: 0 additions & 3 deletions wagtail_ab_testing/test/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
"wagtail.search",
"wagtail.admin",
"wagtail.api.v2",
"wagtail.contrib.modeladmin",
"wagtail.contrib.routable_page",
"wagtail.contrib.styleguide",
"wagtail.sites",
Expand Down Expand Up @@ -149,8 +148,6 @@

USE_I18N = True

USE_L10N = True

USE_TZ = True


Expand Down
6 changes: 5 additions & 1 deletion wagtail_ab_testing/test/tests/test_add_abtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.test import TestCase
from django.urls import reverse

from wagtail import VERSION as WAGTAIL_VERSION
from wagtail.models import Page
from wagtail.test.utils import WagtailTestUtils

Expand Down Expand Up @@ -204,7 +205,10 @@ def test_post_add_form_start(self):
self.assertEqual(ab_test.status, AbTest.STATUS_RUNNING)

def test_post_add_form_start_without_publish_permission(self):
self.moderators_group.page_permissions.filter(permission_type='publish').delete()
if WAGTAIL_VERSION >= (5, 1):
self.moderators_group.page_permissions.filter(permission__codename='publish_page').delete()
else:
self.moderators_group.page_permissions.filter(permission_type='publish').delete()

response = self.client.post(reverse('wagtail_ab_testing_admin:add_ab_test_form', args=[self.page.id]), {
'name': 'Test',
Expand Down
22 changes: 18 additions & 4 deletions wagtail_ab_testing/test/tests/test_progress.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from django.contrib.auth.models import Group, Permission

from django.contrib.contenttypes.models import ContentType
from django.test import TestCase
from django.urls import reverse

from wagtail import VERSION as WAGTAIL_VERSION
from wagtail.models import Page
from wagtail.test.utils import WagtailTestUtils

Expand Down Expand Up @@ -96,7 +98,10 @@ def test_post_end(self):
self.assertEqual(self.ab_test.status, AbTest.STATUS_CANCELLED)

def test_post_start_without_publish_permission(self):
self.moderators_group.page_permissions.filter(permission_type='publish').delete()
if WAGTAIL_VERSION >= (5, 1):
self.moderators_group.page_permissions.filter(permission__codename='publish_page').delete()
else:
self.moderators_group.page_permissions.filter(permission_type='publish').delete()

self.ab_test.status = AbTest.STATUS_DRAFT
self.ab_test.save()
Expand All @@ -112,7 +117,10 @@ def test_post_start_without_publish_permission(self):
self.assertEqual(self.ab_test.status, AbTest.STATUS_DRAFT)

def test_post_pause_without_publish_permission(self):
self.moderators_group.page_permissions.filter(permission_type='publish').delete()
if WAGTAIL_VERSION >= (5, 1):
self.moderators_group.page_permissions.filter(permission__codename='publish_page').delete()
else:
self.moderators_group.page_permissions.filter(permission_type='publish').delete()

response = self.client.post(reverse('wagtailadmin_pages:edit', args=[self.page.id]), {
'action-pause-ab-test': 'on',
Expand All @@ -125,7 +133,10 @@ def test_post_pause_without_publish_permission(self):
self.assertEqual(self.ab_test.status, AbTest.STATUS_RUNNING)

def test_post_restart_without_publish_permission(self):
self.moderators_group.page_permissions.filter(permission_type='publish').delete()
if WAGTAIL_VERSION >= (5, 1):
self.moderators_group.page_permissions.filter(permission__codename='publish_page').delete()
else:
self.moderators_group.page_permissions.filter(permission_type='publish').delete()

self.ab_test.status = AbTest.STATUS_PAUSED
self.ab_test.save()
Expand All @@ -140,7 +151,10 @@ def test_post_restart_without_publish_permission(self):
self.assertEqual(self.ab_test.status, AbTest.STATUS_PAUSED)

def test_post_end_without_publish_permission(self):
self.moderators_group.page_permissions.filter(permission_type='publish').delete()
if WAGTAIL_VERSION >= (5, 1):
self.moderators_group.page_permissions.filter(permission__codename='publish_page').delete()
else:
self.moderators_group.page_permissions.filter(permission_type='publish').delete()

response = self.client.post(reverse('wagtailadmin_pages:edit', args=[self.page.id]), {
'action-end-ab-test': 'on',
Expand Down
33 changes: 9 additions & 24 deletions wagtail_ab_testing/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from wagtail.admin.action_menu import ActionMenuItem
from wagtail.admin.filters import DateRangePickerWidget, WagtailFilterSet
from wagtail.admin.views.reports import ReportView
from wagtail.models import Page, PAGE_MODEL_CLASSES, UserPagePermissionsProxy
from wagtail.models import Page, PAGE_MODEL_CLASSES

from .models import AbTest
from .events import get_event_types
Expand Down Expand Up @@ -197,11 +197,8 @@ class StartAbTestMenuItem(ActionMenuItem):
label = _("Start A/B test")

def is_shown(self, request, context):
if (
not context["user_page_permissions"]
.for_page(context["ab_test"].page)
.can_publish()
):
page = context["ab_test"].page
if not page.permissions_for_user(request.user).can_publish():
return False

return context["ab_test"].status == AbTest.STATUS_DRAFT
Expand All @@ -212,11 +209,8 @@ class RestartAbTestMenuItem(ActionMenuItem):
label = _("Restart A/B test")

def is_shown(self, request, context):
if (
not context["user_page_permissions"]
.for_page(context["ab_test"].page)
.can_publish()
):
page = context["ab_test"].page
if not page.permissions_for_user(request.user).can_publish():
return False

return context["ab_test"].status == AbTest.STATUS_PAUSED
Expand All @@ -227,11 +221,8 @@ class EndAbTestMenuItem(ActionMenuItem):
label = _("End A/B test")

def is_shown(self, request, context):
if (
not context["user_page_permissions"]
.for_page(context["ab_test"].page)
.can_publish()
):
page = context["ab_test"].page
if not page.permissions_for_user(request.user).can_publish():
return False

return context["ab_test"].status in [
Expand All @@ -246,11 +237,8 @@ class PauseAbTestMenuItem(ActionMenuItem):
label = _("Pause A/B test")

def is_shown(self, request, context):
if (
not context["user_page_permissions"]
.for_page(context["ab_test"].page)
.can_publish()
):
page = context["ab_test"].page
if not page.permissions_for_user(request.user).can_publish():
return False

return context["ab_test"].status == AbTest.STATUS_RUNNING
Expand All @@ -262,9 +250,6 @@ class AbTestActionMenu:
def __init__(self, request, **kwargs):
self.request = request
self.context = kwargs
self.context["user_page_permissions"] = UserPagePermissionsProxy(
self.request.user
)
# The ActionMenuItem request object is available in the context dictionary as context['request'].
# https://docs.wagtail.io/en/stable/releases/2.15.html#admin-homepage-panels-summary-items-and-action-menu-items-now-use-components
self.context["request"] = request
Expand Down