How to initialize the database: Difference between revisions

From GCD
Jump to navigation Jump to search
No edit summary
(deleting obsolete instructions)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
==How to initialize the database for local development==
#REDIRECT [[Web Site Project Page#Development Environment]]
 
After you have set [[Getting Started on Windows|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:
 
<pre>FAKE_COVER_IMAGES = True
BETA = True
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'
</pre>
 
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:
 
<pre>
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');
</pre>
 
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]]

Latest revision as of 16:15, 23 January 2015