Skip to content

Commit

Permalink
add django check and dependency on modeladmin
Browse files Browse the repository at this point in the history
The UI for wagtail-sharing depends on wagtail.contrib.modeladmin, but
this is an optional package that is not part of the standard Wagtail
installation. This commit adds a note to the README about this and also
adds a Django check that will fail if wagtail.contrib.modeladmin isn't
in INSTALLED_APPS.

As a side effect this change also adds a custom AppConfig for this app.
  • Loading branch information
chosak committed May 4, 2018
1 parent 15966c2 commit 5b7e912
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ We follow the [Semantic Versioning 2.0.0](http://semver.org/) format.
- Simplified CHANGELOG format.
- Removed superfluous tests of `Page.get_admin_display_title`.
- Add additional tests for the `before_serve_shared_page` and `after_serve_shared_page` hooks.
- Added Django check and note in README to clarify dependency on `wagtail.contrib.modeladmin` app.


## 0.6 - 2017-11-27
Expand Down
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ Add ``wagtailsharing`` as an installed app in your Django settings:
...
)
``wagtail.contrib.modeladmin`` is also required and must be included in your list of installed apps.

Run migrations to create required database tables:

.. code-block:: bash
Expand Down
1 change: 1 addition & 0 deletions wagtailsharing/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
default_app_config = 'wagtailsharing.apps.WagtailSharingAppConfig'
10 changes: 10 additions & 0 deletions wagtailsharing/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.apps import AppConfig
from django.utils.translation import ugettext_lazy as _

from . import checks # noqa F401


class WagtailSharingAppConfig(AppConfig):
name = 'wagtailsharing'
label = 'wagtailsharing'
verbose_name = _("Wagtail Sharing")
23 changes: 23 additions & 0 deletions wagtailsharing/checks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from django.apps import apps
from django.core.checks import Error, register


@register()
def modeladmin_installed_check(app_configs, **kwargs):
errors = []

MODELADMIN_APP = 'wagtail.contrib.modeladmin'
if not apps.is_installed(MODELADMIN_APP):
error_hint = (
"Is '{}' in settings.INSTALLED_APPS?".format(MODELADMIN_APP)
)

errors.append(
Error(
"wagtail-sharing requires the Wagtail ModelAdmin app.",
hint=error_hint,
id='wagtailsharing.E001'
)
)

return errors
21 changes: 21 additions & 0 deletions wagtailsharing/tests/test_checks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from django.apps import apps
from django.core.checks import Error
from django.test import SimpleTestCase, override_settings

from wagtailsharing.checks import modeladmin_installed_check


class TestModelAdminInstalledCheck(SimpleTestCase):
@override_settings(INSTALLED_APPS=[
'wagtail.contrib.modeladmin',
'wagtailsharing',
])
def test_check_passes_if_modeladmin_installed(self):
self.assertFalse(modeladmin_installed_check(apps.get_app_configs()))

@override_settings(INSTALLED_APPS=['wagtailsharing'])
def test_check_fails_if_modeladmin_not_installed(self):
errors = modeladmin_installed_check(apps.get_app_configs())
self.assertEqual(len(errors), 1)
self.assertIsInstance(errors[0], Error)
self.assertEqual(errors[0].id, 'wagtailsharing.E001')

0 comments on commit 5b7e912

Please sign in to comment.