Ticket #24000: create_default_site_patch.patch

File create_default_site_patch.patch, 2.5 KB (added by tkhyn, 10 years ago)
  • django/contrib/sites/management.py

    diff --git a/django/contrib/sites/management.py b/django/contrib/sites/management.py
    index a9daf1c..33bd44d 100644
    a b from django.core.management.color import no_style  
    88from django.db import DEFAULT_DB_ALIAS, connections, router
    99
    1010
    11 def create_default_site(app_config, verbosity=2, interactive=True, db=DEFAULT_DB_ALIAS, **kwargs):
     11def create_default_site(app_config, verbosity=2, interactive=True, using=DEFAULT_DB_ALIAS, **kwargs):
    1212    try:
    1313        Site = apps.get_model('sites', 'Site')
    1414    except LookupError:
    1515        return
    1616
    17     if not router.allow_migrate(db, Site):
     17    if not router.allow_migrate(using, Site):
    1818        return
    1919
    2020    if not Site.objects.exists():
    def create_default_site(app_config, verbosity=2, interactive=True, db=DEFAULT_DB  
    2525        # can also crop up outside of tests - see #15346.
    2626        if verbosity >= 2:
    2727            print("Creating example.com Site object")
    28         Site(pk=settings.SITE_ID, domain="example.com", name="example.com").save(using=db)
     28        Site(pk=settings.SITE_ID, domain="example.com", name="example.com").save(using=using)
    2929
    3030        # We set an explicit pk instead of relying on auto-incrementation,
    3131        # so we need to reset the database sequence. See #17415.
    32         sequence_sql = connections[db].ops.sequence_reset_sql(no_style(), [Site])
     32        sequence_sql = connections[using].ops.sequence_reset_sql(no_style(), [Site])
    3333        if sequence_sql:
    3434            if verbosity >= 2:
    3535                print("Resetting sequence")
    36             with connections[db].cursor() as cursor:
     36            with connections[using].cursor() as cursor:
    3737                for command in sequence_sql:
    3838                    cursor.execute(command)
  • django/contrib/sites/tests.py

    diff --git a/django/contrib/sites/tests.py b/django/contrib/sites/tests.py
    index 72c7a9f..c820b02 100644
    a b class CreateDefaultSiteTests(TestCase):  
    151151        """
    152152        #16353, #16828 - The default site creation should respect db routing.
    153153        """
    154         create_default_site(self.app_config, db='default', verbosity=0)
    155         create_default_site(self.app_config, db='other', verbosity=0)
     154        create_default_site(self.app_config, using='default', verbosity=0)
     155        create_default_site(self.app_config, using='other', verbosity=0)
    156156        self.assertFalse(Site.objects.using('default').exists())
    157157        self.assertTrue(Site.objects.using('other').exists())
    158158
Back to Top