Skip to content

Commit

Permalink
Docs: update Django settings files discussion
Browse files Browse the repository at this point in the history
This encourages using the settings file in a way
which is easier to upgrade for future releases.
  • Loading branch information
acdha committed Oct 30, 2017
1 parent 6b56a29 commit f72e87c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
38 changes: 29 additions & 9 deletions README.md
Expand Up @@ -66,24 +66,44 @@ start MySQL and assign it a root password:

sudo service mysqld start
/usr/bin/mysqladmin -u root password '' # pick a real password

You will probably want to change the password 'pick_one' in the example below
to something else:

echo "DROP DATABASE IF EXISTS chronam; CREATE DATABASE chronam CHARACTER SET utf8; GRANT ALL ON chronam.* to 'chronam'@'localhost' identified by 'pick_one'; GRANT ALL ON test_chronam.* TO 'chronam'@'localhost' identified by 'pick_one';" | mysql -u root -p

You will need to use the settings template to create your application settings.
Add your database password to the settings.py file:
You will need to create a Django settings file which uses the default settings
and sets custom values specific to your site:

1. Create a `settings.py` file in the chronam directory which imports the default values
from the provided template for possible customization:

echo 'from chronam.settings_template import *' > /opt/chronam/settings.py

1. Ensure that the `DJANGO_SETTINGS_MODULE` environment variable is set to
`chronam.settings` before you start a Django management command. This can be
set as a user-wide default in your `~/.profile` or but the recommended way is
simply to make it part of the virtualenv activation process::

cp /opt/chronam/settings_template.py /opt/chronam/settings.py
echo 'export DJANGO_SETTINGS_MODULE=chronam.settings' >> /opt/chronam/ENV/bin/activate

For Django management commands to work you will need to have the
DJANGO_SETTINGS_MODULE environment variable set. You may want to add
this to your ~/.profile so you do not need to remember to do it
everytime you log in.
1. Add your database password to the settings.py file following the standard
Django [settings documentation](https://docs.djangoproject.com/en/1.8/ref/settings/#databases):

export DJANGO_SETTINGS_MODULE=chronam.settings
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'chronam_db',
'USER': 'chronam_user',
'HOST': 'mysql.example.org',
'PASSWORD': 'NotTheRealPassword',
}
}

You should never edit the `settings_template.py` file since that may change in
the next release but you may wish to periodically review the list of
[changes to that file](https://github.com/LibraryOfCongress/chronam/commits/master/settings_template.py)
in case you need to update your local settings.

Next you will need to initialize database schema and load some initial data:

Expand Down
4 changes: 2 additions & 2 deletions vagrant/centos/user_setup.sh
Expand Up @@ -17,11 +17,11 @@ if [ ! -d $CHRONAM_HOME/data/bib ]; then
mkdir $CHRONAM_HOME/data/bib
fi

echo "CREATE DATABASE chronam CHARACTER SET utf8; GRANT ALL ON chronam.* to 'chronam'@'localhost' identified by 'pick_one';" | mysql -u root
echo "CREATE DATABASE chronam CHARACTER SET utf8; GRANT ALL ON chronam.* to 'chronam'@'localhost' identified by 'pick_one';" | mysql -u root

# config env
if [ ! -f $CHRONAM_HOME/settings.py ]; then
ln -s $CHRONAM_HOME/settings_template.py $CHRONAM_HOME/settings.py
echo 'from chronam.settings_template import *' > $CHRONAM_HOME/settings.py
fi

echo "export DJANGO_SETTINGS_MODULE=chronam.settings" >> /home/vagrant/.bashrc
Expand Down

0 comments on commit f72e87c

Please sign in to comment.