How to initialize the database

From GCD
Revision as of 19:12, 3 January 2012 by Adia (talk | contribs) (Blank cover entries no longer needed, bug mentioned was fixed long ago)
Jump to navigation Jump to search

How to initialize the database for local development

After you have set up an initial installation of the code for local development, you need to follow a few more steps before the site is fully functional.

First of all, some more variables you might want to set in settings_local.py:

ADMINS = (
    ('admin', '[email protected]'),
)
EMAIL_NEW_ACCOUNTS_FROM = '[email protected]'
EMAIL_EDITORS = '[email protected]'
EMAIL_CONTACT = '[email protected]'
EMAIL_HOST = 'mail.example.com'
SITE_URL = 'http://localhost:8000/'
MEDIA_URL = '/site_media'

If you set EMAIL_HOST to an SMTP server you can use to send mail, you will be able to test e-mail sending from the app. This will also help with registering test users, since new users need to click on an e-mailed link to become active.

If you had created an admin account during "python manage.py syncdb", please note that the GCD web app uses two records for each account: one in the auth_user table, used by Django to keep base user information such as username and password, and one in gcd_indexer. The app also needs user groups with the appropriate permissions. Here is a SQL script to do this:

INSERT INTO gcd_indexer SET
    user_id = (SELECT id FROM auth_user WHERE is_superuser = 1),
    country_id = (SELECT id FROM gcd_country WHERE code = 'zz'),
    max_reservations = 500,
    max_ongoing=500;

INSERT INTO auth_group (name)
        VALUES ('admin'), ('editor'), ('indexer'), ('board'), ('member');

SET @indexers = (SELECT id FROM auth_group WHERE name = 'indexer');
SET @editors = (SELECT id FROM auth_group WHERE name = 'editor');
SET @admins = (SELECT id FROM auth_group WHERE name = 'admin');
INSERT INTO auth_group_permissions (group_id, permission_id)
    SELECT @indexers, id FROM auth_permission WHERE codename = 'can_reserve';
INSERT INTO auth_group_permissions (group_id, permission_id)
    SELECT @editors, id FROM auth_permission
        WHERE codename IN ('can_reserve', 'can_approve', 'can_cancel',
                           'can_mark');
INSERT INTO auth_group_permissions (group_id, permission_id)
    SELECT @admins, id from auth_permission;

SET @admin = (SELECT id FROM auth_user WHERE is_superuser = 1);
INSERT INTO auth_user_groups (user_id, group_id)
    SELECT @admin, id FROM auth_group
        WHERE name IN ('admin', 'editor', 'indexer');

INSERT INTO auth_user SET
    id = 381,
    last_name = 'Anonymous',
    is_active = 0,
    username = 'anonymous';
INSERT INTO gcd_indexer SET
    id = 381,
    user_id = 381,
    country_id = (SELECT id FROM gcd_country WHERE code = 'zz');

Afterwards, you can create new users normally from the web site. If you want to make some of them editors, just insert the appropriate records in the auth_user_groups table.