Pylonsで作ったアプリの初期化にはwebsetup.pyをつかう。
コマンドは
paster setup-app development.ini
これね。
websetup.pyのなかみはこんなかんじ
# -*- coding: utf-8 -*-
"""Setup the ndi application"""
import logging
import pylons.test
from sqlalchemy import *
from ndi.config.environment import load_environment
from ndi.model.meta import Session, Base
log = logging.getLogger(__name__)
def setup_app(command, conf, vars):
"""Place any commands to setup ndi here"""
# Don't reload the app if it was loaded under the testing environment
if not pylons.test.pylonsapp:
load_environment(conf.global_conf, conf.local_conf)
# Create the tables if they don't already exist
Base.metadata.create_all(bind=Session.bind)
#あとでimportの後は*にするが定義終わってないのもあるため
#作成途中なのでいっこずつ付け足しては投入しております
from ndi.model.member import BaseUser,NdiUser
from ndi.model.master import Server,Nation,OptionSkill,SeaAreaL,SeaAreaS,Port
#テーブル作成
BaseUser.metadata.create_all(bind=Session.bind)
NdiUser.metadata.create_all(bind=Session.bind)
Server.metadata.create_all(bind=Session.bind)
Nation.metadata.create_all(bind=Session.bind)
OptionSkill.metadata.create_all(bind=Session.bind)
SeaAreaL.metadata.create_all(bind=Session.bind)
SeaAreaS.metadata.create_all(bind=Session.bind)
Port.metadata.create_all(bind=Session.bind)
from ndi.model import meta
#マスタ系のデータ入れてくお
#Server
try:
meta.Session.add(Server(id=1,name='notos' ))
meta.Session.add(Server(id=2,name='zephyros'))
meta.Session.add(Server(id=3,name='euros' ))
meta.Session.add(Server(id=4,name='boreas' ))
meta.Session.commit()
except Exception,e:
print 'Abort:Server'
meta.Session.rollback()以下略。このあと延々データ投入が続く。
親の仇みたいに定義書きまくってpaster setup-app development.iniすると、画面が滝のようになってきもちいいいいいいいい
あまりに楽しいので、DBのテーブル全部消す→paster setup-app development.ini→気持ちいいいいいい→DBのテー(略
とかやってます。作業すすみません。進めよ。
