1 # Copyright (C) 2010 Oregon State University et al.
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
18 from django
.conf
import settings
20 from django
.contrib
.sites
import models
as sites_app
21 from django
.contrib
.sites
.management
import create_default_site
22 from django
.contrib
.sites
.models
import Site
24 from django
.db
.models
.signals
import post_syncdb
27 def update_sites_module(sender
, **kwargs
):
29 Create a new row in the django_sites table that
30 holds SITE_ID, SITE_NAME and SITE_DOMAIN defined
33 If SITE_NAME or SITE_DOMAIN are not defined they
34 will default to 'example.com'
36 verb
= kwargs
.get('verbosity', 0)
37 id, name
, domain
= (1, 'example.com', 'example.com')
40 except AttributeError, e
:
42 print 'Using: \'%s\' for site id.' % id
45 name
= settings
.SITE_NAME
46 except AttributeError, e
:
48 print 'Using: \'%s\' for site name.' % name
51 domain
= settings
.SITE_DOMAIN
52 except AttributeError, e
:
54 print 'Using: \'%s\' for site domain.' % domain
57 site
= Site
.objects
.get(id=id)
60 print "Site name changed from %s to %s." % \
63 if site
.domain
!= domain
:
65 print "Site domain changed from %s to %s." % \
69 except Site
.DoesNotExist
:
71 print "New site: [%s] %s (%s) created in django_site table." % \
73 site
= Site(id=id, name
=name
, domain
=domain
)
75 # Reconnect create_default_site request for other apps
76 post_syncdb
.connect(create_default_site
, sender
=sites_app
)
79 print "A site with the id of %s is already taken. " \
80 "Please change SITE_ID to a different number in your " \
81 "settings.py file." % id