How to initialize the database: Difference between revisions

From GCD
Jump to navigation Jump to search
No edit summary
(Blank cover entries no longer needed, bug mentioned was fixed long ago)
Line 5: Line 5:
First of all, some more variables you might want to set in settings_local.py:
First of all, some more variables you might want to set in settings_local.py:


<pre>FAKE_COVER_IMAGES = True
<pre>ADMINS = (
BETA = True
ADMINS = (
     ('admin', '[email protected]'),
     ('admin', '[email protected]'),
)
)
Line 61: Line 59:


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.
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.
To create the initial empty cover records, the easiest way is through the Django command line. Run "python manage.py shell" and enter the following:
<pre>
from apps.gcd.models import *
from django.contrib.auth.models import *
for issue in Issue.objects.all():
    cover = Cover(issue=issue)
    cover.save()
</pre>
There used to be a small mistake in the Django models. In case the code you used for syncdb wasn't fixed yet, you will end up with a problem in the oi_changeset_comment table, which will manifest as
<pre>IntegrityError at ...
(1048, "Column 'content_type_id' cannot be null")</pre>
whenever you try to submit a change. In case you encounter this, you can fix the table with the following SQL commands:
<pre>
ALTER TABLE table oi_changeset_comment CHANGE content_type_id content_type_id int(11) DEFAULT NULL;
ALTER TABLE table oi_changeset_comment CHANGE revision_id revision_id int(11) DEFAULT NULL;
</pre>


[[Category: GCD Technical]]
[[Category: GCD Technical]]

Revision as of 19:12, 3 January 2012

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.