forked from bireme/scielobooks
-
Notifications
You must be signed in to change notification settings - Fork 1
/
create_admin.py
executable file
·35 lines (28 loc) · 1009 Bytes
/
create_admin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python
# coding: utf-8
'''
Script to load essencial data and create the default "admin" user.
This script should be called once right after the system is deployed.
'''
from scielobooks.users import models as users_models
from scielobooks.models import models
from sqlalchemy.orm import sessionmaker
import sqlalchemy
from sqlalchemy.exc import IntegrityError
engine = sqlalchemy.create_engine('postgresql+psycopg2://postgres:ash2so4@localhost:5432/scielobooks', echo=True)
Session = sessionmaker(bind=engine)
session = Session()
group_admin = users_models.Group('admin')
session.add(group_admin)
try:
session.commit()
except IntegrityError:
session.rollback()
group_admin = session.query(users_models.Group).filter_by(name='admin').one()
admin = models.Admin('admin', '123456', group_admin, is_active=True)
reg_profile = users_models.RegistrationProfile(admin)
reg_profile.activation_key = 'ACTIVATED'
session.add(admin)
session.add(reg_profile)
session.commit()
print 'done'