Ticket #7358: 003_create_default_site.patch
File 003_create_default_site.patch, 1.3 KB (added by , 16 years ago) |
---|
-
django/contrib/sites/management.py
old new 6 6 from django.db.models import signals 7 7 from django.contrib.sites.models import Site 8 8 from django.contrib.sites import models as site_app 9 import socket 9 10 10 def create_default_site(app, created_models, verbosity): 11 def get_default_hostname(): 12 try: 13 hostname = socket.gethostname() 14 except socket.error: 15 from django.conf import settings 16 hostname = getattr(settings.DEFAULT_SITE_NAME, 'localhost') 17 return hostname 18 19 def create_default_site(app, created_models, verbosity=1): 11 20 if Site in created_models: 12 if verbosity >= 2: 13 print "Creating example.com Site object" 14 s = Site(domain="example.com", name="example.com") 21 # Don't let script-kiddies ruin your efforts by 22 # hardcoding something as stupid as example.com here. 23 hostname = get_default_hostname() 24 if verbosity >= 1: 25 print "Creating default site: <%s>" % repr(hostname) 26 s = Site(domain=hostname, name=hostname) 15 27 s.save() 16 28 17 29 dispatcher.connect(create_default_site, sender=site_app, signal=signals.post_syncdb)