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
26 def update_sites_module(sender
, **kwargs
):
28 Create a new row in the django_sites table that
29 holds SITE_ID, SITE_NAME and SITE_DOMAIN defined
32 If SITE_NAME or SITE_DOMAIN are not defined they
33 will default to 'example.com'
35 verb
= kwargs
.get('verbosity', 0)
36 id, name
, domain
= (1, 'example.com', 'example.com')
39 except AttributeError, e
:
41 print 'Using: \'%s\' for site id.' % id
44 name
= settings
.SITE_NAME
45 except AttributeError, e
:
47 print 'Using: \'%s\' for site name.' % name
50 domain
= settings
.SITE_DOMAIN
51 except AttributeError, e
:
53 print 'Using: \'%s\' for site domain.' % domain
56 site
= Site
.objects
.get(id=id)
59 print "Site name changed from %s to %s." % \
62 if site
.domain
!= domain
:
64 print "Site domain changed from %s to %s." % \
68 except Site
.DoesNotExist
:
70 print "New site: [%s] %s (%s) created in django_site table." % \
72 site
= Site(id=id, name
=name
, domain
=domain
)
74 # Reconnect create_default_site request for other apps
75 post_syncdb
.connect(create_default_site
, sender
=sites_app
)
78 print "A site with the id of %s is already taken. " \
79 "Please change SITE_ID to a different number in your " \
80 "settings.py file." % id