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

Fix django.contrib.sites detection in set_default_site command when using AppConfig #1662

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion django_extensions/management/commands/set_default_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from django.conf import settings
from django.core.management.base import BaseCommand, CommandError
from django.apps import apps

from django_extensions.management.utils import signalcommand

Expand All @@ -29,7 +30,7 @@ def add_arguments(self, parser):

@signalcommand
def handle(self, *args, **options):
if 'django.contrib.sites' not in settings.INSTALLED_APPS:
if not apps.is_installed('django.contrib.sites'):
raise CommandError('The sites framework is not installed.')

from django.contrib.sites.models import Site
Expand Down
7 changes: 7 additions & 0 deletions tests/management/commands/test_set_default_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,10 @@ def test_should_set_domain_only(self):

self.assertEqual(result.name, 'example.com')
self.assertEqual(result.domain, 'bar')

def test_should_not_raise_if_sites_installed_through_appconfig(self):
with self.modify_settings(INSTALLED_APPS={
'append': 'django.contrib.sites.apps.SitesConfig',
'remove': 'django.contrib.sites',
}):
call_command('set_default_site', '--name=foo', '--domain=foo.bar')