示例#1
0
    def setUp(self):
        self.config = testing.setUp()
        setup_db('sqlite://')

        with transaction.manager:
            model = BlogEntryModel(title=u"blog title", body=u"blog content")
            DBSession.add(model)
示例#2
0
def main(argv=sys.argv):
    if len(argv) != 2:
        usage(argv)

    config_uri = argv[1]
    setup_logging(config_uri)
    settings = get_appsettings(config_uri)

    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    BaseModel.metadata.create_all(engine)

    with transaction.manager:
        from pylonsprojectjp.apps.auth.security import get_user_by_username
        if not get_user_by_username("admin"):
            group = GroupModel.get_or_create(group_name=u"admin")
            admin = UserModel(username=u"admin")
            admin.password = u"admin"
            admin.groups.append(group)
            DBSession.add(admin)

        from pylonsprojectjp.apps.page.api import get_page
        if not get_page(()):
            body = u"""\
これはテストサイトです。
`/admin/ </admin/>`_ から管理画面にログインできます。

- ユーザ名: admin
- パスワード: admin
"""
            page = PageModel(url='/', title=u"Pylons Project JP", body=body,
                             template='index.jinja2')
            DBSession.add(page)
示例#3
0
def update_instance(request, admin, instance, params):
    with transaction.manager:
        instance.from_dict(params)
        DBSession.add(instance)
示例#4
0
def create_instance(request, admin, params):
    with transaction.manager:
        instance = admin.model_class(**params)
        DBSession.add(instance)
示例#5
0
def get_page(request, model, page=1, items_per_page=20):
    query = DBSession.query(model)
    return Page(query, page=page, items_per_page=items_per_page)
示例#6
0
def get_page(url):
    return DBSession.query(PageModel).filter_by(url=url).first()
示例#7
0
def get_user_by_username(username):
    from pylonsprojectjp.models import DBSession
    from .models import UserModel

    query = DBSession.query(UserModel)
    return query.filter_by(username=username).first()