Commit cb7a23a7 authored by Michal Čihař's avatar Michal Čihař

Add management command to change site name.

Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 8a040682
......@@ -443,12 +443,17 @@ Set correct site name
Adjust site name in admin interface, otherwise links in RSS or registration
emails will not work.
You can do this under the :guilabel:`Sites › Sites` (or directly open URL
``/admin/sites/site/1/``), change the :guilabel:`Domain name` to match your
setup. You might want to set :setting:`ENABLE_HTTPS` as well if you serve site
over https.
Please open admin interface and edit default site name and domain under the
:guilabel:`Sites › Sites` (or you can do that directly at
``/admin/sites/site/1/`` URL under your Weblate installation). You have to change
the :guilabel:`Domain name` to match your setup.
.. seealso:: :ref:`faq-site`
You might want to set :setting:`ENABLE_HTTPS` as well if you serve site over
https.
Alternatively you can set the site name from command line using :djadmin:`changesite`.
.. seealso:: :ref:`faq-site`, :djadmin:`changesite`, https://docs.djangoproject.com/en/stable/ref/contrib/sites/
.. _production-indexing:
......
......@@ -11,6 +11,18 @@ Management commands
The ./manage.py is extended with following commands:
changesite
----------
.. django-admin:: changesite
.. versionadded:: 2.4
You can use this to changes site name from command line with ``--set-name``
parameter. The ``--get-name`` prints currently configured site name.
.. seealso:: :ref:`production-site`
checkgit <project|project/component>
------------------------------------
......
......@@ -32,6 +32,7 @@ Released on ? 2015.
* Rewritten handling of static files.
* Direct login/registration links to third party service if that's the only one.
* Commit pending changes on account removal.
* Add management command to change site name.
weblate 2.3
-----------
......
......@@ -117,11 +117,9 @@ Why does registration contain example.com as domain?
----------------------------------------------------
Weblate uses Django sites framework and it defines site name inside the
database. Please open admin interface and edit default site name and domain
(you can do that directly at ``/admin/sites/site/1/`` URL under your Weblate
installation).
database.
.. seealso:: https://docs.djangoproject.com/en/stable/ref/contrib/sites/
.. seealso:: :ref:`production-site`
Why are all commits committed by Weblate <noreply@weblate.org>?
---------------------------------------------------------------
......
......@@ -65,29 +65,20 @@ done < $OPENSHIFT_REPO_DIR/requirements-optional.txt
sh "python ${OPENSHIFT_REPO_DIR}/setup_weblate.py develop"
if [ ! -s $OPENSHIFT_REPO_DIR/weblate/fixtures/site_data.json ]; then
mkdir -p $OPENSHIFT_REPO_DIR/weblate/fixtures
cat <<-EOF >$OPENSHIFT_REPO_DIR/weblate/fixtures/site_data.json
[{
"pk": 1,
"model": "sites.site",
"fields": {
"name": "${OPENSHIFT_APP_DNS}",
"domain":"${OPENSHIFT_APP_DNS}"
}
}]
EOF
fi
sh "python ${OPENSHIFT_REPO_DIR}/openshift/manage.py migrate --noinput"
sh "python ${OPENSHIFT_REPO_DIR}/openshift/manage.py collectstatic --noinput"
if [ ! -s $OPENSHIFT_DATA_DIR/.credentials ]; then
sh "python ${OPENSHIFT_REPO_DIR}/openshift/manage.py changesite ${OPENSHIFT_APP_DNS}"
fi
if [ ! -s $OPENSHIFT_DATA_DIR/.credentials ]; then
sh "python ${OPENSHIFT_REPO_DIR}/openshift/manage.py setupgroups --move"
else
sh "python ${OPENSHIFT_REPO_DIR}/openshift/manage.py setupgroups --no-privs-update"
fi
sh "python ${OPENSHIFT_REPO_DIR}/openshift/manage.py setuplang"
sh "python ${OPENSHIFT_REPO_DIR}/openshift/manage.py compilemessages"
......
# -*- coding: utf-8 -*-
#
# Copyright © 2012 - 2015 Michal Čihař <michal@cihar.com>
#
# This file is part of Weblate <http://weblate.org/>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from django.core.management.base import BaseCommand, CommandError
from django.contrib.sites.models import Site
from optparse import make_option
class Command(BaseCommand):
help = 'changes default site name'
option_list = BaseCommand.option_list + (
make_option(
'--set-name',
type='str',
dest='set_name',
default=None,
help='site name to set'
),
make_option(
'--site-id',
type='int',
dest='site_id',
default=1,
help='site ID to manipulate (1 by default)'
),
make_option(
'--get-name',
action='store_true',
dest='get_name',
default=False,
help='just display the site name'
),
)
def handle(self, *args, **options):
if options['set_name']:
site, created = Site.objects.get_or_create(
pk=options['site_id'],
defaults={'domain': options['set_name'], 'name': options['set_name']}
)
if not created:
site.domain = options['set_name']
site.name = options['set_name']
site.save()
elif options['get_name']:
try:
self.stdout.write(Site.objects.get(pk=options['site_id']).domain)
except Site.DoesNotExist:
raise CommandError('Site does not exist!')
else:
raise CommandError('Please specify desired action!')
......@@ -28,9 +28,11 @@ from django.test import TestCase
from unittest import SkipTest
from django.core.urlresolvers import reverse
from django.contrib.auth.models import AnonymousUser, User, Group
from django.contrib.sites.models import Site
from django.core import mail
from django.test.utils import override_settings
from django.core.management import call_command
from django.core.management.base import CommandError
from django.http import HttpRequest, HttpResponseRedirect
from weblate.accounts.models import (
......@@ -316,6 +318,21 @@ class CommandTest(TestCase):
profile = Profile.objects.get(user__username='testuser')
self.assertEqual(profile.translated, 2000)
def test_changesite(self):
call_command('changesite', get_name=True)
self.assertNotEqual(Site.objects.get(pk=1).domain, 'test.weblate.org')
call_command('changesite', set_name='test.weblate.org')
self.assertEqual(Site.objects.get(pk=1).domain, 'test.weblate.org')
def test_changesite_new(self):
self.assertRaises(
CommandError,
call_command,
'changesite', get_name=True, site_id=2
)
call_command('changesite', set_name='test.weblate.org', site_id=2)
self.assertEqual(Site.objects.get(pk=2).domain, 'test.weblate.org')
class ViewTest(TestCase):
'''
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment