Using multiple settings and databases

Background

The easiest way to use multiple databases is to use multiple settings files.

A specific settings file (e.g. customsettings.py) can be used by adding –settings customsettings to the different manage.py commands. This wil cause the planop program to use the settings included in the customsettings.py file. This could be a different database file for instance.

Creating a specific settings file

The best way to create a new settings file is to import everything from the settings file and overriding the necessary settings.

An example customsettings.py file could look like this:

from settings import *

DATABASES = {
    "default": {
        "ENGINE": 'django.db.backends.sqlite3',
        "NAME": os_path.join(PROJECT_PATH, 'db', 'custom.db'),
        "USER": '',
        "PASSWORD": '',
    },
}
PROJECTNAME = 'Custom'

Notice that we changed the default databasename to custom.db, but kept it in the default ´db` folder.

If we want to put the database in a different location, we could make our customsettings.py like this:

from settings import *

DATABASES = {
    "default": {
        "ENGINE": 'django.db.backends.sqlite3',
        "NAME": 'C:/planop3/databases/custom.db',
        "USER": '',
        "PASSWORD": '',
    },
}
PROJECTNAME = 'Custom'

When specifying the path, always use forward slashes.

Using a specific settings file

To use a specific settings file, you add –settings customsettings (no .py extension) to the manage.py command.

e.g.:

python manage.py runserver --settings customsettings

Creating a second database on windows

The installer of the windows version creates a default database for you.

You may simply copy that database to a different name.

To create a new database from scratch using custom settings, use the following command:

python manage.py createdb --settings customsettings configs\auth_groups.json configs\autologin_auth.json configs\planop3_sl_1.0.2_nl.json

It should be executed in the folder {{ planop install }}\Python27\Lib\site-packages\planop\.

The python executable needs to be on your windows path. If it is not, you need to prepend {{ planop install}}\python27\ to the command, e.g.:

C:\planop3\python27\python.exe manage.py createdb --settings customsettings

This command creates the database structure, and populates the database with users/groups and the suggestion lists from the mentioned data files.

Running multiple planop installations simultaneously on windows

In the windows version you can change the default port (8000) by adding port=portnumber to the runcpserver command, e.g.:

python manage.py runcpserver port=8001

This command is available in the planop background shortcut.

Your browser will then be able to reach planop via the url http://localhost:8001/.

This can be used to run multiple planop backgrounds simultaneaously.

Creating shortcuts for custom settings

The installer of the windows version creates the following shortcuts by default:

  • planop background
  • planop browser
  • planop 2 converter
  • planop replace suggestion lists

The easiest way to create new shortcuts is to copy the default shortcuts and change the targets.

The custom background shortcut could look like this:

C:\planop3\python27\python.exe manage.py runcpserver port=8001 --settings customsettings

The custom planop browser shortcut:

http:\\localhost:8001\

If you need a planop 2 conversion, you can create a shortcut using the custom settings for that in the same way.

Recap

You want to use two planop installations simultaneously.

You need to:

  • create an extra settings file, specifying a different database
  • create that second database
  • add a new shortcut to launch the second planop background
  • add a new shortcut to open my browser with the url of the second planop background