2006-05-02 09:31:56 +08:00
|
|
|
"""
|
|
|
|
Creates the default Site object.
|
|
|
|
"""
|
|
|
|
|
|
|
|
from django.db.models import signals
|
2011-09-22 06:46:48 +08:00
|
|
|
from django.db import router
|
2006-05-02 09:31:56 +08:00
|
|
|
from django.contrib.sites.models import Site
|
|
|
|
from django.contrib.sites import models as site_app
|
|
|
|
|
2009-12-22 23:18:51 +08:00
|
|
|
def create_default_site(app, created_models, verbosity, db, **kwargs):
|
2011-09-22 06:46:48 +08:00
|
|
|
# Only create the default sites in databases where Django created the table
|
|
|
|
if Site in created_models and router.allow_syncdb(db, Site) :
|
2006-08-27 20:46:39 +08:00
|
|
|
if verbosity >= 2:
|
|
|
|
print "Creating example.com Site object"
|
2011-09-22 06:46:48 +08:00
|
|
|
# The default settings set SITE_ID = 1, and some tests in Django's test
|
|
|
|
# suite rely on this value. However, if database sequences are reused
|
|
|
|
# (e.g. in the test suite after flush/syncdb), it isn't guaranteed that
|
|
|
|
# the next id will be 1, so we coerce it. See #15573 and #16353. This
|
|
|
|
# can also crop up outside of tests - see #15346.
|
|
|
|
s = Site(pk=1, domain="example.com", name="example.com")
|
2009-12-22 23:18:51 +08:00
|
|
|
s.save(using=db)
|
2008-06-22 14:34:17 +08:00
|
|
|
Site.objects.clear_cache()
|
2006-05-02 09:31:56 +08:00
|
|
|
|
2008-08-06 23:32:46 +08:00
|
|
|
signals.post_syncdb.connect(create_default_site, sender=site_app)
|