Skip to content

Commit

Permalink
Use external modeladmin package where available
Browse files Browse the repository at this point in the history
  • Loading branch information
gasman committed Nov 6, 2023
1 parent 6a20507 commit ad77595
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
27 changes: 26 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,32 @@ This module supports the creation of A/B testing experiments within a Wagtail si
Installation
------------

wagtail-experiments is compatible with Wagtail 4.1 to 5.1, and Django 3.2 to 4.2. To install::
wagtail-experiments is compatible with Wagtail 4.1 to 5.2, and Django 3.2 to 4.2. It depends on the Wagtail ModelAdmin module, which is available as an external package as of Wagtail 5.0; we recommend using this rather than the bundled `wagtail.contrib.modeladmin` module to avoid deprecation warnings. The external package will be required as of Wagtail 6.0.

### On Wagtail 5.0 and above

To install::

pip install wagtail-experiments wagtail-modeladmin

and ensure that the apps ``wagtail_modeladmin`` and ``experiments`` are included in your project's ``INSTALLED_APPS``:

.. code-block:: python
INSTALLED_APPS = [
# ...
'wagtail_modeladmin',
'experiments',
# ...
]
Then migrate::

./manage.py migrate

### On Wagtail 4.x

To install::

pip install wagtail-experiments

Expand Down
13 changes: 10 additions & 3 deletions experiments/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@

from django.utils.translation import gettext_lazy as _
from experiments import admin_urls
from wagtail.contrib.modeladmin.helpers import ButtonHelper
from wagtail.contrib.modeladmin.options import ModelAdmin, modeladmin_register
from wagtail.contrib.modeladmin.views import CreateView, EditView
from wagtail import hooks

try:
from wagtail_modeladmin.helpers import ButtonHelper
from wagtail_modeladmin.options import ModelAdmin, modeladmin_register
from wagtail_modeladmin.views import CreateView, EditView
except ImportError:
from wagtail.contrib.modeladmin.helpers import ButtonHelper
from wagtail.contrib.modeladmin.options import ModelAdmin, modeladmin_register
from wagtail.contrib.modeladmin.views import CreateView, EditView


from .models import Experiment
from .utils import get_user_id, impersonate_other_page

Expand Down
10 changes: 9 additions & 1 deletion tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@

from wagtail import VERSION as WAGTAIL_VERSION

try:
import wagtail_modeladmin
except ImportError:
HAS_MODELADMIN_PACKAGE = False
else:
HAS_MODELADMIN_PACKAGE = True


DATABASES = {
'default': {
'ENGINE': os.environ.get('DATABASE_ENGINE', 'django.db.backends.sqlite3'),
Expand Down Expand Up @@ -64,7 +72,7 @@
'experiments',
'tests',

'wagtail.contrib.modeladmin',
'wagtail_modeladmin' if HAS_MODELADMIN_PACKAGE else 'wagtail.contrib.modeladmin',
'wagtail.search',
'wagtail.sites',
'wagtail.users',
Expand Down

0 comments on commit ad77595

Please sign in to comment.